Skip to content

Commit 2213db0

Browse files
committed
add
1 parent 7582eb0 commit 2213db0

File tree

6 files changed

+26
-3
lines changed

6 files changed

+26
-3
lines changed

custom/conf/app.example.ini

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,12 @@ LEVEL = Info
791791
;ENABLE_BASIC_AUTHENTICATION = true
792792
;;
793793
;; Show the password sign-in form (for password-based login), otherwise, only show OAuth2 login methods.
794-
;; If you set it to false, maybe it also needs to set ENABLE_BASIC_AUTHENTICATION to false to completely disable password-based authentication.
794+
;; If you set it to false, maybe it also needs to set ENABLE_BASIC_AUTHENTICATION and ENABLE_PASSKEY_AUTHENTICATION to false to completely disable password-based authentication.
795795
;ENABLE_PASSWORD_SIGNIN_FORM = true
796796
;;
797+
;; This setting enables gitea to be signed in with a passkey
798+
;ENABLE_PASSKEY_AUTHENTICATION = true
799+
;;
797800
;; More detail: https://github.com/gogits/gogs/issues/165
798801
;ENABLE_REVERSE_PROXY_AUTHENTICATION = false
799802
; Enable this to allow reverse proxy authentication for API requests, the reverse proxy is responsible for ensuring that no CSRF is possible.

modules/setting/service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var Service = struct {
4646
RequireSignInView bool
4747
EnableNotifyMail bool
4848
EnableBasicAuth bool
49+
EnablePasskeyAuth bool
4950
EnableReverseProxyAuth bool
5051
EnableReverseProxyAuthAPI bool
5152
EnableReverseProxyAutoRegister bool
@@ -161,6 +162,7 @@ func loadServiceFrom(rootCfg ConfigProvider) {
161162
Service.RequireSignInView = sec.Key("REQUIRE_SIGNIN_VIEW").MustBool()
162163
Service.EnableBasicAuth = sec.Key("ENABLE_BASIC_AUTHENTICATION").MustBool(true)
163164
Service.EnablePasswordSignInForm = sec.Key("ENABLE_PASSWORD_SIGNIN_FORM").MustBool(true)
165+
Service.EnablePasskeyAuth = sec.Key("ENABLE_PASSKEY_AUTHENTICATION").MustBool(true)
164166
Service.EnableReverseProxyAuth = sec.Key("ENABLE_REVERSE_PROXY_AUTHENTICATION").MustBool()
165167
Service.EnableReverseProxyAuthAPI = sec.Key("ENABLE_REVERSE_PROXY_AUTHENTICATION_API").MustBool()
166168
Service.EnableReverseProxyAutoRegister = sec.Key("ENABLE_REVERSE_PROXY_AUTO_REGISTRATION").MustBool()

routers/web/auth/auth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func prepareSignInPageData(ctx *context.Context) {
169169
ctx.Data["PageIsLogin"] = true
170170
ctx.Data["EnableSSPI"] = auth.IsSSPIEnabled(ctx)
171171
ctx.Data["EnablePasswordSignInForm"] = setting.Service.EnablePasswordSignInForm
172+
ctx.Data["EnablePasskeyAuth"] = setting.Service.EnablePasskeyAuth
172173

173174
if setting.Service.EnableCaptcha && setting.Service.RequireCaptchaForLogin {
174175
context.SetCaptchaData(ctx)

routers/web/auth/linkaccount.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func LinkAccount(ctx *context.Context) {
4444
ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
4545
ctx.Data["AllowOnlyInternalRegistration"] = setting.Service.AllowOnlyInternalRegistration
4646
ctx.Data["ShowRegistrationButton"] = false
47+
ctx.Data["EnablePasskeyAuth"] = setting.Service.EnablePasskeyAuth
4748

4849
// use this to set the right link into the signIn and signUp templates in the link_account template
4950
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
@@ -136,6 +137,7 @@ func LinkAccountPostSignIn(ctx *context.Context) {
136137
ctx.Data["CfTurnstileSitekey"] = setting.Service.CfTurnstileSitekey
137138
ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
138139
ctx.Data["ShowRegistrationButton"] = false
140+
ctx.Data["EnablePasskeyAuth"] = setting.Service.EnablePasskeyAuth
139141

140142
// use this to set the right link into the signIn and signUp templates in the link_account template
141143
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
@@ -224,6 +226,7 @@ func LinkAccountPostRegister(ctx *context.Context) {
224226
ctx.Data["CfTurnstileSitekey"] = setting.Service.CfTurnstileSitekey
225227
ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration
226228
ctx.Data["ShowRegistrationButton"] = false
229+
ctx.Data["EnablePasskeyAuth"] = setting.Service.EnablePasskeyAuth
227230

228231
// use this to set the right link into the signIn and signUp templates in the link_account template
229232
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"

routers/web/auth/webauthn.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ func WebAuthn(ctx *context.Context) {
5050

5151
// WebAuthnPasskeyAssertion submits a WebAuthn challenge for the passkey login to the browser
5252
func WebAuthnPasskeyAssertion(ctx *context.Context) {
53+
if !setting.Service.EnablePasskeyAuth {
54+
ctx.Error(http.StatusForbidden)
55+
return
56+
}
57+
5358
assertion, sessionData, err := wa.WebAuthn.BeginDiscoverableLogin()
5459
if err != nil {
5560
ctx.ServerError("webauthn.BeginDiscoverableLogin", err)
@@ -66,6 +71,11 @@ func WebAuthnPasskeyAssertion(ctx *context.Context) {
6671

6772
// WebAuthnPasskeyLogin handles the WebAuthn login process using a Passkey
6873
func WebAuthnPasskeyLogin(ctx *context.Context) {
74+
if !setting.Service.EnablePasskeyAuth {
75+
ctx.Error(http.StatusForbidden)
76+
return
77+
}
78+
6979
sessionData, okData := ctx.Session.Get("webauthnPasskeyAssertion").(*webauthn.SessionData)
7080
if !okData || sessionData == nil {
7181
ctx.ServerError("ctx.Session.Get", errors.New("not in WebAuthn session"))

templates/user/auth/signin_inner.tmpl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@
6060
</div>
6161

6262
<div class="ui container fluid">
63-
{{template "user/auth/webauthn_error" .}}
63+
{{if .EnablePasskeyAuth}}
64+
{{template "user/auth/webauthn_error" .}}
65+
{{end}}
6466

6567
<div class="ui attached segment header top tw-max-w-2xl tw-m-auto tw-flex tw-flex-col tw-items-center">
66-
<a class="signin-passkey">{{ctx.Locale.Tr "auth.signin_passkey"}}</a>
68+
{{if .EnablePasskeyAuth}}
69+
<a class="signin-passkey">{{ctx.Locale.Tr "auth.signin_passkey"}}</a>
70+
{{end}}
6771

6872
{{if .ShowRegistrationButton}}
6973
<div class="field">

0 commit comments

Comments
 (0)