From 036fb7861fb8fb12f1dcabbd8edab9b322b7c96c Mon Sep 17 00:00:00 2001 From: zeripath Date: Tue, 6 Jun 2023 06:29:37 +0100 Subject: [PATCH] Clean up WebAuthn javascript code and remove JQuery code (#22697) There were several issues with the WebAuthn registration and testing code and the style was very old javascript with jquery callbacks. This PR uses async and fetch to replace the JQuery code. Ref #22651 Signed-off-by: Andrew Thornton --------- Signed-off-by: Andrew Thornton Co-authored-by: delvh Co-authored-by: silverwind --- routers/web/user/setting/security/webauthn.go | 6 +- templates/user/auth/webauthn.tmpl | 2 +- templates/user/auth/webauthn_error.tmpl | 31 +-- .../user/settings/security/webauthn.tmpl | 2 +- web_src/css/base.css | 22 ++ web_src/css/repo.css | 5 - web_src/js/features/user-auth-webauthn.js | 263 +++++++++--------- web_src/js/utils.js | 16 ++ web_src/js/utils.test.js | 8 +- 9 files changed, 191 insertions(+), 164 deletions(-) diff --git a/routers/web/user/setting/security/webauthn.go b/routers/web/user/setting/security/webauthn.go index 005431886..826562f15 100644 --- a/routers/web/user/setting/security/webauthn.go +++ b/routers/web/user/setting/security/webauthn.go @@ -6,6 +6,8 @@ package security import ( "errors" "net/http" + "strconv" + "time" "code.gitea.io/gitea/models/auth" wa "code.gitea.io/gitea/modules/auth/webauthn" @@ -23,8 +25,8 @@ import ( func WebAuthnRegister(ctx *context.Context) { form := web.GetForm(ctx).(*forms.WebauthnRegistrationForm) if form.Name == "" { - ctx.Error(http.StatusConflict) - return + // Set name to the hexadecimal of the current time + form.Name = strconv.FormatInt(time.Now().UnixNano(), 16) } cred, err := auth.GetWebAuthnCredentialByName(ctx.Doer.ID, form.Name) diff --git a/templates/user/auth/webauthn.tmpl b/templates/user/auth/webauthn.tmpl index ea773d256..f1c4f29fd 100644 --- a/templates/user/auth/webauthn.tmpl +++ b/templates/user/auth/webauthn.tmpl @@ -5,6 +5,7 @@

{{.locale.Tr "twofa"}}

+ {{template "user/auth/webauthn_error" .}}
{{svg "octicon-key" 56}}

{{.locale.Tr "webauthn_insert_key"}}

@@ -18,5 +19,4 @@
-{{template "user/auth/webauthn_error" .}} {{template "base/footer" .}} diff --git a/templates/user/auth/webauthn_error.tmpl b/templates/user/auth/webauthn_error.tmpl index b6467de1a..f90882ef1 100644 --- a/templates/user/auth/webauthn_error.tmpl +++ b/templates/user/auth/webauthn_error.tmpl @@ -1,22 +1,13 @@ -