Skip to content

Commit 104a864

Browse files
committed
Clean up WebAuthn javascript code and remove JQuery code
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 go-gitea#22651 Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent b37e6a1 commit 104a864

File tree

5 files changed

+178
-151
lines changed

5 files changed

+178
-151
lines changed

routers/web/user/setting/security/webauthn.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package security
66
import (
77
"errors"
88
"net/http"
9+
"strconv"
10+
"time"
911

1012
"code.gitea.io/gitea/models/auth"
1113
wa "code.gitea.io/gitea/modules/auth/webauthn"
@@ -23,8 +25,8 @@ import (
2325
func WebAuthnRegister(ctx *context.Context) {
2426
form := web.GetForm(ctx).(*forms.WebauthnRegistrationForm)
2527
if form.Name == "" {
26-
ctx.Error(http.StatusConflict)
27-
return
28+
// Set name to the hexadecimal of the current time
29+
form.Name = strconv.FormatInt(time.Now().UnixNano(), 16)
2830
}
2931

3032
cred, err := auth.GetWebAuthnCredentialByName(ctx.Doer.ID, form.Name)

templates/user/auth/webauthn.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<h3 class="ui top attached header">
66
{{.locale.Tr "twofa"}}
77
</h3>
8+
{{template "user/auth/webauthn_error" .}}
89
<div class="ui attached segment">
910
<i class="huge key icon"></i>
1011
<h3>{{.locale.Tr "webauthn_insert_key"}}</h3>
@@ -18,5 +19,4 @@
1819
</div>
1920
</div>
2021
</div>
21-
{{template "user/auth/webauthn_error" .}}
2222
{{template "base/footer" .}}
+12-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
<div class="ui small modal" id="webauthn-error">
2-
<div class="header">{{.locale.Tr "webauthn_error"}}</div>
3-
<div class="content">
4-
<div class="ui negative message">
5-
<div class="header">
1+
<div id="webauthn-error" class="ui small hide">
2+
<div class="content ui negative message">
3+
<div class="header">
64
{{.locale.Tr "webauthn_error"}}
7-
</div>
8-
<div class="hide" data-webauthn-error-msg="browser"><p>{{.locale.Tr "webauthn_unsupported_browser"}}</div>
9-
<div class="hide" data-webauthn-error-msg="unknown"><p>{{.locale.Tr "webauthn_error_unknown"}}</div>
10-
<div class="hide" data-webauthn-error-msg="insecure"><p>{{.locale.Tr "webauthn_error_insecure"}}</div>
11-
<div class="hide" data-webauthn-error-msg="unable-to-process"><p>{{.locale.Tr "webauthn_error_unable_to_process"}}</div>
12-
<div class="hide" data-webauthn-error-msg="duplicated"><p>{{.locale.Tr "webauthn_error_duplicated"}}</div>
13-
<div class="hide" data-webauthn-error-msg="empty"><p>{{.locale.Tr "webauthn_error_empty"}}</div>
14-
<div class="hide" data-webauthn-error-msg="timeout"><p>{{.locale.Tr "webauthn_error_timeout"}}</div>
15-
<div class="hide" data-webauthn-error-msg="general"></div>
165
</div>
17-
</div>
18-
<div class="actions">
19-
<button onclick="window.location.reload()" class="success ui button hide webauthn_error_timeout">{{.locale.Tr "webauthn_reload"}}</button>
20-
<div class="ui cancel button">{{.locale.Tr "cancel"}}</div>
6+
<div id="webauthn-error-msg" class="">
7+
</div>
8+
<div class="hide" data-webauthn-error-msg="browser"><p>{{.locale.Tr "webauthn_unsupported_browser"}}</div>
9+
<div class="hide" data-webauthn-error-msg="unknown"><p>{{.locale.Tr "webauthn_error_unknown"}}</div>
10+
<div class="hide" data-webauthn-error-msg="insecure"><p>{{.locale.Tr "webauthn_error_insecure"}}</div>
11+
<div class="hide" data-webauthn-error-msg="unable-to-process"><p>{{.locale.Tr "webauthn_error_unable_to_process"}}</div>
12+
<div class="hide" data-webauthn-error-msg="duplicated"><p>{{.locale.Tr "webauthn_error_duplicated"}}</div>
13+
<div class="hide" data-webauthn-error-msg="empty"><p>{{.locale.Tr "webauthn_error_empty"}}</div>
14+
<div class="hide" data-webauthn-error-msg="timeout"><p>{{.locale.Tr "webauthn_error_timeout"}}</div>
2115
</div>
2216
</div>

templates/user/settings/security/webauthn.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
</h4>
44
<div class="ui attached segment">
55
<p>{{.locale.Tr "settings.webauthn_desc" | Str2html}}</p>
6+
{{template "user/auth/webauthn_error" .}}
67
<div class="ui key list">
78
{{range .WebAuthnCredentials}}
89
<div class="item">
@@ -28,7 +29,6 @@
2829
</div>
2930
</div>
3031

31-
{{template "user/auth/webauthn_error" .}}
3232

3333
<div class="ui small basic delete modal" id="delete-registration">
3434
<div class="ui icon header">

0 commit comments

Comments
 (0)