Skip to content

Handling authentication

Endurain's web and mobile apps sign in through an authentication system that includes username/password authentication, Multi-Factor Authentication (MFA), OAuth/SSO integration with PKCE (S256), and JWT-based session management with refresh token rotation and reuse detection. /auth/login is a username/password grant, which OAuth 2.1 does not include, so Endurain does not claim to be OAuth 2.1 compliant.

First-party sign-in

The /auth sign-in routes (login, MFA verification, password change, token exchange and refresh) and the SSO hand-off through ALLOWED_REDIRECT_URIS are first-party protocols for Endurain's own web and mobile apps. Other applications use API keys today, and the OAuth endpoints, reserved under /oauth/*, when they exist. A later release may refuse other applications on the first-party routes.

API Requirements

  • Client Type Header: POST /auth/login, /auth/mfa/verify, /auth/password-change, /auth/sessions/{session_id}/tokens, /auth/refresh and /auth/logout require an X-Client-Type header with web or mobile; a missing or unknown value is 422. On these operations it is an ordinary header parameter in the OpenAPI document, not a security scheme. It selects the shape of the response, and on /auth/refresh and /auth/logout a web request is also subject to the origin check. The session and API-key management routes, and every other route, never read it. The other flows follow the endpoint-specific requirements below.
  • Where the routes live: the routes that obtain, renew or end a session (/auth/login, /auth/mfa/verify, /auth/password-change, /auth/sessions/{session_id}/tokens, /auth/refresh, /auth/logout) are under /auth. Every other route a visitor can call without signing in is under /public (see Public endpoints).
  • PKCE on password sign-in: a mobile client sends code_challenge and code_challenge_method (S256) as form fields of POST /auth/login; both are required. A web client sends neither: the field is refused. A missing, refused or malformed field is 422, and it is checked before the password. The MFA step and the password-change step carry no PKCE values; the sign-in keeps the ones the password step sent.
  • OAuth/PKCE Client Type Binding: For /public/idp/login/{idp_slug} (decided by the redirect alone, never by a header) and a mobile password sign-in, the backend records a client_type on the PKCE/OAuth state. POST /auth/sessions/{session_id}/tokens requires X-Client-Type, and it must match the stored value, which controls the response shape. A different value is refused with the same 400 as a wrong code_verifier, so a session one kind of client started cannot be redeemed by the other.
  • Authorization: Most protected JWT requests must include an Authorization: Bearer <access token> header with a valid access token. Login, MFA verification, the password-change step, OAuth initiation/callback/token exchange, password reset, sign-up, and activity uploads authenticated with an API key are exceptions.
  • Origin check of the cookie routes (web only): The refresh token is an httpOnly SameSite=Strict cookie that only POST /auth/refresh and POST /auth/logout read. A request to either route that declares X-Client-Type: web must carry an Origin header equal to one of the origins the server allows (ENDURAIN_HOST, plus the development origins in a development install): a missing, null or foreign Origin is 403 with urn:endurain:error:permission-denied, and so is a Sec-Fetch-Site: cross-site header. same-origin is not required, because a development front end on another port is same-site but not same-origin. A request that declares mobile is not checked, since a mobile client sends its refresh token in the body and uses no cookie. There is no CSRF token: every other route reads its credential from the Authorization header, which a browser never sends on its own, and the login routes read no cookie, so they rely on the CORS preflight that their form and custom headers trigger. The controls are therefore X-Client-Type, the SameSite=Strict cookie and the origin check. They cover a forged cross-site request, or one from a sibling subdomain, to the two cookie routes; script running in the page itself (XSS) is out of scope for this control.
  • Two kinds of 401: urn:endurain:error:invalid-token (with WWW-Authenticate: Bearer error="invalid_token", or plain Bearer when no token was sent) means only that the access token of a resource route is missing, expired or invalid: refresh once with POST /auth/refresh and replay the request. urn:endurain:error:session-ended (with WWW-Authenticate: Session) is final: /auth/refresh answers it for every refusal, and /auth/mfa/verify and /auth/password-change answer it for a dead pending sign-in. Clear the local session and send the user to sign in; do not retry. A failed password sign-in at /auth/login is a plain 401 that also carries WWW-Authenticate: Session, because the route has no bearer scheme. Session is a scheme token without parameters. /auth/logout never answers 401.

