Authentication API reference
Password reset tokens
Sign up tokens
Profile sessions
The signed-in user's own sessions, mounted under /profile/sessions.
delete_profile_session
delete_profile_session(request, session_id, token_user_id, db)
Delete user session from database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
session_id
|
AuthSessionId
|
Session identifier to delete. |
required |
token_user_id
|
CurrentUserId
|
User ID from access token. |
required |
db
|
DbSession
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None. |
Source code in backend/app/modules/auth/account_security/sessions_router.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
read_sessions_me
read_sessions_me(token_user_id, token_session_id, page, db)
Retrieve one page of the authenticated user's sessions.
is_current marks the session the request is made from; it is false for every item when an API key calls.
Source code in backend/app/modules/auth/account_security/sessions_router.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
revoke_profile_sessions
revoke_profile_sessions(request, response, token_user_id, token_session_id, db, keep_current=False)
Sign out everywhere, or only on the other devices.
By default every session of the authenticated user ends, the current one included, so the client must discard
its tokens and send the user to the login page; the browser's refresh-token cookie is cleared on the response.
With keep_current=true every other session ends and the caller stays signed in, so the cookie is left alone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
response
|
Response
|
The response, on which the refresh-token cookie is cleared. |
required |
token_user_id
|
CurrentUserId
|
User ID from access token. |
required |
token_session_id
|
CurrentSessionId
|
The caller's current session, preserved when |
required |
db
|
DbSession
|
Database session. |
required |
keep_current
|
Annotated[bool, Query(description="Keep the caller's current session and end only the others")]
|
Whether to keep the caller's current session. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
None. |
Source code in backend/app/modules/auth/account_security/sessions_router.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
Profile two-step verification
The signed-in user's own two-step verification, mounted under /profile/mfa.
disable_mfa
disable_mfa(request, body, token_user_id, token_session_id, step_up_store, db)
Disable MFA for authenticated user after step-up verification.
Disabling MFA materially weakens the account's security
posture, so a valid access token alone is not sufficient: the
caller must re-prove identity with both their current
password and a fresh MFA code, both in step_up. The MFA code may be either a
6-digit TOTP or an unused XXXX-XXXX backup code — the
same set of factors accepted at login. Step-up verification
is the single source of truth for the MFA check;
:func:modules.auth.mfa.service.disable_user_mfa only clears state. The user's
other sessions end with the change unless revoke_other_sessions is false.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
body
|
MFADisableRequest
|
The step-up verification, with the MFA code, and whether to end the other sessions. |
required |
token_user_id
|
CurrentUserId
|
User ID from access token. |
required |
token_session_id
|
CurrentSessionId
|
Session ID from access token. |
required |
step_up_store
|
Annotated[StepUpStore, Depends(get_step_up_attempts)]
|
Step-up lockout store. |
required |
db
|
DbSession
|
Database session. |
required |
Raises:
| Type | Description |
|---|---|
DomainError
|
403 if step-up verification fails (the current password is wrong or the MFA code is invalid); 409 if MFA is not currently enabled. |
Source code in backend/app/modules/auth/account_security/mfa_router.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
enable_mfa
enable_mfa(request, response, mfa_request, token_user_id, token_session_id, step_up_store, mfa_secret_store, db)
Enable MFA for authenticated user after step-up verification.
A stolen access token alone must not be sufficient to enrol a
new TOTP secret on a victim's account (which would lock the
legitimate user out and hand the attacker the backup codes).
The caller therefore has to re-prove identity with their
current password before the binding is committed. The step-up
verification is the step_up object (see
:func:modules.auth.account_security.step_up_service.verify_step_up_credentials).
The totp_code in the request body is the fresh enrolment code from the
user's authenticator app and is verified separately by
:func:modules.auth.mfa.service.enable_user_mfa against the secret
issued by POST /profile/mfa/setup. The user's other sessions end with the
change unless revoke_other_sessions is false.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
response
|
Response
|
The response, marked as not cacheable because it carries the backup codes. |
required |
mfa_request
|
MFASetupRequest
|
MFA setup request with the TOTP code and the step-up verification. |
required |
token_user_id
|
CurrentUserId
|
User ID from access token. |
required |
token_session_id
|
CurrentSessionId
|
Session ID from access token. |
required |
mfa_secret_store
|
Annotated[MFASecretStoreBackend, Depends(get_mfa_secret_store)]
|
Temporary secret storage. |
required |
step_up_store
|
Annotated[StepUpStore, Depends(get_step_up_attempts)]
|
Step-up lockout store. |
required |
db
|
DbSession
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
MFABackupCodesRead
|
The freshly issued backup codes and when they were created. |
Raises:
| Type | Description |
|---|---|
DomainError
|
409 if no setup is in progress or MFA is already enabled; 400 if the TOTP code is invalid; 403 if step-up verification fails. |
Source code in backend/app/modules/auth/account_security/mfa_router.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
generate_mfa_backup_codes
generate_mfa_backup_codes(response, request, body, token_user_id, token_session_id, step_up_store, db)
Generate new MFA backup codes for authenticated user.
Requires step-up verification (current password + MFA code,
when MFA is enabled). Issuing new backup codes invalidates
the previous set, so an attacker holding only an access
token must not be able to lock the legitimate user out of
their second factor. The user's other sessions end with the change
unless revoke_other_sessions is false.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
Response
|
The response, marked as not cacheable because it carries the codes. |
required |
request
|
Request
|
FastAPI request object for rate limiting. |
required |
body
|
MFABackupCodesRequest
|
The step-up verification and whether to end the other sessions. |
required |
token_user_id
|
CurrentUserId
|
User ID from access token. |
required |
token_session_id
|
CurrentSessionId
|
Session ID from access token. |
required |
step_up_store
|
Annotated[StepUpStore, Depends(get_step_up_attempts)]
|
Step-up lockout store. |
required |
db
|
DbSession
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
MFABackupCodesRead
|
Response with generated backup codes and timestamp. |
Raises:
| Type | Description |
|---|---|
DomainError
|
403 if step-up verification fails, 404 if user not found, 409 if MFA is not enabled. |
Source code in backend/app/modules/auth/account_security/mfa_router.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
get_backup_code_status
get_backup_code_status(token_user_id, db)
Retrieve MFA backup code status for authenticated user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_user_id
|
CurrentUserId
|
User ID from access token. |
required |
db
|
DbSession
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
MFABackupCodeStatusRead
|
Backup code status with counts and creation date. |
Source code in backend/app/modules/auth/account_security/mfa_router.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
get_mfa_status
get_mfa_status(token_user_id, db)
Return whether the account has MFA and the second factors it has enrolled.
Source code in backend/app/modules/auth/account_security/mfa_router.py
20 21 22 23 24 25 26 27 28 29 30 | |
setup_mfa
setup_mfa(request, response, token_user_id, mfa_secret_store, db)
Initiate MFA setup for authenticated user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
response
|
Response
|
The response, marked as not cacheable because it carries the secret. |
required |
token_user_id
|
CurrentUserId
|
User ID from access token. |
required |
mfa_secret_store
|
Annotated[MFASecretStoreBackend, Depends(get_mfa_secret_store)]
|
Temporary secret storage. |
required |
db
|
DbSession
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
MFASetupRead
|
MFA setup response with secret and QR code. |
Source code in backend/app/modules/auth/account_security/mfa_router.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
Profile identity provider links
The signed-in user's own identity provider links, mounted under /profile/identity-providers.
delete_my_identity_provider
delete_my_identity_provider(idp_id, body, request, token_user_id, token_session_id, step_up_store, db)
Delete (unlink) an identity provider from the authenticated user's account.
This endpoint allows users to remove the association between their account and a specific identity provider. It requires step-up verification (current password or a fresh identity-provider sign-in, and MFA when enabled) and includes safety checks to prevent account lockout by ensuring users maintain at least one authentication method (either a password or another IdP link).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idp_id
|
UUID
|
The ID of the identity provider to unlink. |
required |
body
|
StepUpRequest
|
The step-up verification. |
required |
request
|
Request
|
The FastAPI request object. |
required |
token_user_id
|
UUID
|
User ID extracted from the access token. |
required |
token_session_id
|
CurrentSessionId
|
Session ID from access token. |
required |
step_up_store
|
Annotated[StepUpStore, Depends(get_step_up_attempts)]
|
Step-up lockout store. |
required |
db
|
DbSession
|
Database session. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Returns 204 No Content on successful deletion. |
Raises:
| Type | Description |
|---|---|
DomainError(403)
|
If step-up verification fails. |
DomainError(404)
|
If the identity provider doesn't exist or is not linked to the user's account. |
DomainError(409)
|
If attempting to unlink the last authentication method without having a password set (prevents account lockout). |
DomainError(500)
|
If the deletion operation fails at the database level. |
Notes
- Enforces step-up verification before unlinking.
- Prevents account lockout by ensuring users have at least one authentication method (password or remaining IdP link).
- Logs the unlinking action for audit purposes.
- Uses token-based authentication to ensure users can only unlink their own IdPs.
Source code in backend/app/modules/auth/account_security/identity_links_router.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
get_my_identity_providers
get_my_identity_providers(token_user_id, page, db)
Retrieve one page of the authenticated user's identity provider links.
Each link carries its connection metadata and the provider's name, slug, icon and type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_user_id
|
CurrentUserId
|
The authenticated user's ID from the access token. |
required |
page
|
ListPage
|
The requested window. |
required |
db
|
DbSession
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
IdentityProviderLinkPage
|
The page of the user's identity provider links, oldest first. |
Source code in backend/app/modules/auth/account_security/identity_links_router.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
start_idp_link
start_idp_link(idp_id, link, request, response, token_user_id, token_session_id, step_up_store, state, db)
Start linking an identity provider to the authenticated user's account.
Linking enables persistent sign-in, so it needs step-up verification in step_up: current_password (or, for
an
account without one, idp_reauth), and an MFA code when MFA is enabled. The browser then follows
authorization_url, signs in at the provider, and the callback returns to redirect. For a web client the
response sets a cookie that binds the link to this browser. For a native-app redirect the app opens
authorization_url in the system browser, which is not the app's HTTP client: the URL is an Endurain address
with a single-use ticket that lives two minutes, and the browser that opens it receives the binding cookie and is
redirected to the provider. The callback then returns to redirect with idp_link=success or
idp_link=error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idp_id
|
UuidId
|
The identity provider to link. |
required |
link
|
IdentityProviderLinkStart
|
The frontend return path and the step-up verification. |
required |
request
|
Request
|
The incoming request, read by the rate limiter and for the client address. |
required |
response
|
Response
|
The response, which receives the browser-binding cookie. |
required |
token_user_id
|
CurrentUserId
|
User ID from access token. |
required |
token_session_id
|
CurrentSessionId
|
Session ID from access token. |
required |
step_up_store
|
Annotated[StepUpStore, Depends(get_step_up_attempts)]
|
Step-up lockout store. |
required |
state
|
PlatformState
|
The platform state provider, which holds the link ticket of a native app. |
required |
db
|
DbSession
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
BrowserFlowStartRead
|
The provider's authorization URL, or the ticket URL of a native app. |
Source code in backend/app/modules/auth/account_security/identity_links_router.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
start_idp_step_up
start_idp_step_up(idp_id, start, request, response, token_user_id, token_session_id, step_up_store, db)
Start a fresh sign-in with a linked identity provider, for an account without a local password.
Such an account has no password to prove, so a sensitive operation asks for this instead: the browser
follows authorization_url, the provider signs the user in again, and the callback returns to
redirect with a single-use step_up_ticket in the URL fragment. The sensitive request then sends the
ticket and the PKCE verifier of code_challenge as idp_reauth. The response sets a cookie that binds
the sign-in to this browser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idp_id
|
UuidId
|
The linked provider to sign in with again. |
required |
start
|
StepUpStartRequest
|
The PKCE challenge, the operation and the return path. |
required |
request
|
Request
|
The incoming request, read by the rate limiter. |
required |
response
|
Response
|
The response, which receives the browser-binding cookie. |
required |
token_user_id
|
CurrentUserId
|
User ID from access token. |
required |
token_session_id
|
CurrentSessionId
|
Session ID from access token. |
required |
step_up_store
|
Annotated[StepUpStore, Depends(get_step_up_attempts)]
|
Step-up lockout store. |
required |
db
|
DbSession
|
Database session. |
required |
Returns:
| Type | Description |
|---|---|
BrowserFlowStartRead
|
The provider's authorization URL. |
Source code in backend/app/modules/auth/account_security/identity_links_router.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |