OAuth and federated identity
iam.svc signs people in through external identity providers: Microsoft Entra ID (Microsoft
365), Google Workspace, Slack, Okta, Keycloak, or any OAuth 2.0 or OpenID Connect provider. A
product declares the providers it offers in its iam/ files. Each tenant configures them
with a providerconfigs row: endpoints, client, and the rules for linking and provisioning
people. A sign-in uses the authorization-code flow with PKCE (S256), verifies the provider’s ID
token when the provider speaks OpenID Connect, lands in the realm that offers the provider, and
returns the same login response every other sign-in method returns.
Declare the provider
Section titled “Declare the provider”A provider is declared in the product’s iam/providers.yaml with type: oauth, and offered by
listing it in a realm’s providers: (see Realms and providers):
providers: - { name: password, type: challenge } - { name: o365, type: oauth, idp: microsoft, organisations: [6a1d9c2e-0b8f-4c1a-9d3e-2f7a5b6c8d90] } - { name: google, type: oauth, idp: google, organisations: [acme.com] }
# iam/realms.yamlrealms: users: { default: true, providers: [password, o365, google] }| Key | Meaning |
|---|---|
name | The :provider segment of the routes, lowercase |
type | oauth for a federated provider |
idp | microsoft, google or slack: where the provider’s ID token keeps the person’s subject, organisation and attributes. Omitted for any other OpenID Connect or OAuth provider |
organisations | The organisations the workspace trusts, see Trusted organisations. Needs idp |
A tenant overlay can declare or restate providers the same way, so one tenant can trust a directory another does not.
Configure it for a tenant
Section titled “Configure it for a tenant”Each declared provider gets one providerconfigs row in the tenant, written by the tenant’s
admin through /rest/providerconfigs:
{ "provider": "o365", "issuer": "https://login.microsoftonline.com/6a1d9c2e-0b8f-4c1a-9d3e-2f7a5b6c8d90/v2.0", "auth_url": "https://login.microsoftonline.com/6a1d9c2e-0b8f-4c1a-9d3e-2f7a5b6c8d90/oauth2/v2.0/authorize", "token_url": "https://login.microsoftonline.com/6a1d9c2e-0b8f-4c1a-9d3e-2f7a5b6c8d90/oauth2/v2.0/token", "userinfo_url": "https://graph.microsoft.com/v1.0/me", "client_id": "4f1c…", "client_secret_ref": "iam/oauth/o365/client-secret", "redirect_url": "https://app.example.com/auth/o365/callback", "scopes": ["openid", "profile", "email", "User.Read"], "email_claim": "mail", "name_claim": "displayName", "subject_claim": "id", "active": true}| Field | Required | Meaning |
|---|---|---|
provider | yes | The declared provider name. Fixed once written |
client_id | yes | The client the provider issued |
client_secret_ref | no | A vault reference to the client secret, never the secret itself. Empty for a public client (PKCE protects the exchange). Masked on every read |
auth_url, token_url, userinfo_url | yes | The provider’s authorization, token and userinfo endpoints |
redirect_url | yes | The absolute callback URL registered with the provider, used exactly as written |
scopes | yes | The scopes requested. Requesting openid makes the provider OpenID Connect |
issuer | with openid | The issuer the provider’s ID tokens must carry. For Microsoft, one directory’s https://login.microsoftonline.com/<tenant-id>/v2.0 |
jwks_url | no | Where the issuer publishes its signing keys. Empty reads the issuer’s discovery document |
email_claim, name_claim | yes | The userinfo claims carrying the address and the display name |
subject_claim | no | The userinfo claim carrying the provider’s stable id for the person, usually sub (id for Microsoft Graph’s /me). See Who a sign-in signs in as |
link | no | email-verified (default) or subject |
provision | no | true (default) or false |
active | no | false switches the provider off for the tenant |
Every field in the required column has no default, and a write that leaves one out is refused
with 422. issuer and jwks_url are https URLs (plain http is accepted on a loopback host
for local testing). The row records last_used_at each time a sign-in completes a round trip
with the provider.
Sign in
Section titled “Sign in”| Method | Path | Purpose | Rate-limit profile |
|---|---|---|---|
GET | /auth/oauth/:provider/start[?realm=<name>] | Start a sign-in: 302 to the provider | auth_login |
GET | /auth/oauth/:provider/callback?code=…&state=… | Complete it: the login response | auth_login |
POST | /auth/discover | Which method and provider an address signs in with | auth_login |
Both sign-in routes are public and need the four CEPT headers (X-Customer, X-Product,
X-Env, X-Tenant). :provider is lowercased.
All three are rate-limited on the auth_login profile, as password login is: a token bucket per
(tenant, caller IP), capacity 30, refill 0.5 per second. A request over the limit answers 429 with
Retry-After and the limiter’s body,
{"error": "rate_limited", "profile": "auth_login", "retry_after_seconds": N}. See rate
limits.
Start resolves the provider and the realm the sign-in lands in, emits before_oauth_start
(a hook may refuse with 403 hook_denied), and writes a single-use state that lives for ten
minutes. The state holds the PKCE verifier, the realm, and for an OpenID Connect provider the
nonce the ID token must carry. The redirect carries state, code_challenge,
code_challenge_method=S256, the nonce and access_type=online.
Callback consumes the state (it is deleted before any call to the provider), checks it has not expired, checks the realm still offers the provider, redeems the code with the PKCE verifier, verifies the ID token, fetches userinfo, finds or creates the person, applies the MFA gate, and mints. On success it returns the login response:
{ "token": "v4.public.…", "refresh_token": "01K….<secret>", "expires_in": 900,}email and displayname in this response are the provider’s values for this sign-in. A tenant
with tokens as cookies (token.cookie: true) also receives them as HttpOnly cookies. On a tenant
whose session preset is managed, the response is the
managed-session shape, and the session records auth_method: idp:<provider> with the ID token’s
issuer and session id.
Discovery
Section titled “Discovery”POST /auth/discover with {"identity": "[email protected]", "realm": "users"} (realm optional)
answers from the address’s domain:
{ "method": "oauth", "provider": "o365", "start_url": "/auth/oauth/o365/start", "realm": "users" }or {"method": "password", "realm": "users"} for a domain no provider serves. The answer depends
on the domain alone, never on whether the address belongs to anyone. Domains are mapped to
providers in the tenant’s provider_domains rows (domain, provider, active), one provider
per domain.
OpenID Connect
Section titled “OpenID Connect”A provider whose scopes request openid returns an ID token, and the callback verifies it before
userinfo is asked anything:
- the signature, against
jwks_urlor the keys in the issuer’s discovery document; issequals the row’sissuer;audnames the row’sclient_id;- the token is current (
exp,iat); nonceequals the one/startsent.
A userinfo response that names a subject must name the ID token’s. A provider that does not
request openid is plain OAuth, and its userinfo response identifies the person.
Trusted organisations
Section titled “Trusted organisations”The verified ID token names the person, and the organisation they belong to, in each provider’s own claims:
idp | Subject | Organisation | Attributes kept |
|---|---|---|---|
microsoft | oid | tid (directory id) | preferred_username, email |
google | sub | hd (Workspace domain) | email, email_verified |
slack | https://slack.com/user_id | https://slack.com/team_id, and https://slack.com/enterprise_id on Enterprise Grid | email |
| (other) | sub | none | email, email_verified |
With organisations listed, a sign-in from any other organisation is refused with 403 organisation_not_trusted, and so is a Google account without a Workspace domain. Without a list,
the provider’s issuer is the boundary.
One Microsoft app across several directories. Set the row’s issuer to
https://login.microsoftonline.com/{tenantid}/v2.0 and list the directories under
organisations. Each sign-in is verified against its own directory’s issuer, and a directory not
on the list is refused before anything is fetched for it. Microsoft includes oid when the
profile scope is requested.
GET /auth/sso/apps lists each configured provider’s public identifiers (provider, idp,
client_id, issuer, organisations) for the workspace’s admins and for services whose token
reaches the workspace. An integration uses it to find the app people sign in with.
Who a sign-in signs in as
Section titled “Who a sign-in signs in as”The callback finds the person in the realm’s entity in this order:
- By subject. With
subject_claimset, a subject linked earlier signs in to the person it is linked to, whatever address the provider sends now. A credential switched off for that person refuses the sign-in. - By address, once. A subject nobody is linked to yet may join a person who already holds
the address. The provider must vouch for the address (below), and the provider’s
linkmust beemail-verified. The subject is then linked, so step 1 answers every later sign-in. - New. Nobody holds the address: the person is created in the realm’s entity with the
realm’s default roles, and the subject is linked. The provider’s
provisionmust betrue.
A provider vouches for an address when:
- the verified ID token or the userinfo response carries it as
emailwithemail_verified: true; - for
idp: microsoft, the ID token carries it asemailwithxms_edov: true. Addxms_edovto the ID token in the app registration’s token configuration; - for
idp: microsoftwith anissuerthat names one directory, the address’s domain is mapped to the provider inprovider_domains. With a{tenantid}issuer,xms_edovis the signal.
| Setting | Effect |
|---|---|
link: email-verified | The default. An existing person is joined on an address the provider vouches for |
link: subject | An existing person is joined only through a subject already linked to them. Needs subject_claim |
provision: true | The default. Someone new is created at their first sign-in |
provision: false | Only people the tenant already has sign in, for an invite-only tenant |
Without subject_claim, the provider finds the person by address on every sign-in, and the
address must be vouched for each time. Set subject_claim so that each person’s first sign-in
links them.
A person created at a first sign-in gets the fields the realm’s entity declares among email,
firstname, lastname (from the display name), middlename, avatar, active: true, and a
random password nobody knows. They sign in through the provider, or set a password through
password reset. The display name is split into first and last name, and a part shorter than three
characters is replaced with OAuth or User.
Realms
Section titled “Realms”A sign-in lands in a realm that lists its provider:
?realm=<name>on/startnames it. The realm must exist (400 unknown_realm) and list the provider (403 provider_not_allowed).- With no realm named, the default realm if it lists the provider, otherwise the one realm that
does. Several such realms answer
400 realm_required. - The token carries that realm, and the person is found or created in the realm’s entity, which
needs an
emailfield.
To give two populations different directories, declare two providers and list each on its own realm:
providers: - { name: o365_staff, type: oauth } - { name: o365_patient, type: oauth }
# iam/realms.yamlrealms: users: { default: true, providers: [password, o365_staff] } patient: { entity: patient, active: true, providers: [o365_patient] }A person with TOTP enrolled receives the MFA-required response instead of tokens, and completes
the sign-in at POST /auth/mfa/verify:
{ "mfa_required": true, "mfa_token": "v4.public.…", "methods": ["totp"] }The decision follows the person’s enrolment in iam.svc. See multi-factor
authentication.
Errors
Section titled “Errors”Every error is the auth envelope, {"error": "<message>", "code": "<slug>"}, except a
rate-limit denial, which is 429 with the limiter’s body described under Sign in.
| Code | HTTP | Route | Cause |
|---|---|---|---|
no_tenant | 400 | both | CEPT headers missing |
engine_unavailable | 500 | both | The tenant’s datastore could not be resolved |
unknown_provider | 404 | both | No active configuration for that provider name in the tenant |
provider_misconfigured | 500 | both | A row exists but cannot be used, for example a required field is empty or the secret reference does not resolve |
unknown_realm | 400 | both | The named realm does not exist |
realm_required | 400 | both | Several realms list the provider and none was named |
provider_not_allowed | 403 | both | The realm does not list the provider |
hook_denied | 403 | start | A before_oauth_start hook refused |
state_failed, persist_failed | 500 | start | The state could not be generated or stored |
provider_error | 401 | callback | The provider redirected back with an error |
missing_callback | 400 | callback | code or state missing |
invalid_state | 401 | callback | The state is unknown, for another provider, used, or expired |
exchange_failed | 401 | callback | The provider refused the code |
id_token_missing | 401 | callback | An OpenID Connect provider returned no ID token |
id_token_invalid | 401 | callback | The ID token failed verification |
organisation_not_trusted | 403 | callback | The sign-in’s organisation is not one the workspace trusts |
userinfo_failed | 500 | callback | Userinfo could not be fetched |
subject_mismatch | 401 | callback | Userinfo names a different subject than the ID token |
no_email | 500 | callback | The email claim is empty |
provider_domain_mismatch | 403 | callback | The address is outside the domains mapped to the provider |
account_exists_unverified | 409 | callback | Someone holds the address, and the provider has not verified it |
account_exists_not_linked | 409 | callback | Someone holds the address, and the provider links by subject only |
not_provisioned | 403 | callback | Nobody holds the address, and the provider creates nobody |
user_provision_failed | 500 | callback | The person could not be found or created |
mfa_lookup_failed | 500 | callback | MFA enrolment could not be read |
invalid_token | 401 | callback | The person is not in the realm the sign-in landed in |
sign_failed, issue_failed | 500 | callback | The tokens could not be issued |
The refusals from unknown_provider through not_provisioned leave no person created and no
subject linked. A write to /rest/providerconfigs with a missing required field, an issuer that is not https,
an unknown link, or link: subject without subject_claim is refused with 422. The full
catalogue is on the error page.
Events
Section titled “Events”| Event | Kind | Payload |
|---|---|---|
before_oauth_start | Can refuse: 403 hook_denied | provider, realm, redirect_url, client_ip |
before_signup / after_signup | Observers, for a person created at this sign-in | email, realm, source: oauth:<provider>; after_signup adds user_id |
after_oauth_callback | Observer, after a stateless mint | provider, realm, user_id, email, is_new_user, and identity (the person at the provider: idp, subject, organisation, attributes) for an OpenID Connect provider |
after_login_success | Observer | user_id, mfa_required: false, flow: oauth:<provider> |
before_signup is an observer on this flow: its result is not consulted. A sign-in that returns
the MFA-required response or a managed session returns before after_oauth_callback; count
federated sign-ins with after_login_success.
Continue with
Section titled “Continue with”- Realms and providers: which realm a sign-in lands in
- Multi-factor authentication: the gate on the callback
- Sessions: the managed response
- Identity entities:
providerconfigs,provider_domainsandcredentials - IAM API reference: request and response shapes