API Key Authentication

Every authenticated endpoint accepts an API key as an alternative to a Bearer token. API key requests do not require the X-Client-Type header. See API Key Authentication for details.

Token Handling

Token Lifecycle

  • The backend generates an access_token valid for 15 minutes (default) and a refresh_token valid for 7 days (default).
  • The access_token is used for authorization; the refresh_token is used to obtain new access tokens.
  • Both tokens are JWTs signed with HS256. The JOSE header carries typ (at+jwt for an access token, rt+jwt for a refresh token) and kid, the id of the signing key; the scope claim is a space-separated string of the scopes the token carries (RFC 9068). The sub claim of both is the user's UUID. A client treats both tokens as opaque and does not read them.
  • The two kinds cannot stand in for each other (RFC 8725): each is signed with a key of its own, derived from SECRET_KEY for that kind, and carries its own audience. Both have iss set to ENDURAIN_HOST. An access token's aud is ENDURAIN_HOST; a refresh token's aud is the URL of the refresh endpoint, <ENDURAIN_HOST>/api/v1/auth/refresh (/auth/logout accepts the same token). Both carry client_type, the client type (web or mobile) of the session they belong to, and no client_id.
  • iat, nbf and exp are checked with 60 seconds of leeway, so a token issued by a replica whose clock is slightly ahead, or one that expired a moment ago, is still accepted. It does not lengthen a session: an access token is honoured only while its session exists, and a refresh token only against its session.
  • Token and session lifetimes are set by an administrator in Settings > Server settings > Access & security > Sessions (see Session Configuration).
  • A session ends at the absolute session timeout whatever its activity: 720 hours (30 days) by default. An idle timeout (on at 72 hours by default) also ends a session after inactivity, and an unused session ends after the refresh token lifetime (7 days by default). Administrators change the access token, refresh token, idle and absolute settings in Settings > Server settings > Access & security > Sessions. A client should read refresh_token_expires_in rather than assume a lifetime. The server checks both timeouts on every request, not only at refresh: a request whose session passed either answers 401 with urn:endurain:error:invalid-token, the same as for a revoked session, and the refresh that follows is refused for good. The idle timeout counts from the last refresh, so an access token must live shorter than it: PUT /server-settings answers 422 when the idle timeout is enforced and access_token_expire_minutes is at or above session_idle_timeout_hours in minutes.

Token storage model (hybrid approach)

Endurain splits web tokens between memory and an httpOnly cookie:

Token Storage Location Lifetime Security Purpose
Access Token In-memory (JavaScript) 15 minutes Short-lived, never written to storage
Refresh Token httpOnly cookie 7 days SameSite=Strict, Path=/, no Domain
Device id Web: httpOnly cookie (endurain_device, or __Host-endurain_device in production and demo, path /, SameSite=Strict). Mobile: the app's own storage, sent as the X-Device-Id header 400 days from the last sign-in Recognises the browser or app, so a sign-in from a new one sends a security notice, and a known one is not held by the account lock. Not a credential; the server stores only its SHA-256 hash

Cookie names: In production and demo, where the cookies carry Secure, their names carry a prefix: the refresh, device and identity provider binding cookies carry __Host- (__Host-endurain_refresh_token, __Host-endurain_device, __Host-endurain_idp_binding), which a browser stores only with Secure, Path=/ and no Domain so a sibling subdomain cannot plant one. Development serves plain HTTP and keeps the plain names.

