PasskeyAuthenticationOptions handles POST /passkeys/authentication/options. Generates WebAuthn authentication options for discoverable credential login.
(w http.ResponseWriter, r *http.Request)
| 31 | // PasskeyAuthenticationOptions handles POST /passkeys/authentication/options. |
| 32 | // Generates WebAuthn authentication options for discoverable credential login. |
| 33 | func (a *API) PasskeyAuthenticationOptions(w http.ResponseWriter, r *http.Request) error { |
| 34 | config := a.config |
| 35 | db := a.db.WithContext(r.Context()) |
| 36 | |
| 37 | webAuthn, err := a.getPasskeyWebAuthn() |
| 38 | if err != nil { |
| 39 | return apierrors.NewInternalServerError("Failed to initialize WebAuthn").WithInternalError(err) |
| 40 | } |
| 41 | |
| 42 | // Discoverable flow: empty allowCredentials, no user binding |
| 43 | options, session, err := webAuthn.BeginDiscoverableLogin() |
| 44 | if err != nil { |
| 45 | return apierrors.NewInternalServerError("Failed to generate WebAuthn authentication options").WithInternalError(err) |
| 46 | } |
| 47 | |
| 48 | expiresAt := time.Now().Add(config.WebAuthn.ChallengeExpiryDuration) |
| 49 | challenge := models.NewWebAuthnChallenge( |
| 50 | nil, // no user_id for discoverable flow |
| 51 | models.WebAuthnChallengeTypeAuthentication, |
| 52 | &models.WebAuthnSessionData{SessionData: session}, |
| 53 | expiresAt, |
| 54 | ) |
| 55 | |
| 56 | if err := db.Create(challenge); err != nil { |
| 57 | return apierrors.NewInternalServerError("Database error storing challenge").WithInternalError(err) |
| 58 | } |
| 59 | |
| 60 | return sendJSON(w, http.StatusOK, &PasskeyAuthenticationOptionsResponse{ |
| 61 | ChallengeID: challenge.ID.String(), |
| 62 | Options: &options.Response, |
| 63 | ExpiresAt: expiresAt.Unix(), |
| 64 | }) |
| 65 | } |
| 66 | |
| 67 | // PasskeyAuthenticationVerify handles POST /passkeys/authentication/verify. |
| 68 | // Validates the WebAuthn assertion and issues tokens for discoverable credential login. |
nothing calls this directly
no test coverage detected