Authentication and sessions
The runtime signs people in two ways: through an external OIDC provider, or with local accounts whose passwords it stores itself. Both produce the same exchange code, session, and canonical user. Local accounts covers the second.
The runtime uses the openidconnect library for Authorization Code Flow and S256 PKCE.
Discovery supplies trusted issuer metadata and signing keys.
The adapter disables HTTP redirects for provider requests.
HTTPS issuers must advertise HTTPS authorization, token, and key endpoints.
New signing key IDs trigger rediscovery from the same configured issuer.
Browser integration
The browser has an application cookie only. The application backend retains the runtime session credential. The runtime does not depend on third-party cookies or arbitrary identity headers.
- The application creates a random state and exchange verifier.
- The application stores both values in its backend session.
- The backend calls
POST /v1/auth/flowswith its service credential. - The request names a permitted organization, connection, exact redirect URI, state, and S256 verifier challenge.
- The browser visits the returned runtime login URL.
- The runtime consumes the login handle and redirects to the configured issuer.
- The issuer authenticates the user and returns an authorization code and state.
- The runtime consumes the matching, unexpired flow.
It rejects the response if it arrived on another connection's callback URL, or if its RFC 9207
issparameter names another issuer. It also rejects a response withoutisswhen the issuer's discovery metadata setsauthorization_response_iss_parameter_supported. - The OIDC library exchanges the code with its PKCE verifier.
- The library verifies signature, issuer, audience, expiration, nonce, and applicable access-token hash.
- The provisioning provider resolves the verified subject and immutable directory claim to a canonical user.
- The runtime redirects to the exact application URI with a single-use exchange code and application state.
- The application verifies the state against its backend session.
- The backend redeems the exchange code with its service credential and verifier.
- The runtime atomically consumes the grant and creates a hashed session credential.
- The application regenerates its cookie session and retains the runtime credential on the backend.
Login flows expire after five minutes.
Exchange grants expire after 60 seconds.
Session expiration follows sessions.ttl_seconds, with a maximum of one day.
The example encrypts the runtime credential before its PostgreSQL session store persists it.
The runtime consumes each flow before the upstream exchange. If the upstream request fails, the user must start another login. The runtime never includes a long-lived token in a redirect URL.
GET /v1/me verifies the session and returns canonical identity, session metadata, and the user's membership in that session's organization.
The membership can be null before invitation acceptance, or until SCIM provisions the person.
Reading this context does not require access to the member roster.
Applications must still check active membership and the permission for each protected operation.
POST /v1/auth/logout revokes the local runtime session.
Logout does not terminate the upstream IdP session.
An organization suspension denies organization operations immediately, even if the session remains valid.
The example checks project:read before it queries project data.
It checks create and delete permissions separately.
When a runtime session expires, the example clears its local session and returns to sign-in.
Local logout also completes when the runtime has already expired or revoked the session.
Removing an organization's service scope denies pending exchange grants without consuming them or creating sessions. Disabling the OIDC capability stops new login flows and callbacks. It does not revoke existing sessions or unexpired exchange grants. Revoke sessions separately when a deployment requires immediate termination.
Let people sign in with their work email
When the application doesn't know a person's organization yet, it can let the runtime ask for their email.
Call POST /v1/auth/discovery instead of POST /v1/auth/flows, with the same redirect URI, state and verifier challenge but no organization or connection.
The redirect URI must be configured for a connection of one of the service's organizations.
The response's login_url opens a runtime page that asks for a work email.
The page takes the email's domain and looks for an organization among those the service lists that has verified the domain and routes it, as POST /v1/administration/login-route does.
When it finds one, the browser continues into that organization's single sign-on, and the application receives a login code as from any other sign-in.
When it finds none, the browser returns to the redirect URI with error=sso_not_configured and the application's state, so the application can offer its own sign-in instead.
The runtime doesn't send the email to the application or the identity provider.
The link works once and expires after 10 minutes.
A mistyped address shows the form again without using up the link.
With the SDK, call client.auth.discover({ redirectUri, state, exchangeChallenge }).
Keep your own users and sessions
An application that already has users, sessions and login can use the runtime only for single sign-on.
This is broker mode.
The login flow is the same up to step 14, but the backend redeems the code with POST /v1/auth/exchange/profile instead of POST /v1/auth/exchange.
The request body and checks are the same: the service credential needs auth:login for the organization, and the verifier must match the challenge.
The runtime consumes the grant and returns the verified sign-in without creating a runtime session:
{
"user": {
"id": "usr_…",
"email": "alice@example.com",
"display_name": "Alice",
"external_id": "42",
"created_at": "…",
"updated_at": "…"
},
"organization_id": "acme",
"membership": { "role": "member", "status": "active", "…": "…" },
"connection_id": "acme-okta",
"authenticated_at": "2026-11-15T09:30:00Z",
"amr": ["pwd", "mfa"],
"acr": null
}The application matches user.external_id or user.id to its own account, then starts its own session.
Before the first SSO sign-in, import the application's stable user ID and link the customer's immutable provider subject to the resulting canonical user in a reviewed migration. Existing SaaS walkthrough
membership can be null for the same reasons as in GET /v1/me.
In the TypeScript SDK the call is client.auth.exchangeProfile(code, verifier).
Broker mode moves session lifetime to the application, so a directory deactivation or suspension no longer ends the user's session on its own.
The runtime still refuses new sign-ins and pending codes for that user.
To end existing application sessions, have the backend subscribe the organization to a webhook for user.deactivated, membership.updated and membership.deleted, and sign the user out when membership stops being active.
With include_profile, the same webhook keeps the application's copy of each user's email and name current as the directory changes them.
Configure another provider
- Register a confidential OIDC client with Authorization Code Flow.
- Register the exact runtime callback URI,
/v1/auth/callback. Customer-managed OIDC connections use/v1/auth/callback/{organization_id}instead; see the administration guide. - Put the client secret in the environment variable named by
client_secret_env. - Set the connection issuer and client ID in the YAML configuration.
- List the permitted organizations in
organization_ids. - Configure exact application redirect URIs.
- Restart the runtime.
- Run the browser integration test.
A connection can serve one organization or an explicit list of organizations. A shared connection preserves the same canonical identity across those organizations. Each organization still requires its own membership and a separate scoped session. Separate connection IDs deliberately create separate identity mappings. Connections with different verified issuer or subject identifiers never merge by email.
The local Keycloak and Dex configurations use the same public application contract.
Production configuration requires HTTPS.
The development: true flag explicitly permits HTTP for local infrastructure.
Keycloak can federate an upstream customer IdP such as Entra ID. The customer identity source and the runtime authentication implementation remain separate concepts. The generic adapter does not migrate canonical mappings between different connection IDs or issuers.
Membership on first sign-in
An organization admin can set jit_role in the SSO configuration, shown as Role for first sign-in on the Single sign-on page.
Once that configuration is active, a person who signs in without a membership joins with that role when either:
- they signed in through the organization's own connection, or
- their verified email address is in one of the organization's verified domains.
The role must be configured and can't be owner.
When the current or proposed configuration grants a first-sign-in role, the administrator needs sso:write,
members:write, and authority to delegate both roles. A portal credential must include both operations.
The runtime rechecks these permissions before activation commits.
If a tenant changes its dedicated connection while a sign-in is underway, start a new sign-in.
Pending exchange codes from the previous version expire at activation. Independent recovery and shared deployment
connections keep serving their own sign-ins.
An existing membership keeps its role and status, so a suspended member stays suspended.
SCIM directories and invitations keep working as before; this covers customers who turn on SSO without SCIM.
Each membership created this way is audited as administration.membership.jit_created.
Invitations
Invitations contain a random bearer token, a role, an email address, and an expiration.
The invitation row holds the token hash. The creator receives the token once.
Set local_authentication.invitation_accept_url to the host's invitation landing page on a registered application origin. OE returns acceptance_url with the organization and token. When a local SMTP outbox is configured, OE queues the link and returns email_queued: true. The pending delivery holds a sealed copy until its worker sends or expires it. The host can copy the link or deliver the returned token through its own trusted channel.
The Fastify starter handles /invite, binds the link to the browser's sign-in attempt, and accepts it using the authenticated session. To replace a pending or recently expired link, call POST /v1/organizations/{id}/invitations/{invitation}/reissue. This rotates the secret and preserves the recipient and role. Accepted and cancelled invitations cannot be reissued.
With local accounts under the invitation registration policy, the token also permits registering the invited address. First-time local registration verifies the mailbox separately, including when an administrator shared the invitation link manually. With an existing verified SSO identity, the application can sign the recipient in on its configured connection and accept the invitation with that session.
Acceptance requires an authenticated session for the invitation organization and a verified matching email. Acceptance consumes the invitation and creates the membership in one transaction. An invitation cannot replace an existing role or reactivate a suspended membership. Only an owner can grant ownership or change another owner through user APIs.
Passwords and brokered SAML
For OIDC and SAML connections, the external IdP owns passwords, registration, email verification, recovery, and MFA. The runtime never sees those passwords. The standard Keycloak browser fixture covers password login through OIDC.
With local accounts, the runtime stores Argon2id password hashes and TOTP seeds sealed with a deployment key, and serves its own sign-in, registration, recovery, and account pages.
Local sessions record amr and acr values for password, password plus TOTP, and password plus recovery code.
See local accounts.
For SAML, Keycloak validates the customer's signed assertion and returns a signed OIDC ID token.
The runtime checks the configured immutable directory claim and the signed upstream_idp claim.
The kc_idp_hint parameter selects the login screen; the signed claim enforces the upstream restriction.
An account profile field that users can edit must never supply either claim.
The SAML fixture creates the required administrator-controlled mappings.
Directory status is checked during login, exchange, session verification, and authorization. Deactivation revokes every runtime session and pending exchange for that user in that organization. Reactivation requires a new verified login; old grants and tokens remain invalid. A separate recovery connection and owner preserve administration access.
Connections enrolled in SSF or selected for full permissions request max_age=86400 and require signed auth_time within that age, with 60 seconds of clock tolerance.
This prevents a refreshed token from presenting an old authentication as a new one after revocation.
See security signals for upstream session identifiers and delayed-event handling.
Assurance for permissions
The OIDC adapter retains signed amr, acr, and auth_time in the session's verified login origin.
Malformed assurance claims fail authentication.
Old session origins without assurance default to no MFA proof.
The full permission evaluator derives mfa only from the signed mfa AMR value.
Configure the issuer to emit this value only after real MFA.
Local sign-in sets mfa after a TOTP code or a recovery code, and adds recovery_code for the latter so that policies can tell them apart.
Attribute policy freshness uses the original authentication time, not token refresh time. Service calls without a session cannot assert user MFA. Browser context cannot replace verified authentication attributes. The permissions deployment demonstrates a real password-plus-TOTP login and rejects password-only invoice approval.
Organization-managed SSO
With administration enabled, active persistent configuration overrides the designated customer's deployment connection. Draft tests use a separate state, nonce, PKCE verifier, callback, and immutable broker alias. They do not create an application session. Enforcement requires a fresh successful test and independent local recovery-owner access. Enforcement revokes older customer sessions and pending exchanges.
SCIM immutable identifiers still determine canonical provisioned-user mapping. A local suspension revokes sessions and grants, and SCIM cannot clear it. Portal credentials authorize administrative operations only and cannot call the generic user-session endpoints. See enterprise administration for the setup and recovery procedures.
Lifecycle notifications
Session creation and explicit revocation produce transactional lifecycle facts. SCIM deactivation and local suspension still block session validation and pending exchange before asynchronous delivery. An unavailable consumer cannot preserve access. Natural session expiration follows the stored expiration time. See lifecycle events for notification and consumer recovery behavior.
Linked identities and login policy
A canonical user can hold a local account and identities at several connections. People link an identity from the account pages after signing in freshly with both methods; operators can link in bulk from a reviewed mapping. The runtime never links two identities because their email addresses match.
Every grant, exchange, and session check runs the organization's login gate in PostgreSQL.
It applies the organization's local login policy (enabled, recovery_only, or disabled), its MFA requirement for local sign-in, SSO enforcement, and account or local-credential disablement.
A change takes effect for existing sessions and pending exchanges at once.
Password resets, factor recovery, and account disablement advance a credential epoch, so a proof or exchange that started earlier fails even if it finishes later.
See the provider-migration runbook.