Security Properties:

  • XSS exposure: Keeping the access token in memory keeps it out of storage that a browser extension or a later page can read, and it expires in minutes. It does not stop script running in the page: that script can call POST /auth/refresh, which the browser answers with the httpOnly cookie, and read the fresh access token from the response. The refresh route checks Origin, which script in the page satisfies, and the CSP allows no inline script, which stops injected markup from running one (next point).
  • Cross-site requests: Protected routes authenticate with the Authorization header, which a browser never sends on its own, and the refresh token is an httpOnly SameSite=Strict cookie. The two routes that read the cookie also verify Origin (see the origin check above).
  • Content Security Policy: HTML responses carry a CSP whose script-src and style-src allow no inline script and no inline style (no 'unsafe-inline'), and it carries base-uri 'self', object-src 'none' and frame-ancestors 'none'. The app writes styles through the CSSOM, which style-src does not block, and the SPA's meta policy is equally strict. The only exceptions are the API documentation pages (/api/v1/docs and /api/v1/redoc, served in development and demo only): their policy allows exactly their own inline script by SHA-256 hash and keeps 'unsafe-inline' for styles, because the documentation UIs style themselves. The defences that remain beside the policy are never rendering user data with v-html, keeping the access token out of persistent storage, and the SameSite=Strict refresh cookie. Every response carries X-Frame-Options: DENY, Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Resource-Policy: same-site. Every HTML response carries Referrer-Policy: no-referrer, so a token in a page URL never leaves the page; the map tile requests set strict-origin-when-cross-origin themselves, because tile servers such as OpenStreetMap require a Referer. A JSON response carries Content-Security-Policy: default-src 'none'; frame-ancestors 'none' and Referrer-Policy: strict-origin-when-cross-origin. In a deployed environment (not development) every response carries Strict-Transport-Security: max-age=31536000; includeSubDomains, plus ; preload when HSTS_PRELOAD is true. Error responses carry these headers too. A reverse proxy that sets its own Content-Security-Policy or cross-origin policies replaces them, so let Endurain's headers through.
  • Self-declared client type: X-Client-Type is chosen by the caller, so it selects the response shape and whether the origin check applies but proves nothing about who is calling. This is an accepted risk: a caller that declares mobile reads no cookie, since the refresh token must then be in the body, and it still needs a valid refresh token. A session keeps the client type it was created for, so a web session's refresh token taken out of its cookie cannot be refreshed by declaring mobile.
  • Session Persistence: Page reload triggers /auth/refresh with httpOnly cookie to restore tokens
  • Multi-tab Support: httpOnly cookie shared across browser tabs

Token Delivery by Client Type

  • For web apps:

    • Access token returned in JSON response body (stored in-memory)
    • Refresh token set as httpOnly cookie (endurain_refresh_token; __Host-endurain_refresh_token in production and demo)
    • Password login, MFA verification, the password-change step and the SSO token exchange also set the endurain_device cookie (prefixed like the refresh cookie), which names the browser for new-device sign-in notices
    • On page reload, call /auth/refresh to restore in-memory tokens
  • For mobile apps:

  • Password login (with its PKCE challenge) and OAuth/SSO return a session_id first; the app exchanges that session with its PKCE verifier to receive access and refresh tokens. A mobile sign-in never answers tokens directly
    • Store tokens in secure platform storage (iOS Keychain, Android EncryptedSharedPreferences)
  • Device id: send X-Device-Id on /auth/login, /auth/mfa/verify, /auth/password-change and the /auth/sessions/{session_id}/tokens exchange, with the value the server returned earlier (43 characters of A-Z a-z 0-9 - _; a missing or malformed value counts as none). A sign-in from an id the account has not used before sends the user a new-device notice, except the first device of an account that has no known device and was created in the last 24 hours. When the app sends no valid id, the server mints one and returns it as device_id in the response body: in the session body of a password login, an MFA verification or a password change, and in the token body of the exchange of an SSO sign-in or of the MFA verification that finishes one. The field is null on /auth/refresh, and absent from every web body, in a login answer and in the token exchange alike (a browser keeps its id in the cookie). Store it in secure storage next to the tokens and send it on every later sign-in. It is not a credential, and responses that carry it are Cache-Control: no-store.

Authentication Flows

Standard Login Flow (Username/Password)

  1. Client sends credentials to /auth/login endpoint
  2. Backend validates credentials and checks for account lockout
  3. Backend answers with a body whose next_step says what the client does next (see Sign-in steps)
  4. The client follows the steps until it receives tokens or exchange
  5. Tokens are delivered based on client type:
    • Web: Access token in response body, refresh token as httpOnly cookie
    • Mobile: A session ID, exchanged for the tokens in the response body with the PKCE verifier (see Mobile Password Login with PKCE)

Sign-in steps

Every answer of POST /auth/login, POST /auth/mfa/verify, POST /auth/password-change and POST /auth/sessions/{session_id}/tokens carries a required next_step. A client switches on it; the other members of the body depend on its value.

