Step-up
A sensitive action asks a recent authentication (requireRecentAuth(), 403 REAUTHENTICATION_REQUIRED) or a recent second factor (requireMfa({ maxAge }), 403 MFA_REQUIRED). The step-up authenticates the current session again, without a new login. It needs the sessions store and mfa.
method is password, totp, email, sms, recovery_code or passkey. A code by email or SMS comes with the challengeToken of /auth/step-up/send, sent back with the code: see Codes by email or SMS. A passkey comes with the challengeToken of POST /auth/step-up/passkey/options and the response of the browser: see Passkeys. A wrong password answers 401 INVALID_PASSWORD, a wrong code 400 INVALID_CODE: 10 failures per 15 minutes per user (rateLimits.stepUp.user, and rateLimits.mfa.verify for the second factors), then 429 TOO_MANY_REQUESTS. Both also count 30 attempts per 15 minutes, atomically: a TOTP or recovery code has no challenge of its own, and the failures are written after the check, so of parallel guesses 30 at most are checked.
The step-up routes refuse impersonation sessions (403 IMPERSONATION_FORBIDDEN): the staff member does not hold the credentials of the user. With mode: 'cookie', POST /auth/step-up from an untrusted origin answers 403 CROSS_ORIGIN_REQUEST.
The session records reauthenticatedAt, and mfaVerifiedAt for a second factor. The answer holds a new token pair of the same session, whose amr adds the method (pwd, otp, email, sms, hwk or swk for a passkey) and mfa for a second factor: an API that checks the tokens without the sessions store sees it. A passkey adds mfa when the authenticator verified the user, or in a session not opened by a passkey. auth_time stays the start of the session. In cookie mode (mode: 'cookie'), the pair replaces the cookies. The previous refresh token keeps working, with its amr.
The app answers 403 MFA_REQUIRED by a step-up, then retries with the new access token.
auth.stepUp.send({ session }) and auth.stepUp.verify({ session, method, … }) do the same outside the routes; session is ctx.auth.