Examples
Enable and disable two-factor authentication
Turn authenticator 2FA on or off with CSRF and ReAuth.
Manage authenticator 2FA for a signed-in user. Paths are under /identity/manage/2fa. POST requires authorization, CSRF (RequestVerificationToken), and ReAuth. Body shape is Identity TwoFactorRequest.
Assume cookie session (credentials: "include") and a fresh CSRF token from GET /identity/csrfToken.
Read status
- Sign in.
GET /identity/manage/2fa.- Response includes
isTwoFactorEnabled.
Enable
- Complete step-up: Complete step-up (ReAuth) (password, 2FA, or passkey proof).
- Mint or refresh the authenticator shared key with
POST /identity/manage/2faand body{}(plus CSRF). When no key exists, the response includessharedKey. - Show the shared key (or QR) in the authenticator app.
- Complete ReAuth again if the ReAuth cookie expired (5 minutes).
POST /identity/manage/2fawith{ "enable": true, "twoFactorCode": "<6-digit TOTP>" }and CSRF.- On
200, storerecoveryCodesfrom the response when present.isTwoFactorEnabledistrue.
Do not send enable: true together with resetSharedKey: true. That combination returns a validation problem.
Disable
- Complete ReAuth.
POST /identity/manage/2fawith{ "enable": false }and CSRF.- On
200,isTwoFactorEnabledisfalse.
To rotate the authenticator key, set resetSharedKey: true (this also disables 2FA until you enable again with a code from the new key).
Optional flags on POST
| Field | Effect |
|---|---|
resetRecoveryCodes | Issues a new set of recovery codes |
forgetMachine | Clears the two-factor remember-client cookie |
Sign in after 2FA is enabled
Password cookie login: POST /identity/login with email, password, and either twoFactorCode or twoFactorRecoveryCode when Identity requires 2FA. Login does not require CSRF. See Cookie auth.