next_step Meaning Body members The client
mfa A second factor must be verified mfa_challenge, methods (the kinds of code the account can answer with, such as totp and backup_code; an open set) Asks for the MFA code and sends it with the challenge to POST /auth/mfa/verify. The challenge lives 5 minutes, ends at the third wrong code (the first two are 400, the third 401), and is accepted only from the client network (an IPv4 address or an IPv6 /64) and client type of the step that answered it (the password sign-in, or the token exchange of an SSO session); a dead challenge is 401 and the client restarts the sign-in
password_change An administrator set the account's password, so the user must choose a new one before a session exists password_change_challenge Asks for a new password and sends it with the challenge to POST /auth/password-change
exchange A mobile client gets a session to exchange session_id, device_id Exchanges the session at /auth/sessions/{session_id}/tokens with its PKCE verifier
tokens The client is signed in session_id, access_token, expires_in, refresh_token_expires_in, token_type, and, for a mobile client only, refresh_token and device_id Stores the tokens

POST /auth/refresh answers the tokens body too: the same two bodies, token_type is bearer in both, the web body has no refresh_token (it is in the cookie), and the mobile body has refresh_token and device_id. The two bodies are not told apart by a discriminator: the OpenAPI response of /auth/refresh, /auth/sessions/{session_id}/tokens and /auth/mfa/verify is an anyOf of the bodies the operation can answer, and both token bodies carry next_step: "tokens". The body is the one of the X-Client-Type the request sent, so a client reads the fields of its own client type and does not pick the body by which fields are present. /auth/login can answer mfa, password_change, exchange (mobile) or tokens (web). /auth/sessions/{session_id}/tokens answers tokens, or mfa for an SSO session of an account with MFA (see Accounts with MFA enabled). /auth/mfa/verify answers password_change, exchange (mobile) or tokens (web) after a password sign-in, and tokens of either client type after the exchange of an SSO session. /auth/password-change answers exchange (mobile) or tokens (web).

Treat an unknown next_step as \"update the app\"

The set of steps can grow. A client that receives a next_step it does not know cannot continue the sign-in: it must stop, keep no partial state and tell the user that the app needs an update. Do not guess from the other members of the body.

Password change at sign-in

password is optional in the body of POST /users. Without it the account is created active with no password, and the server emails its owner an invitation, in the owner's language, that says an administrator created the account and carries a 24-hour link. The link opens /signup/confirm#token=… on the frontend, which posts the token and the password the owner chose to POST /public/sign-up/confirm (see Confirming a link); that also marks the address verified, and it works while sign-up is turned off. Until then the account cannot sign in with a password, like an account that only signs in through an identity provider. A request without a password is 400 with urn:endurain:error:password-required when the server has no mail configured to send the invitation, and 422 when active is false, because the invitation cannot activate an account. The users.user.create audit entry carries invited, true for such an account.

When an administrator sets a user's password, or creates the account with one (POST /users with a password), the administrator knows it, so the account must replace it at its next password sign-in. An administrator can also require the change without setting a password, through POST /users/{user_id}/password/require-change: the user keeps the current password until the next password sign-in, where the same password_change step applies. That route ends all of the user's sessions and answers 409 for an account that has no local password. POST /auth/login (and POST /auth/mfa/verify for an account with MFA, after the code is verified) then answers password_change instead of tokens and creates no session. The password_change_challenge is valid for 10 minutes, works once, and names the sign-in, its client type and its PKCE values. A security change on the account before it is used, such as another password set by an administrator, ends it, and so does one before a pending POST /auth/sessions/{session_id}/tokens exchange is redeemed.

POST /api/v1/auth/password-change
Content-Type: application/json
X-Client-Type: web|mobile

{
  "password_change_challenge": "<password_change_challenge from the sign-in response>",
  "password": "the new password"
}

The new password must meet the account's password policy and differ from the current one. The answer is the one the sign-in would have given: tokens for a web client, or exchange for a mobile client. The new password, its audit entry and the session are one transaction, and unused password-reset links are voided.

