graphlife Docs graphlife.app

Accounts and access

9. Single sign-on (OIDC)

SSO is off by default. It is turned on by setting the OIDC_PROVIDERS environment variable. While it is off, every route in this section answers 404 with code sso_disabled, and GET /health reports "sso": [].

The protocol is OpenID Connect, authorization-code flow with PKCE. SAML is not supported, and there is no SCIM or other directory-provisioning interface.

9.1 Configuration#

OIDC_PROVIDERS is a JSON array. Each entry:

Field Required Meaning
id yes Short identifier, matching ^[a-z0-9][a-z0-9_-]{0,31}$. Unique within the array.
label yes Name shown to people ("Sign in with …").
issuer yes The provider's issuer URL, exactly as it appears in the iss claim. Must be https (or http on localhost / 127.0.0.1). A multi-tenant issuer may contain the literal {tenantid}.
client_id yes The client id registered at the provider.
client_secret yes The client secret registered at the provider.
tenants for multi-tenant issuers The tenant ids that are admitted. Required when issuer contains {tenantid}.
[
  {
    "id": "corp",
    "label": "Corporate SSO",
    "issuer": "https://idp.example.com/realms/main",
    "client_id": "graphlife",
    "client_secret": "…"
  }
]

If the value cannot be parsed, or any entry is incomplete, the server logs one line and starts with SSO off entirely.

Register this redirect URI at the provider:

https://graphlife.example.com/v1/sso/callback

The server builds it from PUBLIC_URL when that variable is set, and otherwise from the Host header of the request. Setting PUBLIC_URL is recommended whenever SSO is used, so that the URI is fixed.

What the server requires of the provider:

  • A discovery document at <issuer>/.well-known/openid-configuration whose issuer equals the configured one, with https authorization and token endpoints. The server needs outbound HTTPS access to the provider. The document is fetched on first use and then cached until the server restarts.
  • For a multi-tenant issuer, the discovery document is fetched with {tenantid} replaced by organizations, the ID token must carry a tid claim that is listed in tenants, and its iss must equal the configured issuer with {tenantid} replaced by that tid. This matches the Microsoft Entra ID conventions; other multi-tenant schemes are not supported.
  • The token endpoint must accept the client secret in the form body (client_secret_post).
  • The scopes requested are openid email profile.
  • The ID token must carry a verified email: email_verified: true, or, for a multi-tenant issuer, xms_edov: true. A sign-in without one is refused with email_unverified.
  • The ID token is received directly from the provider's token endpoint over TLS (authorization code flow), and the server validates its issuer, audience, expiry, nonce and, for multi-tenant issuers, tenant.

9.2 Which account an SSO sign-in reaches#

Situation Result
The identity (provider + subject) is already linked to an account Signs in to that account.
No link, but an account with the same email address already exists Refused: link_required. The person signs in with their password and links the provider (section 9.5). Accounts are never joined automatically by email.
No link and no account, and the address has an open organisation invite that admits new accounts A new, SSO-only account is created and joins every organisation that invited the address. An invite admits a new account when it was issued by the instance owner, or when SIGNUP=open.
None of the above Refused: no_invite.

An SSO-only account has no password: POST /v1/accounts/login answers 401 for it and POST /v1/accounts/password answers 409 sso_account.

Removing a person at the identity provider does not delete or disable their GraphLife account. Their sessions stop being refreshable SSO_SESSION_HOURS (default 24) after their last sign-in, and they cannot sign in again; an access token already issued stays valid until it expires (up to one hour). Their organisation membership, any API keys they minted and any OAuth connections they approved remain, and keep working, until an org admin removes the member (section 10.4).

9.3 Device flow (for apps and scripts)#

The flow for a client that cannot receive a browser redirect. The client obtains a URL for the person to open in a browser, then polls.

POST/v1/sso/device#

Public, rate limited.

Body field Required Meaning
provider yes A provider id from GET /health.
curl -X POST https://graphlife.example.com/v1/sso/device \
  -H 'Content-Type: application/json' -d '{"provider":"corp"}'
{
  "flow": "…",
  "pollSecret": "…",
  "userCode": "BCDF-GHJK",
  "verifyUrl": "https://graphlife.example.com/v1/sso/start?flow=…",
  "expiresIn": 600
}

