Skip to content
Talk to our solutions team

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.

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):

iam/providers.yaml
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.yaml
realms:
users: { default: true, providers: [password, o365, google] }
KeyMeaning
nameThe :provider segment of the routes, lowercase
typeoauth for a federated provider
idpmicrosoft, 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
organisationsThe 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.

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
}
FieldRequiredMeaning
provideryesThe declared provider name. Fixed once written
client_idyesThe client the provider issued
client_secret_refnoA 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_urlyesThe provider’s authorization, token and userinfo endpoints
redirect_urlyesThe absolute callback URL registered with the provider, used exactly as written
scopesyesThe scopes requested. Requesting openid makes the provider OpenID Connect
issuerwith openidThe issuer the provider’s ID tokens must carry. For Microsoft, one directory’s https://login.microsoftonline.com/<tenant-id>/v2.0
jwks_urlnoWhere the issuer publishes its signing keys. Empty reads the issuer’s discovery document
email_claim, name_claimyesThe userinfo claims carrying the address and the display name
subject_claimnoThe 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
linknoemail-verified (default) or subject
provisionnotrue (default) or false
activenofalse 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.

MethodPathPurposeRate-limit profile
GET/auth/oauth/:provider/start[?realm=<name>]Start a sign-in: 302 to the providerauth_login
GET/auth/oauth/:provider/callback?code=…&state=…Complete it: the login responseauth_login
POST/auth/discoverWhich method and provider an address signs in withauth_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,
"user": { "id": "01K…", "email": "[email protected]", "displayname": "Maya Rao" }
}

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.

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.

A provider whose scopes request openid returns an ID token, and the callback verifies it before userinfo is asked anything:

  • the signature, against jwks_url or the keys in the issuer’s discovery document;
  • iss equals the row’s issuer;
  • aud names the row’s client_id;
  • the token is current (exp, iat);
  • nonce equals the one /start sent.

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.

The verified ID token names the person, and the organisation they belong to, in each provider’s own claims:

idpSubjectOrganisationAttributes kept
microsoftoidtid (directory id)preferred_username, email
googlesubhd (Workspace domain)email, email_verified
slackhttps://slack.com/user_idhttps://slack.com/team_id, and https://slack.com/enterprise_id on Enterprise Gridemail
(other)subnoneemail, 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.

The callback finds the person in the realm’s entity in this order:

  1. By subject. With subject_claim set, 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.
  2. 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 link must be email-verified. The subject is then linked, so step 1 answers every later sign-in.
  3. 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 provision must be true.

A provider vouches for an address when:

  • the verified ID token or the userinfo response carries it as email with email_verified: true;
  • for idp: microsoft, the ID token carries it as email with xms_edov: true. Add xms_edov to the ID token in the app registration’s token configuration;
  • for idp: microsoft with an issuer that names one directory, the address’s domain is mapped to the provider in provider_domains. With a {tenantid} issuer, xms_edov is the signal.
SettingEffect
link: email-verifiedThe default. An existing person is joined on an address the provider vouches for
link: subjectAn existing person is joined only through a subject already linked to them. Needs subject_claim
provision: trueThe default. Someone new is created at their first sign-in
provision: falseOnly 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.

A sign-in lands in a realm that lists its provider:

  • ?realm=<name> on /start names 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 email field.

To give two populations different directories, declare two providers and list each on its own realm:

iam/providers.yaml
providers:
- { name: o365_staff, type: oauth }
- { name: o365_patient, type: oauth }
# iam/realms.yaml
realms:
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.

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.

CodeHTTPRouteCause
no_tenant400bothCEPT headers missing
engine_unavailable500bothThe tenant’s datastore could not be resolved
unknown_provider404bothNo active configuration for that provider name in the tenant
provider_misconfigured500bothA row exists but cannot be used, for example a required field is empty or the secret reference does not resolve
unknown_realm400bothThe named realm does not exist
realm_required400bothSeveral realms list the provider and none was named
provider_not_allowed403bothThe realm does not list the provider
hook_denied403startA before_oauth_start hook refused
state_failed, persist_failed500startThe state could not be generated or stored
provider_error401callbackThe provider redirected back with an error
missing_callback400callbackcode or state missing
invalid_state401callbackThe state is unknown, for another provider, used, or expired
exchange_failed401callbackThe provider refused the code
id_token_missing401callbackAn OpenID Connect provider returned no ID token
id_token_invalid401callbackThe ID token failed verification
organisation_not_trusted403callbackThe sign-in’s organisation is not one the workspace trusts
userinfo_failed500callbackUserinfo could not be fetched
subject_mismatch401callbackUserinfo names a different subject than the ID token
no_email500callbackThe email claim is empty
provider_domain_mismatch403callbackThe address is outside the domains mapped to the provider
account_exists_unverified409callbackSomeone holds the address, and the provider has not verified it
account_exists_not_linked409callbackSomeone holds the address, and the provider links by subject only
not_provisioned403callbackNobody holds the address, and the provider creates nobody
user_provision_failed500callbackThe person could not be found or created
mfa_lookup_failed500callbackMFA enrolment could not be read
invalid_token401callbackThe person is not in the realm the sign-in landed in
sign_failed, issue_failed500callbackThe 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.

EventKindPayload
before_oauth_startCan refuse: 403 hook_deniedprovider, realm, redirect_url, client_ip
before_signup / after_signupObservers, for a person created at this sign-inemail, realm, source: oauth:<provider>; after_signup adds user_id
after_oauth_callbackObserver, after a stateless mintprovider, 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_successObserveruser_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.