Status Meaning
401 The challenge is unknown, expired or already used, was issued to the other client type, or the account no longer needs to change its password. One answer for all of these
403 The account is no longer active
422 The password does not meet the policy (the type names why, for example urn:endurain:error:password-too-short). The challenge stays valid, so the client can ask again
429, 503 Rate limit, or the shared sign-in state is unavailable

Sign-in through an identity provider (SSO) does not use the password, so it is not affected: an account whose password an administrator set can still sign in with its provider.

OAuth/SSO Flow

  1. Client requests list of enabled providers from /public/idp
  2. Client initiates OAuth at /public/idp/login/{idp_slug} with a PKCE challenge. A redirect listed in ALLOWED_REDIRECT_URIS (a custom-scheme or claimed-https address, for example com.endurain.endurain:/auth/sso/callback) records the flow as mobile; a relative redirect, or none, records web. The route reads no X-Client-Type header, because the system browser that starts the flow cannot send one. Its redirect sets the endurain_idp_binding cookie, which binds the login to this browser.
  3. User authenticates with the OAuth provider
  4. Provider redirects back to /public/idp/callback/{idp_slug} with authorization code. A callback without the browser's binding cookie is refused like an unknown state.
  5. Backend exchanges code for provider tokens and user info
  6. Backend creates or links the user account, creates a session, and redirects the client with a session_id
  7. The client exchanges the session for tokens via the PKCE token exchange endpoint /auth/sessions/{session_id}/tokens. The exchange response follows the stored client type; the X-Client-Type header is required and must match it, or the exchange is refused:
  8. Web clients: Access token in response body, refresh token as httpOnly cookie
  9. Mobile clients: Access token + refresh token in response body

The session from step 6 lasts only as long as the sign-in's OAuth state (10 minutes), is not listed in the session lists and cannot be used until the exchange; the exchange gives it its normal lifetime. A session that is never exchanged is removed after those 10 minutes.

Token Refresh Flow

The token refresh flow rotates the refresh token on every call:

  1. When access token expires, client calls POST /auth/refresh:
    • Web clients: Send the Origin header the browser adds (the origin check refuses a missing or foreign one with 403)
    • Mobile clients: Send the refresh token in the JSON body, {"refresh_token": "<Refresh Token>"}, never in the Authorization header (that header carries access tokens only). A missing token is 401
    • Web clients send no body: the refresh cookie is the only source, and a token in a web request's body is not read
  2. Backend validates refresh token and session, checks for token reuse
    • If token reuse detected: Entire token family is invalidated (security breach response)
    • Retry within the grace period: an already rotated refresh token presented again within 10 seconds is answered with the same replacement refresh token only for the client that rotated it (same IPv4 address or IPv6 /64, and same User-Agent). From any other client it counts as reuse and ends the session
    • Client type: a session is refreshed only with the X-Client-Type it was created for. A web session's refresh token presented as mobile, or a mobile one as web, is refused like an invalid token
    • Every refusal (the session ended or expired, belongs to the other client type, the token is invalid, expired or reused, or the user was deleted or deactivated) is 401 with urn:endurain:error:session-ended and WWW-Authenticate: Session, and the response clears the web client's refresh cookie. The same answer covers a user deactivated while a retry was replayed. Every 401 from /auth/refresh is final: do not retry it, sign in again. A refused origin is 403 and keeps the cookie, so it does not end the session.
  3. New tokens are generated (access and refresh) with refresh token rotation
  4. Old refresh token is stored for reuse detection, with a fingerprint of the rotating client's network and User-Agent (grace period: 10 seconds; the record is kept until the old token would have expired)
  5. Response includes new tokens; web clients receive new httpOnly cookie

Token Refresh Request (Web):

POST /api/v1/auth/refresh
X-Client-Type: web
Origin: https://endurain.example.com
Cookie: __Host-endurain_refresh_token={refresh_token}

Token Refresh Response (Web):

{
  "next_step": "tokens",
  "session_id": "550e8400-e29b-41d4-a716-446655440000",
  "access_token": "eyJ...",
  "token_type": "bearer",
  "expires_in": 900,
  "refresh_token_expires_in": 604800
}

Token Refresh Response (Mobile):

{
  "next_step": "tokens",
  "session_id": "550e8400-e29b-41d4-a716-446655440000",
  "access_token": "eyJ...",
  "refresh_token": "eyJ...",
  "token_type": "bearer",
  "expires_in": 900,
  "refresh_token_expires_in": 604800,
  "device_id": null
}