Show userCode to the person and have them open verifyUrl. Keep pollSecret private; it is what collects the tokens. 404 unknown_provider if the provider id is not configured.

POST/v1/sso/device/poll#

Public (the poll secret is the credential).

Body field Required Meaning
pollSecret yes From the previous call.
deviceId no A label for the session, as device_id at login.
Status Body Meaning
200 {user_id, access_token, refresh_token, expires_in} Signed in. The tokens are returned exactly once.
428 pending The person has not finished yet. Poll again.
403 one of the codes in section 9.6 The sign-in was refused.
410 expired The flow has expired or its tokens were already collected.
404 not_found Unknown poll secret.
400 invalid pollSecret missing.

No polling interval is prescribed by the server. A few seconds between polls is reasonable.

9.4 Browser routes#

These routes are visited by a person's browser and return HTML. They are listed for completeness and for firewall and proxy configuration.

Route Purpose
GET/v1/sso/start?flow=… Confirmation page for a device or link flow. Sets a short-lived, HttpOnly, SameSite=Strict cookie named gl_sso.
POST/v1/sso/start The page's "Continue" button. Redirects the browser to the identity provider. Works only from the page above, in the same browser.
GET/v1/sso/start?provider=…&purpose=oauth&… The "Sign in with …" link on the OAuth consent page. Carries the authorization request and redirects to the provider.
GET/v1/sso/callback Where the provider returns the browser. Completes the device flow, the link, or the OAuth sign-in.

Their HTML error pages use 410 for an expired or already-used flow, 403 for a refused sign-in or for a "Continue" that did not come from the confirmation page in the same browser, 404 for an unknown provider on the OAuth sign-in link, 409 when the identity is already linked to another account, 413 for an oversized form, 502 when the provider cannot be reached, and 429 when rate limited.

9.5 Linked identities#

GET/v1/accounts/identities#

Lists the identity-provider sign-ins linked to the caller's account. Session.

{
  "identities": [
    { "provider": "oidc:corp", "subject": "00u1abcd", "email": "[email protected]", "verified": true }
  ]
}

POST/v1/accounts/identities#

Starts linking a provider to the caller's existing account. Session, with re-authentication.

Body field Required Meaning
provider yes A provider id.
password for password accounts Re-authentication.

Response: 200 OK

{ "url": "https://graphlife.example.com/v1/sso/start?flow=…", "expiresIn": 600 }

The person opens url in a browser and signs in at the provider; the identity is then linked.

Status code When
401 unauthorized No valid session.
403 reauth_required Re-authentication failed.
404 unknown_provider

DELETE/v1/accounts/identities#

Removes a link. Session, with re-authentication.

Body field Required Meaning
provider yes As returned by the listing, for example oidc:corp.
subject yes As returned by the listing.
password for password accounts Re-authentication.

Response: 204 No Content.

Status code When
400 invalid provider or subject missing.
401 unauthorized No valid session.
403 reauth_required Re-authentication failed.
404 not_found No such linked identity.
409 last_identity The account is SSO-only and this is its only identity.

9.6 SSO refusal codes#

Returned by POST /v1/sso/device/poll with status 403. The same codes are written to the server's audit log, but a refused sign-in is recorded without an account, so no API route returns it (section 11.1).

Code Meaning
no_invite No account and no invite that admits one (section 9.2).
link_required An account with this email exists and is not linked to this identity.
identity_in_use The identity is linked to a different account. Occurs only when linking (section 9.5), where it is shown on the browser page; the device poll never returns it.
account_inactive The linked account is scheduled for deletion.
email_unverified The provider did not assert a verified email.
tenant_not_allowed Multi-tenant provider: the tenant is not in tenants.
provider_denied The provider returned no authorization code (the person cancelled, or the provider refused).
provider_unreachable The provider's discovery or token endpoint could not be reached.
provider_misconfigured The discovery document does not match the configuration.
exchange_failed The provider's token endpoint refused the code or returned no ID token.
bad_token, bad_iss, bad_aud, bad_nonce, expired The ID token failed validation. Note that expired with status 403 means an expired ID token, while expired with status 410 means the flow itself has expired or was already collected.
unknown_provider The provider was removed from the configuration during the flow.