oficina / home Public

Add browser-bound direct passkey sign-in and atomic enrollment

Paul Campbell pushed by paul@keymail.dev 939f1f6ede9b0d94eb81bf6536c1e07e307399f4 parent 97660e9
9 files changed, +492 −13
  • implementation/oficina-id-slice1-validation.md +6 −0
  • internal/home/app.go +8 −6
  • internal/home/id_passkey.go +340 −0
  • internal/home/id_passkey_test.go +111 −0
  • internal/home/migrations/0003_id_ceremonies.sql +13 −0
  • internal/home/signin.go +1 −1
  • internal/home/static/passkey.js +7 −4
  • internal/home/templates/passkey_enrol.html +1 −2
  • internal/home/templates/signin.html +5 −0

CI failed — run details

diff --git a/implementation/oficina-id-slice1-validation.md b/implementation/oficina-id-slice1-validation.md
index fe73bee..1b28f22 100644
--- a/implementation/oficina-id-slice1-validation.md
+++ b/implementation/oficina-id-slice1-validation.md
@@ -12,3 +12,9 @@ Agent record, 2026-11-13. No deploy or merge.
## Mutations
Pending.
+
+- Task 2: direct sign-in and proof-negative tests failed with 404 before the
+ handlers existed. Credential-transfer test failed because enrollment replaced
+ the first person's row. All now pass, along with enrollment freshness and
+ existing gated-sign-in tests. New registrations use the existing WebAuthn
+ helper's required resident key and user verification options.
diff --git a/internal/home/app.go b/internal/home/app.go
index 5901425..db23107 100644
--- a/internal/home/app.go
+++ b/internal/home/app.go
@@ -245,10 +245,12 @@ func (a *App) Router() http.Handler {
// with script off, because recovery is exactly the moment WebAuthn
// is not working.
r.Get(confirmPath, a.handlePasskeyConfirm)
- r.Post("/passkey/stepup/begin", a.passkeys.StepUpBegin)
- r.Post("/passkey/stepup/finish", a.passkeys.StepUpFinish)
- r.Post("/passkey/signin/begin", a.passkeys.SignInBegin)
- r.Post("/passkey/signin/finish", a.passkeys.SignInFinish)
+ r.Post("/passkey/direct/begin", a.idBegin("direct"))
+ r.Post("/passkey/direct/finish", a.idFinish("direct"))
+ r.Post("/passkey/stepup/begin", a.idBegin("stepup"))
+ r.Post("/passkey/stepup/finish", a.idFinish("stepup"))
+ r.Post("/passkey/signin/begin", a.idBegin("signin"))
+ r.Post("/passkey/signin/finish", a.idFinish("signin"))
r.Post("/passkey/signin/recovery", a.passkeys.SignInRecovery)
// Enrolling changes who can get in, and there is no operator reset,
// so it wants a recent session rather than merely a valid one — see
@@ -256,8 +258,8 @@ func (a *App) Router() http.Handler {
r.Group(func(r chi.Router) {
r.Use(a.sessions.RequireFresh(enrolFreshness))
r.Get("/passkey/enrol", a.handlePasskeyEnrol)
- r.Post("/passkey/register/begin", a.passkeys.RegisterBegin)
- r.Post("/passkey/register/finish", a.passkeys.RegisterFinish)
+ r.Post("/passkey/register/begin", a.idBegin("register"))
+ r.Post("/passkey/register/finish", a.idFinish("register"))
})
// The codes page shows ten codes once, so it wants a recent session
diff --git a/internal/home/id_passkey.go b/internal/home/id_passkey.go
new file mode 100644
index 0000000..28bba33
--- /dev/null
+++ b/internal/home/id_passkey.go
@@ -0,0 +1,340 @@
+package home
+
+import (
+ "context"
+ "database/sql"
+ "encoding/base64"
+ "encoding/hex"
+ "encoding/json"
+ "errors"
+ "net/http"
+ "strings"
+ "time"
+
+ "amadan.net/rastrillo/rastrillo/sessions"
+ "amadan.net/rastrillo/rastrillo/webauthn"
+)
+
+const ceremonyCookie = "__Host-oficina-ceremony"
+const gateCookie = "__Host-rastrillo_passkey_pending"
+
+var errIDProof = errors.New("home: identity proof refused")
+
+func idCookie(w http.ResponseWriter, name, value string, seconds int) {
+ http.SetCookie(w, &http.Cookie{Name: name, Value: value, Path: "/", MaxAge: seconds, Secure: true, HttpOnly: true, SameSite: http.SameSiteLaxMode})
+}
+func cookieValue(r *http.Request, name string) string {
+ value := ""
+ count := 0
+ for _, c := range r.Cookies() {
+ if c.Name == name {
+ value = c.Value
+ count++
+ }
+ }
+ if count != 1 || len(value) > 4096 {
+ return ""
+ }
+ return value
+}
+func idJSONReply(w http.ResponseWriter, status int, v any) {
+ w.Header().Set("Cache-Control", "no-store")
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(status)
+ _ = json.NewEncoder(w).Encode(v)
+}
+func idRefuse(w http.ResponseWriter) {
+ idJSONReply(w, http.StatusBadRequest, map[string]string{"error": "ceremony failed"})
+}
+func (a *App) idTransaction(ctx context.Context) (*sql.Tx, int64, error) {
+ tx, err := a.db.Writer().BeginTx(ctx, nil)
+ if err != nil {
+ return nil, 0, errIDProof
+ }
+ now := time.Now().Unix()
+ if _, err = tx.ExecContext(ctx, "UPDATE home_id_clock SET high_water=MAX(high_water,?) WHERE id=1", now); err != nil {
+ tx.Rollback()
+ return nil, 0, errIDProof
+ }
+ var high int64
+ if err = tx.QueryRowContext(ctx, "SELECT high_water FROM home_id_clock WHERE id=1").Scan(&high); err != nil || now < high {
+ tx.Rollback()
+ return nil, 0, errIDProof
+ }
+ return tx, high, nil
+}
+
+func (a *App) idWebAuthn() webauthn.Config {
+ return webauthn.Config{RPID: a.credentialHost, Origin: a.origins.Credential, LegacyRPID: a.passkeyCfg.LegacyRPID}
+}
+
+// Read the live session inside the writer transaction, so recovery revocation
+// and a simultaneous enrollment or session mint cannot pass one another.
+func (a *App) idSession(tx *sql.Tx, r *http.Request, now int64) (sessions.Session, string, error) {
+ token := cookieValue(r, a.sessions.CookieName())
+ if token == "" {
+ return sessions.Session{}, "", errIDProof
+ }
+ hash := sessions.HashToken(token)
+ var s sessions.Session
+ var auth, created, expires string
+ err := tx.QueryRow("SELECT subject,method,auth_time,created_at,expires_at FROM sessions WHERE token_hash=?", hash).Scan(&s.Subject, &s.Method, &auth, &created, &expires)
+ exp, e := time.Parse(time.RFC3339, expires)
+ if err != nil || e != nil || exp.Unix() <= now {
+ return s, "", errIDProof
+ }
+ s.AuthTime, _ = time.Parse(time.RFC3339, auth)
+ s.At, _ = time.Parse(time.RFC3339, created)
+ return s, hash, nil
+}
+func (a *App) idBinding(tx *sql.Tx, r *http.Request, purpose string, now int64) (subject, binding string, err error) {
+ switch purpose {
+ case "direct":
+ v := cookieValue(r, ceremonyCookie)
+ if v == "" {
+ return "", "", errIDProof
+ }
+ return "", sessions.HashToken(v), nil
+ case "signin":
+ v := cookieValue(r, gateCookie)
+ if v == "" {
+ return "", "", errIDProof
+ }
+ binding = sessions.HashToken(v)
+ var exp string
+ err = tx.QueryRow("SELECT subject,expires_at FROM passkey_pending WHERE token_hash=?", binding).Scan(&subject, &exp)
+ at, e := time.Parse(time.RFC3339, exp)
+ if err != nil || e != nil || at.Unix() <= now {
+ return "", "", errIDProof
+ }
+ return subject, binding, nil
+ default:
+ s, hash, e := a.idSession(tx, r, now)
+ if e != nil {
+ return "", "", e
+ }
+ if purpose == "register" && (!sessions.Fresh(s, enrolFreshness, time.Unix(now, 0)) || strings.Contains(s.Method, "recovery")) {
+ return "", "", errIDProof
+ }
+ return s.Subject, hash, nil
+ }
+}
+func (a *App) idBegin(purpose string) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ tx, now, err := a.idTransaction(r.Context())
+ if err != nil {
+ idRefuse(w)
+ return
+ }
+ defer tx.Rollback()
+ var direct string
+ if purpose == "direct" {
+ direct, _, err = sessions.NewToken()
+ if err != nil {
+ idRefuse(w)
+ return
+ }
+ r = r.Clone(r.Context())
+ r.Header = r.Header.Clone()
+ r.Header.Del("Cookie")
+ r.AddCookie(&http.Cookie{Name: ceremonyCookie, Value: direct})
+ }
+ subject, binding, err := a.idBinding(tx, r, purpose, now)
+ if err != nil {
+ idRefuse(w)
+ return
+ }
+ if _, err = tx.Exec("DELETE FROM home_id_ceremonies WHERE expires_at<=? OR (browser_hash=? AND purpose=?)", now, binding, purpose); err != nil {
+ idRefuse(w)
+ return
+ }
+ var n int
+ if err = tx.QueryRow("SELECT count(*) FROM home_id_ceremonies").Scan(&n); err != nil || n >= 10000 {
+ idRefuse(w)
+ return
+ }
+ challenge, err := webauthn.NewChallenge()
+ if err != nil {
+ idRefuse(w)
+ return
+ }
+ if _, err = tx.Exec("INSERT INTO home_id_ceremonies VALUES (?,?,?,?,?)", hex.EncodeToString(challenge), binding, subject, purpose, now+300); err != nil {
+ idRefuse(w)
+ return
+ }
+ if err = tx.Commit(); err != nil {
+ idRefuse(w)
+ return
+ }
+ if direct != "" {
+ idCookie(w, ceremonyCookie, direct, 300)
+ }
+ idJSONReply(w, 200, map[string]string{"challenge": base64.RawURLEncoding.EncodeToString(challenge)})
+ }
+}
+
+type idCeremony struct {
+ ID string `json:"id"`
+ ClientData string `json:"clientDataJSON"`
+ AuthData string `json:"authenticatorData"`
+ Signature string `json:"signature"`
+ Attestation string `json:"attestationObject"`
+}
+
+func decodeIDCeremony(w http.ResponseWriter, r *http.Request) (idCeremony, []byte, []byte, error) {
+ var body idCeremony
+ d := json.NewDecoder(http.MaxBytesReader(w, r.Body, 64<<10))
+ d.DisallowUnknownFields()
+ if d.Decode(&body) != nil {
+ return body, nil, nil, errIDProof
+ }
+ cd, err := base64.RawURLEncoding.Strict().DecodeString(body.ClientData)
+ if err != nil {
+ return body, nil, nil, errIDProof
+ }
+ var c struct {
+ Challenge string `json:"challenge"`
+ }
+ if json.Unmarshal(cd, &c) != nil {
+ return body, nil, nil, errIDProof
+ }
+ challenge, err := base64.RawURLEncoding.Strict().DecodeString(c.Challenge)
+ if err != nil || len(challenge) != 32 {
+ return body, nil, nil, errIDProof
+ }
+ return body, cd, challenge, nil
+}
+
+// This is the narrow storage adapter to replace when upstream auth can supply
+// address-blind storage AND transaction-owned session minting. Keep the proof
+// consumption, live credential check and session write on this same writer.
+func (a *App) idMint(tx *sql.Tx, r *http.Request, s sessions.Session, now int64) (string, error) {
+ token, hash, err := sessions.NewToken()
+ if err != nil {
+ return "", errIDProof
+ }
+ stamp := time.Unix(now, 0).UTC().Format(time.RFC3339)
+ if old := cookieValue(r, a.sessions.CookieName()); old != "" {
+ if _, err = tx.Exec("DELETE FROM sessions WHERE token_hash=?", sessions.HashToken(old)); err != nil {
+ return "", errIDProof
+ }
+ }
+ _, err = tx.Exec("INSERT INTO sessions(token_hash,subject,method,auth_time,created_at,expires_at) VALUES(?,?,?,?,?,?)", hash, s.Subject, s.Method, stamp, stamp, time.Unix(now, 0).Add(30*24*time.Hour).UTC().Format(time.RFC3339))
+ if err != nil {
+ return "", errIDProof
+ }
+ return token, nil
+}
+func (a *App) idFinish(purpose string) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+ body, cd, challenge, err := decodeIDCeremony(w, r)
+ if err != nil {
+ idRefuse(w)
+ return
+ }
+ tx, now, err := a.idTransaction(r.Context())
+ if err != nil {
+ idRefuse(w)
+ return
+ }
+ defer tx.Rollback()
+ subject, binding, err := a.idBinding(tx, r, purpose, now)
+ if err != nil {
+ idRefuse(w)
+ return
+ }
+ var consumed string
+ err = tx.QueryRow("DELETE FROM home_id_ceremonies WHERE challenge=? AND browser_hash=? AND subject=? AND purpose=? AND expires_at>? RETURNING challenge", hex.EncodeToString(challenge), binding, subject, purpose, now).Scan(&consumed)
+ if err != nil {
+ idRefuse(w)
+ return
+ }
+ refuse := func() { _ = tx.Commit(); idRefuse(w) }
+ if purpose == "register" {
+ att, e := base64.RawURLEncoding.Strict().DecodeString(body.Attestation)
+ if e != nil {
+ refuse()
+ return
+ }
+ cred, e := a.idWebAuthn().Register(challenge, cd, att)
+ if e != nil {
+ refuse()
+ return
+ }
+ id := hex.EncodeToString(cred.ID)
+ if _, e = tx.Exec("INSERT INTO passkey_credentials(id,subject,public_key,sign_count,created_at) VALUES(?,?,?,?,?)", id, subject, cred.PublicKey, cred.SignCount, time.Unix(now, 0).UTC().Format(time.RFC3339)); e != nil {
+ idRefuse(w)
+ return
+ }
+ if _, e = tx.Exec("INSERT INTO home_id_discoverable VALUES(?)", id); e != nil {
+ idRefuse(w)
+ return
+ }
+ if tx.Commit() != nil {
+ idRefuse(w)
+ return
+ }
+ idJSONReply(w, 200, map[string]bool{"ok": true})
+ return
+ }
+ id, e := base64.RawURLEncoding.Strict().DecodeString(body.ID)
+ if e != nil {
+ refuse()
+ return
+ }
+ ad, e := base64.RawURLEncoding.Strict().DecodeString(body.AuthData)
+ if e != nil {
+ refuse()
+ return
+ }
+ sig, e := base64.RawURLEncoding.Strict().DecodeString(body.Signature)
+ if e != nil {
+ refuse()
+ return
+ }
+ var owner string
+ var cred webauthn.Credential
+ cred.ID = id
+ query := "SELECT subject,public_key,sign_count FROM passkey_credentials WHERE id=?"
+ if purpose == "direct" {
+ query += " AND id IN (SELECT credential_id FROM home_id_discoverable)"
+ }
+ if e = tx.QueryRow(query, hex.EncodeToString(id)).Scan(&owner, &cred.PublicKey, &cred.SignCount); e != nil || (subject != "" && owner != subject) {
+ refuse()
+ return
+ }
+ next, e := a.idWebAuthn().Verify(cred, challenge, cd, ad, sig)
+ if e != nil {
+ refuse()
+ return
+ }
+ if _, e = tx.Exec("UPDATE passkey_credentials SET sign_count=? WHERE id=?", next, hex.EncodeToString(id)); e != nil {
+ idRefuse(w)
+ return
+ }
+ method, to := "passkey", readReturn(r)
+ if purpose == "signin" {
+ if e = tx.QueryRow("DELETE FROM passkey_pending WHERE token_hash=? RETURNING method,return_to", binding).Scan(&method, &to); e != nil {
+ idRefuse(w)
+ return
+ }
+ method += "+passkey"
+ }
+ token, e := a.idMint(tx, r, sessions.Session{Subject: owner, Method: method}, now)
+ if e != nil {
+ idRefuse(w)
+ return
+ }
+ if e = tx.Commit(); e != nil {
+ idRefuse(w)
+ return
+ }
+ idCookie(w, a.sessions.CookieName(), token, 30*24*3600)
+ idCookie(w, ceremonyCookie, "", -1)
+ if purpose == "signin" {
+ idCookie(w, gateCookie, "", -1)
+ }
+ writeReturn(w, "/")
+ idJSONReply(w, 200, map[string]any{"ok": true, "to": to})
+ }
+}
diff --git a/internal/home/id_passkey_test.go b/internal/home/id_passkey_test.go
new file mode 100644
index 0000000..5139d2d
--- /dev/null
+++ b/internal/home/id_passkey_test.go
@@ -0,0 +1,111 @@
+package home
+
+import (
+ "encoding/base64"
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/home/internal/home/sealtest"
+ "amadan.net/rastrillo/rastrillo/webauthn/authtest"
+)
+
+func idJSON(t *testing.T, app *testApp, path string, body any, cookies ...*http.Cookie) *httptest.ResponseRecorder {
+ t.Helper()
+ b, err := json.Marshal(body)
+ if err != nil {
+ t.Fatal(err)
+ }
+ req := httptest.NewRequest("POST", Origin+path, strings.NewReader(string(b)))
+ req.Header.Set("Origin", Origin)
+ req.Header.Set("Content-Type", "application/json")
+ for _, c := range cookies {
+ if c != nil {
+ req.AddCookie(c)
+ }
+ }
+ w := httptest.NewRecorder()
+ app.Router().ServeHTTP(w, req)
+ return w
+}
+func assertionBody(a *authtest.Authenticator, challenge []byte, opts authtest.Options) map[string]string {
+ cd, ad, sig, _ := a.Get(challenge, opts)
+ return map[string]string{"id": base64.RawURLEncoding.EncodeToString(a.CredID), "clientDataJSON": base64.RawURLEncoding.EncodeToString(cd), "authenticatorData": base64.RawURLEncoding.EncodeToString(ad), "signature": base64.RawURLEncoding.EncodeToString(sig)}
+}
+func TestIDDirectPasskey(t *testing.T) {
+ app := newTestApp(t)
+ session := signInFully(t, app, sealtest.CanaryAddress)
+ key := enrol(t, app, session)
+ begin := idJSON(t, app, "/passkey/direct/begin", nil)
+ challenge := challengeFrom(t, begin)
+ cookie := namedCookie(t, begin, "__Host-oficina-ceremony")
+ body := assertionBody(key, challenge, authtest.Options{RPID: credentialHost, Origin: Origin})
+ wrong := idJSON(t, app, "/passkey/direct/finish", body)
+ if sessionCookie(wrong) != nil || wrong.Code == 200 {
+ t.Fatal("unbound browser signed in")
+ }
+ done := idJSON(t, app, "/passkey/direct/finish", body, cookie)
+ if done.Code != 200 || sessionCookie(done) == nil {
+ t.Fatal("direct sign-in failed", done.Code)
+ }
+ if subjectOf(t, app, sessionCookie(done)) != subjectOf(t, app, session) {
+ t.Fatal("wrong person")
+ }
+ replay := idJSON(t, app, "/passkey/direct/finish", body, cookie)
+ if sessionCookie(replay) != nil || replay.Code == 200 {
+ t.Fatal("replay signed in")
+ }
+ sealtest.AssertNoPlaintext(t, app.dbPath)
+}
+func TestIDPasskeyRejectsBadProofs(t *testing.T) {
+ for _, kind := range []string{"origin", "rp", "uv", "signature", "unknown", "expired", "purpose"} {
+ t.Run(kind, func(t *testing.T) {
+ app := newTestApp(t)
+ s := signInFully(t, app, sealtest.CanaryAddress)
+ key := enrol(t, app, s)
+ begin := idJSON(t, app, "/passkey/direct/begin", nil)
+ challenge := challengeFrom(t, begin)
+ c := namedCookie(t, begin, "__Host-oficina-ceremony")
+ opts := authtest.Options{RPID: credentialHost, Origin: Origin}
+ switch kind {
+ case "origin":
+ opts.Origin = "https://evil.invalid"
+ case "rp":
+ opts.RPID = "oficina.works"
+ case "uv":
+ opts.Flags = authtest.FlagUserPresent
+ case "signature":
+ opts.CorruptSig = true
+ case "unknown":
+ key, _ = authtest.New()
+ case "expired":
+ if _, err := app.db.Writer().Exec("UPDATE home_id_ceremonies SET expires_at=?", time.Now().Unix()-1); err != nil {
+ t.Fatal(err)
+ }
+ case "purpose":
+ if _, err := app.db.Writer().Exec("UPDATE home_id_ceremonies SET purpose='register'"); err != nil {
+ t.Fatal(err)
+ }
+ }
+ r := idJSON(t, app, "/passkey/direct/finish", assertionBody(key, challenge, opts), c)
+ if r.Code == 200 || sessionCookie(r) != nil {
+ t.Fatal("bad proof signed in", kind)
+ }
+ })
+ }
+}
+func TestIDEnrollmentCannotTransferCredential(t *testing.T) {
+ app := newTestApp(t)
+ first := signInFully(t, app, sealtest.CanaryAddress)
+ key := enrol(t, app, first)
+ second := signInFully(t, app, "other@example.invalid")
+ challenge := challengeFrom(t, idJSON(t, app, "/passkey/register/begin", nil, second))
+ cd, att := key.Create(challenge, authtest.Options{RPID: credentialHost, Origin: Origin})
+ got := idJSON(t, app, "/passkey/register/finish", map[string]string{"clientDataJSON": base64.RawURLEncoding.EncodeToString(cd), "attestationObject": base64.RawURLEncoding.EncodeToString(att)}, second)
+ if got.Code == 200 {
+ t.Fatal("credential transferred to another person")
+ }
+}
diff --git a/internal/home/migrations/0003_id_ceremonies.sql b/internal/home/migrations/0003_id_ceremonies.sql
new file mode 100644
index 0000000..ee21efc
--- /dev/null
+++ b/internal/home/migrations/0003_id_ceremonies.sql
@@ -0,0 +1,13 @@
+CREATE TABLE home_id_clock (id INTEGER PRIMARY KEY CHECK (id = 1), high_water INTEGER NOT NULL);
+INSERT INTO home_id_clock VALUES (1, 0);
+CREATE TABLE home_id_ceremonies (
+ challenge TEXT PRIMARY KEY,
+ browser_hash TEXT NOT NULL,
+ subject TEXT NOT NULL,
+ purpose TEXT NOT NULL,
+ expires_at INTEGER NOT NULL
+);
+CREATE INDEX home_id_ceremonies_expiry ON home_id_ceremonies(expires_at);
+CREATE TABLE home_id_discoverable (
+ credential_id TEXT PRIMARY KEY REFERENCES passkey_credentials(id) ON DELETE CASCADE
+);
diff --git a/internal/home/signin.go b/internal/home/signin.go
index b757edd..e459ff0 100644
--- a/internal/home/signin.go
+++ b/internal/home/signin.go
@@ -178,7 +178,7 @@ func (a *App) handleSigninForm(w http.ResponseWriter, r *http.Request) {
// form is on screen, so an error page that dropped the override would
// send a forced retry straight back to Keymail.
func (a *App) renderSigninForm(w http.ResponseWriter, r *http.Request, status int, msg string) {
- data := map[string]any{}
+ data := a.passkeyPageData("", nil)
if msg != "" {
data["Error"] = msg
}
diff --git a/internal/home/static/passkey.js b/internal/home/static/passkey.js
index 74b3fc5..7d7e560 100644
--- a/internal/home/static/passkey.js
+++ b/internal/home/static/passkey.js
@@ -57,16 +57,17 @@ async function enrol(button) {
}
}
-async function confirm(button) {
+async function confirm(button, direct = false) {
button.disabled = true;
try {
- const begin = await post("/passkey/signin/begin");
+ const path = direct ? "/passkey/direct" : "/passkey/signin";
+ const begin = await post(path + "/begin");
const got = await authenticate({
challenge: begin.challenge,
rpId: document.body.dataset.rpid,
legacyRpId: document.body.dataset.legacyrpid || undefined,
});
- const done = await post("/passkey/signin/finish", {
+ const done = await post(path + "/finish", {
id: got.credentialId,
clientDataJSON: got.clientDataJSON,
authenticatorData: got.authenticatorData,
@@ -74,10 +75,12 @@ async function confirm(button) {
});
window.location.assign(done.to || "/");
} catch (err) {
- say(button, "That did not work. Use a recovery code below.");
+ say(button, "That did not work. You can try again.");
}
}
reveal();
document.getElementById("passkey-enrol")?.addEventListener("click", (e) => enrol(e.currentTarget));
document.getElementById("passkey-confirm")?.addEventListener("click", (e) => confirm(e.currentTarget));
+
+document.getElementById("passkey-direct")?.addEventListener("click", (e) => confirm(e.currentTarget, true));
diff --git a/internal/home/templates/passkey_enrol.html b/internal/home/templates/passkey_enrol.html
index 09a06d3..32c3ad8 100644
--- a/internal/home/templates/passkey_enrol.html
+++ b/internal/home/templates/passkey_enrol.html
@@ -2,8 +2,7 @@
{{define "bodyattrs"}} data-rpid="{{.Data.RPID}}" data-userid="{{.Data.UserID}}" data-username="{{.Data.UserName}}"{{end}}
{{define "content"}}
<h1>Add a passkey</h1>
-<p>A passkey is an optional second step. Without one, your email link is
-the only thing standing between someone with your inbox and your account.</p>
+<p>Add a passkey to sign in without entering your email. JavaScript is needed to add and use passkeys.</p>
<button id="passkey-enrol" type="button" rst-btn="primary" data-passkey hidden>Add a passkey</button>
<p id="passkey-status" role="status"></p>
<noscript><p rst-callout><span rst-callout-body>Adding a passkey needs JavaScript. Everything else here does not.</span></p></noscript>
diff --git a/internal/home/templates/signin.html b/internal/home/templates/signin.html
index 2c2f816..6a6ca3c 100644
--- a/internal/home/templates/signin.html
+++ b/internal/home/templates/signin.html
@@ -1,6 +1,8 @@
{{define "title"}}{{signinDoor.Title}}{{end}}
{{define "content"}}{{with signinDoor}}
<h1>{{.Heading}}</h1>
+<button id="passkey-direct" type="button" rst-btn="primary" data-passkey hidden>Sign in with a passkey</button>
+<p id="passkey-status" role="status"></p>
{{if $.Data.Error}}<p role="alert" rst-callout rst-tone="negative"><span rst-callout-body>{{$.Data.Error}}</span></p>{{end}}
<form method="post" action="{{with $.Data.Action}}{{.}}{{else}}/signin{{end}}" rst-form estilo-signin-form>
<div rst-field>
@@ -13,3 +15,6 @@
</div>
</form>
{{end}}{{end}}
+
+{{define "bodyattrs"}} data-rpid="{{.Data.RPID}}" data-legacyrpid="{{.Data.LegacyRPID}}"{{end}}
+{{define "scripts"}}<script type="module" src="/static/passkey.js"></script>{{end}}