refresh_token_expires_in is an upper bound on the number of seconds until the client must sign in again: the refresh token's remaining lifetime, or the time left before the session reaches the absolute session timeout when that comes first. The session can end sooner, when the idle timeout passes or a change of the account's credentials ends it (see Ending other sessions), so a client does not schedule its sign-out by it and treats the 401 of a refresh as the answer. The refresh cookie of a web client expires at the same time. Every response that carries it (a web login, MFA verification, refresh and the token exchange) follows this rule.

Refresh Token Rotation & Reuse Detection

Endurain implements automatic refresh token rotation with reuse detection to prevent token theft:

Security Feature Description
Automatic Rotation New refresh token issued on every /auth/refresh call
Token Family Tracking All tokens in a session share a token_family_id
Reuse Detection Old tokens are stored until they would have expired and monitored for reuse
Grace Period A retry within 10 seconds of a rotation is answered with the replacement token only for the client that rotated it (same IPv4 address or IPv6 /64, and same User-Agent). From any other client, or after 10 seconds, presenting the old token counts as reuse and ends the session
Family Invalidation If reuse detected, ALL tokens in family are invalidated
Rotation Count Tracks number of rotations for audit purposes

API Key Authentication Flow

For integrations that do not maintain a JWT session, API keys provide a stateless alternative:

  1. Generate an API key via the web UI (Settings → Security → Sessions & access → API keys) or the management API (requires JWT)
  2. Store the raw key securely — it is shown only once at creation time
  3. Include the key in requests to supported endpoints via the X-API-Key header, or via the ?api_key= query parameter only when ALLOW_API_KEY_QUERY_PARAM=true is explicitly enabled
  4. The backend validates the key hash, checks revocation and expiry, and resolves the user identity and scopes
  5. The endpoint processes the request if the required scope is present in the key's grant

See API Key Authentication for the complete reference.

API Endpoints

The API is reachable under /api/v1. Below are the authentication-related endpoints. The complete interactive API documentation (OpenAPI) is served at /api/v1/docs (Swagger UI) and /api/v1/redoc, for example http://localhost:8080/api/v1/docs; the schema itself is /openapi.json. Both are only available when the ENVIRONMENT variable is set to development or demo; in production they are disabled, and the published API reference holds the schema.

Core Authentication Endpoints (Web)

What Url Expected Information Rate Limit
Authorize /auth/login Header: X-Client-Type: web; FORM with fields: username and password. code_challenge and code_challenge_method are refused (422). HTTPS highly recommended 10 requests/min
Refresh Token /auth/refresh Header: X-Client-Type: web; Cookie: __Host-endurain_refresh_token (endurain_refresh_token in development); Header: Origin (added by the browser) 30 requests/min
Verify MFA /auth/mfa/verify Header: X-Client-Type: web; JSON {'mfa_challenge': <mfa_challenge from /auth/login or the token exchange>, 'mfa_code': '123456'} 10 requests/min
Change Password /auth/password-change Header: X-Client-Type: web; JSON {'password_change_challenge': <password_change_challenge from /auth/login or /auth/mfa/verify>, 'password': '<new password>'} 10 requests/min
Logout /auth/logout Header: X-Client-Type: web; Header: Origin (added by the browser); Cookie: __Host-endurain_refresh_token (endurain_refresh_token in development) 30 requests/min

Core Authentication Endpoints (Mobile)

What Url Expected Information Rate Limit
Authorize /auth/login Header: X-Client-Type: mobile; FORM with fields: username, password, code_challenge, code_challenge_method (S256); all four are required. HTTPS highly recommended 10 requests/min
Refresh Token /auth/refresh Header: X-Client-Type: mobile; JSON body: {'refresh_token': <Refresh Token>} 30 requests/min
Verify MFA /auth/mfa/verify Header: X-Client-Type: mobile; JSON body: {'mfa_challenge': <mfa_challenge from /auth/login or the token exchange>, 'mfa_code': '123456'}. No PKCE values: the challenge of the password step is kept with the MFA challenge, and the token exchange of an SSO session has already checked its verifier 10 requests/min
Change Password /auth/password-change Header: X-Client-Type: mobile; JSON {'password_change_challenge': <password_change_challenge from /auth/login or /auth/mfa/verify>, 'password': '<new password>'}. The PKCE values of the sign-in are kept with the challenge 10 requests/min
Logout /auth/logout Header: X-Client-Type: mobile; JSON body: {'refresh_token': <Refresh Token>} 30 requests/min

Logout

POST /auth/logout ends the session named by the refresh token and answers 200 with Cache-Control: no-store and a JSON body:

{ "idp_logout_url": "https://idp.example.com/logout?id_token_hint=...&client_id=...&post_logout_redirect_uri=https%3A%2F%2Fendurain.example.com%2Flogin" }

idp_logout_url is null unless the session signed in through an identity provider whose discovery document names an end_session_endpoint (OpenID Connect RP-Initiated Logout 1.0). Then it is that endpoint with the query parameters id_token_hint (the ID token the provider issued at sign-in), client_id and, for a web client only, post_logout_redirect_uri (<ENDURAIN_HOST>/login), added to any query string the endpoint already has. The URL carries the ID token, so use it once and do not store or log it.

  • Web client: the session is already ended and the refresh cookie cleared when the answer arrives. When idp_logout_url is an https: URL, navigate the browser to it so the provider ends its session and sends the user back to the login page; otherwise show the login page.
  • Mobile client: the session is already ended. To also end the provider session, open idp_logout_url in the system browser (ASWebAuthenticationSession or Custom Tabs), as for sign-in. It has no post_logout_redirect_uri, so the provider shows its own signed-out page. A client that does not open it leaves the provider session in place.

Logout is idempotent. A refresh token that is missing, malformed, expired, revoked, of the wrong kind, or whose session no longer exists ends nothing and gets the same 200 answer with idp_logout_url: null, so signing out twice is fine and /auth/logout never answers 401. A web client's refresh cookie is cleared in every one of those answers, so the browser never keeps a dead cookie. A mobile client gets the same answer for a missing or invalid refresh_token in the body, and should delete its stored tokens whatever the answer. A web logout whose Origin is missing or not allowed is 403 (urn:endurain:error:permission-denied), checked before the token is read: no session is ended.

The Endurain session is ended and committed before the provider is asked for its endpoint. If the provider cannot be reached for it, logout still succeeds with idp_logout_url: null and the provider session stays.

The reverse also holds: signing out at a provider that supports back-channel logout ends the Endurain sessions signed in through it, and the client's next request or refresh is 401. See Provider-initiated sign-out.

OAuth/SSO Endpoints

What Url Expected Information Rate Limit
Get Enabled Providers /public/idp None (public endpoint). Paged: optional page_number (default 1) and num_records (default 25, maximum 200); the response is {items, total, page, num_records, next} 120 requests/min
Initiate OAuth Login /public/idp/login/{idp_slug} No X-Client-Type header: a redirect listed in ALLOWED_REDIRECT_URIS marks the flow as mobile, a relative one or none as web. Query params: redirect, code_challenge, code_challenge_method. Sets the endurain_idp_binding cookie; the callback must arrive in the same browser 10 requests/min per IP
OAuth Callback /public/idp/callback/{idp_slug} Query params: state=<state> and code=<code>, or error=<provider error code> when the provider refused; iss=<issuer> is read as well (RFC 9207): it must equal the provider's issuer exactly when present, and is required when the provider's discovery document sets authorization_response_iss_parameter_supported. Always answers with a redirect to the frontend; a failed login lands on /login?error=sso_failed, or on the native redirect the sign-in started with (?error=...), or a more specific code (sso_email_missing, sso_email_unverified, sso_auto_create_disabled, sso_link_by_email_disabled, sso_approval_pending or sso_account_disabled), see SSO failures 10 requests/min per IP
Token Exchange (PKCE) POST /auth/sessions/{session_id}/tokens Header: X-Client-Type (web or mobile), which must match the client type stored on the PKCE/OAuth state; JSON: {"code_verifier": "<verifier>"} (mobile password sign-in or SSO); any other member is 422. Answers the tokens body of the client type, or the mfa step for an SSO session of an account with MFA 10 requests/min
Start IdP Link POST /profile/identity-providers/{idp_id}/link Requires authenticated session and a step_up object in the JSON body: current_password for local-password accounts, idp_reauth for accounts without one, and mfa_code when MFA is enabled; plus an optional redirect (a relative frontend path, or a native address listed in ALLOWED_REDIRECT_URIS). Returns authorization_url and sets the endurain_idp_binding cookie. The browser then navigates to authorization_url. 409 if already linked 10 requests/min
Start IdP Step-up POST /profile/identity-providers/{idp_id}/step-up Requires authenticated session. JSON: code_challenge, action, redirect (relative path). Returns authorization_url and sets the endurain_idp_binding cookie. See Account security 10 requests/min

Session Management Endpoints

What Url Expected Information
Get Own Sessions /profile/sessions Header: Authorization: Bearer <Access Token>; requires account:security scope. Paged like the admin list. Each session carries app_redirect_uri: the native-app redirect address an SSO sign-in handed it to, or null, and is_current, true for the session the request is made from (always false when an API key calls)
Delete Own Session /profile/sessions/{session_id} Same headers and scope
Sign Out Everywhere /profile/sessions/revoke (POST) Same headers and scope, no body and no step-up; optional query keep_current (default false). Without it, ends every session of the caller, the current one included, and clears the refresh-token cookie, so the client discards its tokens and shows the login page. With keep_current=true, ends every session except the current one and leaves the cookie alone. Answers 204; records one auth.session.revoke audit row
Get User Sessions (admin) /users/{user_id}/sessions Header: Authorization: Bearer <Access Token>; requires sessions:read scope. Paged: optional page_number (default 1) and num_records (default 25, maximum 200); the response is {items, total, page, num_records, next}. Each session has is_current, true only for the caller's own session, so it is false for every item unless the administrator lists their own sessions
Revoke Session (admin) /users/{user_id}/sessions/{session_id}/revoke (POST) Header: Authorization: Bearer <Access Token>; requires sessions:write scope. Body: the administrator's step-up; answers 204
Revoke User Sessions (admin) /users/{user_id}/sessions/revoke (POST) Same headers, scope and body; optional exclude_session_id query parameter keeps that session; ends every other session of the user; answers 204
List User API Keys (admin) /users/{user_id}/api-keys Header: Authorization: Bearer <Access Token>; requires api-keys:read scope. Same paging and page envelope as the sessions list; each item is the key's metadata (name, prefix, scopes, dates, active flag), never its secret. 404 when the user does not exist
Revoke User API Key (admin) /users/{user_id}/api-keys/{api_key_id}/revoke (POST) Same headers; requires api-keys:write scope. Body: the administrator's step-up; answers 204. The key stops authenticating at once; 404 when it does not belong to the user. Writes an auth.api_key.revoke audit row and sends the owner a security notice
Revoke All User API Keys (admin) /users/{user_id}/api-keys/revoke (POST) Same headers, scope and body; revokes every active key of the user and answers 204, also when there were none. Writes an auth.api_keys.revoke audit row with the number of keys revoked, and sends the owner a security notice when at least one was

A session_id, api_key_id or device id that is not a UUID is 422; an unknown one is 404.

API Key Management Endpoints

Require JWT authentication. API keys cannot manage other API keys.

Method Url Description
GET /profile/api-keys List one page of API keys for the authenticated user
POST /profile/api-keys Create an API key after step-up verification. An account holds at most 25 active keys
POST /profile/api-keys/{api_key_id}/revoke Revoke an API key owned by the authenticated user
DELETE /profile/api-keys/{api_key_id} Permanently delete an API key owned by the authenticated user

Example Resource Endpoints

What Url Expected Information
Activity Upload POST /activities/upload .gpx, .tcx, .gz or .fit file. Accepts JWT or API key (X-API-Key header, or ?api_key= query param only when ALLOW_API_KEY_QUERY_PARAM=true) with activities:upload scope, as every authenticated endpoint does. Answers 202 with an ingestion job
Job GET /jobs/{job_id} Poll the job returned by the upload. An upload job needs the activities:upload scope
Set Weight POST /health/weight JSON {'weight_kg': <number>, 'date': 'yyyy-MM-dd'}; requires health:write scope