Skip to content

Single sign-on

Members sign in through an identity provider the instance admin has added as an auth provider. This guide covers OpenID Connect and SAML: how to set a provider up, what a sign-in does, how a person is matched to a member, and what each error on the sign-in page means.

Setting up an OIDC provider

  1. Set FLAGNETIC_BASE_URL to the address members reach the console at, such as https://flags.example.com. Without it a provider cannot be created, edited or enabled, and the redirect URI below cannot be built.
  2. In the identity provider, register a client for a web application that uses the authorization code flow, and give it the redirect URI the instance computes: <base URL>/sso/<slug>/callback, answered as redirect_uri when the provider is created. Take note of the client ID and the client secret. The instance sends the client secret to the token endpoint and uses PKCE besides, so a client that insists on PKCE alone is fine too.
  3. As an instance admin, add the provider under Auth providers in the console (New provider; its page shows the redirect URI to copy), or with POST /instance/auth-providers: a slug of your choice, the issuer (the address under which the identity provider serves /.well-known/openid-configuration), the client_id, the client_secret, and the domains the provider vouches for.
  4. Check it with Test on the provider’s page, or POST /instance/auth-providers/{slug}/test, which fetches the discovery document and says what it found. The console also warns when the document does not list the S256 PKCE method, which sign-in needs.

The provider now appears as a button on the sign-in page, and GET /sso/<slug>/start begins a sign-in.

The issuer, and every endpoint its discovery document names, must be https, except on a loopback address. Private networks are allowed.

Domains, linking and provisioning

A provider vouches only for the email domains it names. A domain is the part of the address after the @, compared whatever its case; a subdomain is not its parent (mail.example.com is not example.com).

  • A person whose identity is already linked signs in whatever their email says: the link is the proof. A member it links who is invited (reactivated while their only way in was at a disabled provider, say) is activated, as accepting their invitation would.
  • So does a person whose subject is the externalId of a member the provider provisioned through SCIM: the directory named them itself, so the sign-in is linked to that member, at this provider only, with link_by_email and auto_provision off.
  • Otherwise the email must be in one of the provider’s domains, and verified (the provider’s email_verified claim is exactly true) unless require_verified_email is switched off. The email_verified claim speaks of the standard email claim alone: when claims.email names another claim (upn, a custom one), whose value a person may be able to set themselves, nothing is verified and the address counts only with require_verified_email switched off, so switch it off only where the directory controls that claim.
  • An invited member holding the email accepts their invitation by signing in, whether link_by_email is on or not.
  • With link_by_email on, an active member holding the email is then linked to the person and signed in. With it off, they are not found.
  • With auto_provision on, an email no member holds creates a new active member, named after the name claim or else the email, with no password.
  • Anything else is member_not_found. A member who was deactivated is member_deactivated, whichever rule would have matched them.

Accepting an invitation through a provider

An invited person never needs a password when a provider vouches for their email. Signing in through it (the email in its domains, and verified as above) makes the invited member active, links the person’s identity to them and opens their session, in one step:

  • Their invitations are used up, and the open one makes the grant in a project it carries, by hand and in the name of the member who invited, as accepting it with a password does; an inviter who can no longer hand it out grants nothing (invitation.grant_revoked).
  • An invitation that expired still activates the person, since the provider proves what the link would have, but grants nothing.
  • An email the provider does not vouch for (outside its domains, or unverified where verification is required) is member_not_found, and the invitation stays open.
  • For an email in an enforced domain, only the enforced provider accepts it; another one is sso_required.
  • The acceptance is recorded as member.invitation_accepted with its method (oidc or saml) and provider, beside identity.linked, grant.created in the project and auth.signed_in.

GET /auth/invitations/{secret} answers in providers the enabled providers that accept the invitation ({slug, display_name, kind}, ordered by display name): those whose domains hold the invited email, only the enforced one when its domain is enforced, none when no provider vouches for it.

If the ID token carries no email, the instance asks the provider’s UserInfo endpoint for it, and trusts the answer only when its sub is the token’s; its email_verified is judged on its own.

Example: Dex

staticClients:
- id: flagnetic
secret: change-me
name: Flagnetic
redirectURIs:
- https://flags.example.com/sso/dex/callback

Add a provider with slug dex, issuer https://dex.example.com, client ID flagnetic, that client secret and domains: ["example.com"].

Example: Keycloak

Create an OpenID Connect client in the realm, with Client authentication on and the standard flow enabled. Set Valid redirect URIs to https://flags.example.com/sso/keycloak/callback. The issuer is https://keycloak.example.com/realms/<realm>; the client secret is on the client’s Credentials tab. Keycloak sets email_verified from the user’s Email verified switch.

For group mappings, add a Group Membership mapper to the client’s dedicated scope, claim name groups, with Full group path off so the names match what you write in the mappings, and add groups to the provider’s scopes if the mapper is attached to a client scope of that name.

Example: Microsoft Entra ID

  1. In App registrations, register a web application and add the redirect URI https://flags.example.com/sso/entra/callback. Under Certificates & secrets, create a client secret and copy its value (not its ID).
  2. The issuer is https://login.microsoftonline.com/<tenant-id>/v2.0, the client ID is the application’s Application (client) ID.
  3. Entra ID leaves email out of the ID token of a member until you add it: under Token configuration, add the optional claim email to the ID token. It does not send email_verified for members, so an Entra provider that vouches for your own tenant’s domains is created with require_verified_email: false; the tenant’s administrators control those addresses. Never switch it off for a provider that accepts addresses anyone can claim.
  4. For group mappings, add a groups claim under Token configuration (restrict it to the groups assigned to the application). Entra ID sends group object IDs, so the group of a mapping is the object ID, such as 0b1f6c3e-.... A user in too many groups (over 200) gets no groups claim at all, which counts as no groups for anyone who claimed groups here before (see what a sign-in does), so they lose what their groups gave them. Assign only the groups you map to the application to stay under the limit, or use SCIM groups, whose names the directory sends as they are.
  5. The ID token’s sub is different for every application, so a member provisioned through SCIM is found by email: switch link_by_email on.

Example: Okta

  1. In the Okta admin console, create an OIDC - OpenID Connect app integration of type Web Application, with the sign-in redirect URI https://flags.example.com/sso/okta/callback and the assignments you want.
  2. The issuer is your Okta domain, https://<org>.okta.com, or https://<org>.okta.com/oauth2/default for a custom authorization server; the client ID and secret are on the app’s General tab. Okta sets email_verified from the user’s profile.
  3. For group mappings, add groups to the provider’s scopes (openid email profile groups), and under the app’s Sign On tab edit OpenID Connect ID Token and give the Groups claim filter a name of groups, with a filter such as Matches regex .* (or narrower, to the groups you map). On a custom authorization server define the groups claim under its Claims tab instead, included in the ID token. Okta refuses more than 100 matching groups, so filter.

Example: Google

  1. In the Google Cloud console, under APIs & Services, configure the OAuth consent screen (for a Google Workspace organization, choose Internal so only its accounts can sign in) and create an OAuth client ID of type Web application with the authorized redirect URI https://flags.example.com/sso/google/callback.
  2. The issuer is https://accounts.google.com; the client ID and secret are those of the OAuth client. Google sends email_verified and email, and the default scopes (openid email profile) are enough.
  3. Set domains to your Workspace domain only. A personal @gmail.com address is a verified address too, so a provider that lists gmail.com lets anyone with a Google account in, with link_by_email or auto_provision on.
  4. Google sends no groups, so group mappings have nothing to read at a Google provider: grant roles by hand, or sign in through a provider that sends groups.

Setting up a SAML provider

  1. Set FLAGNETIC_BASE_URL, as for an OIDC provider.
  2. As an instance admin, add the provider under Auth providers in the console (New provider, protocol SAML; its page shows the three addresses to copy and a Download SP metadata button), or with POST /instance/auth-providers: a slug, kind: saml, the domains it vouches for, and the identity provider’s metadata, either as idp_metadata_url (fetched now) or pasted as idp_metadata_xml; give one of the two. The answer carries the three addresses to register at the identity provider:
    • entity_id, the instance’s entity ID for this provider (the audience of its assertions): <base URL>/sso/<slug>/metadata;
    • metadata_url, where the instance serves its SAML metadata, which is the same address (GET /sso/<slug>/metadata, application/samlmetadata+xml), for an identity provider that imports metadata from a URL. It is served only while the provider is enabled;
    • acs_url, the assertion consumer service the identity provider posts its responses to: <base URL>/sso/<slug>/acs.
  3. Register the instance at the identity provider with those addresses, or by importing the metadata. Several identity providers insist on the entity ID and the ACS being entered by hand; they must be exactly as answered.
  4. Check it with Test on the provider’s page, or POST /instance/auth-providers/{slug}/test, which reads the identity provider’s metadata again (fetching it when it came from a URL) and answers what it found: idp_entity_id, idp_sso_url and the idp_certificates (their sha256 and not_after). Nothing is stored.

The provider appears as a button on the sign-in page, and GET /sso/<slug>/start begins a sign-in.

The identity provider’s metadata

The metadata is read when the provider is created and again whenever an edit names idp_metadata_url or idp_metadata_xml; naming one clears the other. The instance takes the entity ID, the single sign-on endpoint with the HTTP-Redirect binding and the signing certificates from it.

  • A metadata URL must be https, except on a loopback address (422 insecure_url); the document is at most 1 MiB, and one that cannot be fetched is 502 provider_unreachable with the failure.
  • Metadata that cannot be used is 422 invalid_auth_provider with a violation at the field it came from: invalid_metadata (not an EntityDescriptor of an identity provider, a DOCTYPE, a certificate that cannot be read, an http single sign-on address away from loopback), no_redirect_binding (the identity provider offers no HTTP-Redirect single sign-on service) or no_signing_certificate.
  • The idp_certificates are the certificates a response may be signed with. For metadata fetched from a URL they follow the identity provider’s own rotations through the daily refresh; metadata that was pasted is never read again, so to follow a rotation edit the provider with the new document.

Refreshing the metadata

An identity provider that publishes its metadata at a URL rotates its signing certificate now and then, and a sign-in signed by a certificate the instance has not read is refused. So every replica runs the SAML metadata refresh worker once an hour; replicas running it at once take turns under an advisory lock, so one fetches. A round reads again the metadata of each enabled SAML provider whose metadata comes from a URL and was last read (idp_metadata_refreshed_at) a day ago or more. A provider with pasted metadata, or one that is disabled, is left alone; enabling a provider that has gone stale refreshes it in the next round.

  • Nothing changed. Only idp_metadata_refreshed_at moves, so the provider is not read again for a day. Nothing is audited and the provider’s version stays.
  • New certificates or a new single sign-on address. They are applied when the metadata still lists at least one certificate the provider trusts now (matched by fingerprint), the version goes up, and auth_provider.metadata_refreshed records the certificates and address before and after (certificates as their fingerprints), attributed to the system actor SAML metadata refresh. The certificates the metadata lists replace the old ones, so an identity provider rotates by listing the old and the new certificate together for a while, then the new one alone.
  • Another entity ID. The metadata now describes a different identity provider, which is never applied silently. Nothing changes, the server logs the identity provider’s metadata names another entity than the provider’s with the provider, its entity ID and the one offered, and auth_provider.metadata_refresh_refused is audited with both (refused_reason is entity_changed). The refusal repeats every round (hourly) until an instance admin settles it: if the identity provider really moved, edit the provider with the metadata (idp_metadata_url or idp_metadata_xml), which reads it at once; if the URL is wrong, correct it.
  • No certificate the provider trusts. The entity ID is not a secret, so a document that names it proves nothing about who published it; whoever answers at the metadata URL (a lapsed domain, a compromised host, an open redirect on the provider’s host) could otherwise swap the signing certificates and sign in as any linked person. Metadata that lists none of the certificates the provider holds is therefore handled like another entity: nothing changes, the server logs the identity provider’s metadata holds none of the certificates the provider trusts, and auth_provider.metadata_refresh_refused is audited with refused_reason no_trusted_certificate, every round until an instance admin settles it. An identity provider that replaces every certificate at once needs that edit: check the new metadata, then edit the provider with idp_metadata_url or idp_metadata_xml, which the instance trusts because an admin asked for it. What the check does not do: a certificate in metadata is public, so a document that lists a trusted certificate beside one of its own passes the check, and the added certificate is trusted from then on; the check stops a document that replaces every certificate, not one that adds a certificate. It does not verify an XML signature on the metadata, and creating or editing the provider still trusts whatever the URL answers at that moment, so keep the metadata URL on a host you control, over https.
  • The fetch or the metadata fails (the identity provider is down, answers a status other than 200, or the document cannot be used). The provider keeps the metadata it has, the server logs the identity provider’s metadata could not be refreshed with the provider and the cause, and the next hourly round tries again.

flagnetic_worker_failures_total{worker="saml_metadata_refresh"} counts rounds that failed on the instance’s own storage; an identity provider’s failure is a log record, not a failed round.

The instance’s key pair

Creating a SAML provider generates a key pair for it: an RSA-2048 key and a self-signed certificate valid for three years. The private key is sealed under the instance’s secret key and never leaves the instance; the certificate is in the SP metadata. The instance signs its authentication requests with the key (sign_requests, default true: the HTTP-Redirect binding signs the query with RSA-SHA256) and decrypts encrypted assertions with it; an identity provider that encrypts assertions needs the certificate from the SP metadata. The provider answers its certificates as sp_certificates, each with its sha256, not_after and status.

Rotating the certificate

Before the certificate expires, or if its key may have leaked, replace the pair in two steps, so that sign-in never breaks while the identity provider catches up. In the console, the provider’s page lists its certificates under Certificates, with Start certificate rotation and, once started, Complete rotation; through the API:

  1. POST /instance/auth-providers/{slug}/rotate-certificate generates the next pair beside the current one. The answer has rotation_pending: true and two sp_certificates, current and next. The SP metadata now lists both certificates, each for signing and for encryption; an assertion encrypted to either is decrypted, while authentication requests are still signed with the current key. A second start is refused 409 rotation_pending.
  2. Give the identity provider the new SP metadata (re-import metadata_url, or upload the next certificate as the encryption certificate and, if it verifies requests, as the request signing certificate). Until it has, nothing changes for it.
  3. POST /instance/auth-providers/{slug}/rotate-certificate/complete makes the next pair current and destroys the retired private key: requests are signed with the new key from then on, the metadata lists only the new certificate, and an assertion still encrypted to the old one is refused. Completing with no rotation pending is 409 no_rotation_pending.

Both calls are for SAML providers (422 not_saml for an OIDC one), need no If-Match and answer the provider with its new ETag. They are audited as auth_provider.certificate_rotation_started and auth_provider.certificate_rotation_completed, naming the certificates by fingerprint and never a key. Editing the provider while a rotation is pending leaves it pending. Complete the rotation only after the identity provider encrypts to the new certificate: an assertion it still encrypts to the old one is lost the moment you complete.

Attributes, name identifiers and signing

  • claims names the assertion attributes the instance reads, as for an OIDC provider’s claims: email, name and groups by default. An attribute is matched by its Name or its FriendlyName, and its first value counts. The email is the NameID when its format is emailAddress, otherwise the attribute named by claims.email.
  • The subject the sign-in links to an identity is the NameID. With a transient NameID it changes at each sign-in, so nothing stays linked: ask for persistent, emailAddress or unspecified instead.
  • name_id_format (unspecified, the default, emailAddress, persistent or transient) is the format the request asks for.
  • A SAML provider has no verification flag to read: the instance counts an email as verified only inside the provider’s domains, which are also what decide linking by email and provisioning.
  • Fields of the other kind are refused: issuer, client_id, client_secret, scopes and require_verified_email belong to OIDC providers, idp_metadata_url, idp_metadata_xml, sign_requests and name_id_format to SAML ones (422 invalid_auth_provider, violation not_for_kind). The pasted document is never answered.

What the instance checks of a response

The identity provider posts a SAML response to the ACS (at most 1 MiB; the address takes the cross-site POST an identity provider makes, and is bound by the attempt it answers instead). It is verified with gosaml2 and refused unless:

  • the Response or the Assertion is signed by one of the provider’s certificates, and every claim is read from the element the signature covers: an assertion wrapped beside a signed one, or an unsigned one, is not read;
  • it is from the identity provider’s entity, addressed to the ACS (Destination and Recipient) and to the instance’s entity ID (Audience), and its status is success;
  • it answers the request the attempt made: InResponseTo is the request’s ID. A response nobody asked for is refused, so a sign-in cannot start at the identity provider;
  • its conditions and its subject confirmation hold, with two minutes of clock skew;
  • it holds one assertion, and that assertion was not accepted before: each is remembered until it could no longer be accepted;
  • an encrypted assertion uses RSA-OAEP key transport and AES-CBC or AES-GCM; rsa-1_5 is refused, and so is any document with a DOCTYPE. The OAEP digest is SHA-1: the library reads the SHA-2 digests only under the XML-DSig names, not the XML Encryption names identity providers send (http://www.w3.org/2001/04/xmlenc#sha256), so an identity provider that encrypts with the SHA-256 digest, as Keycloak does by default, cannot be used with encryption yet. Leave assertions unencrypted (they are signed, and the connection is TLS) or set the identity provider’s digest to SHA-1.

A response that does not pass is sso_failed, and a response that says the identity provider refused the person is idp_error. The server’s log record single sign-on failed carries the cause.

An identity provider that starts the sign-in itself (IdP-initiated sign-in) and single logout are not offered.

Example: Keycloak

Create a client of type SAML in the realm. Client ID is the entity_id; Valid redirect URIs and Master SAML Processing URL (or Assertion Consumer Service POST Binding URL) the acs_url. Turn on Sign assertions, set Name ID format to username, email or persistent, and add User Property mappers email (property email) and name, and a Group list mapper named groups. Keycloak does not need to verify the instance’s requests, so Client signature required may stay off; to have it check them, upload the certificate of the SP metadata. The identity provider’s metadata is https://keycloak.example.com/realms/<realm>/protocol/saml/descriptor.

Example: Entra ID

In Enterprise applications, create an application and choose Single sign-on, SAML. Set Identifier (Entity ID) to the entity_id and Reply URL (Assertion Consumer Service URL) to the acs_url. Under Attributes & claims, set the Unique User Identifier (NameID) to user.mail with the format Email address, so the NameID is the email. The attribute names Entra ID sends are URIs; to read the name and the groups, give them in claims:

  • name: http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name;
  • groups: http://schemas.microsoft.com/ws/2008/06/identity/claims/groups (add a groups claim first).

Entra ID signs the assertion by default. Use the App Federation Metadata Url as idp_metadata_url. To have Entra ID encrypt assertions, upload the certificate of the SP metadata as a token encryption certificate.

Example: Okta

Create a SAML 2.0 app integration. Set Single sign-on URL to the acs_url and Audience URI (SP Entity ID) to the entity_id, Name ID format to EmailAddress and Application username to Email. Add attribute statements email (user.email), name (user.displayName) and, for groups, groups with a filter. Set idp_metadata_url to the Metadata URL of the Sign On tab. Okta signs the assertion; to have it encrypt, switch on Assertion Encryption with the certificate of the SP metadata.

Group mappings

A provider’s group mappings turn the directory groups of the people who sign in through it into access: a role in a project, or instance admin. The access follows the directory: it is made when a person signs in with a group, and removed when they no longer have it.

Reading the groups. A member’s groups at a provider are those their last sign-in through it claimed together with the provider’s SCIM groups they are in. For the claim, the identity provider has to send them. For an OIDC provider that is the claim claims.groups names (default groups) in the ID token, and the provider usually needs a scope or a setting to include it: Dex and Keycloak ask for the groups scope, Okta for a groups claim on the authorization server, Entra ID for the groups claim of the app registration. For a SAML provider it is the multi-valued attribute claims.groups names. A claim counts only when it is a list of strings; a list may be empty, which says the person is in no group.

Mapping groups. In the console, the provider’s page has a Group mappings section: one row per mapping, in order, each naming a directory group and either a role in a project or instance admin, with buttons to add, move and remove rows. Save mappings replaces the whole list and says how many grants it granted and removed, and how many members stayed instance admin as the last active one. Through the API, PUT /instance/auth-providers/{slug}/group-mappings replaces the provider’s whole list, and GET reads it. The ETag of the GET is the version of the list, and the PUT names it in If-Match: without it the call is refused 428 precondition_required, and when another admin changed the list since, 412 version_mismatch, so a stale page cannot put back a mapping that was removed or revoke what was just granted. The version moves on with each replacement that changes the list, and the PUT answers the new one. The console takes the list as it is now when it changes under a page with no edits, and says so when the page has edits. An instance admin’s call, from a signed-in session (an API token is refused 403 session_required, since a mapping promotes members in a way revoking the token would not undo), with a body of items, in order:

{
"items": [
{ "group": "engineering", "project": "checkout", "role": "developer" },
{ "group": "platform-leads", "project": "checkout", "role": "owner" },
{ "group": "it-admins", "instance_admin": true }
]
}

A mapping names a group, matched exactly as the identity provider spells it, and either a project (its key) with one of the built-in roles owner, maintainer, developer and viewer, or instance_admin alone. A blank group, a mapping that is both or neither, an unknown role and a project that does not exist are refused 422 invalid_group_mappings, naming each field, and nothing changes. Several groups may map to the same role, and one group to several projects; a person holds the union of what their groups map to.

What a sign-in does. Completing a sign-in stores the groups the person claimed, then makes the grants and the instance admin their groups (the claim and their SCIM groups) map to and removes the provider’s others. A person who loses a group loses what only that group gave them, at their next sign-in. A sign-in whose claim is missing or is not a list of strings counts as an empty claim for a person the provider has claimed groups for before: some providers (Entra ID, Okta’s SAML group filters, AD FS) leave the claim out when the filtered list is empty, so a person removed from every group would otherwise keep their access for good. For a person the provider has never claimed groups for it changes nothing, and the server logs the groups claim is missing or is not a list of strings when the provider has mappings, so a provider that never sends the claim cannot strip anybody. When the provider has mappings, every such sign-in is audited as auth.groups_claim_missing (by the person, with the provider, their member_email and treated_as_empty: true when the stored claim was emptied, false when the access was left as it was). A claim that goes missing because the identity provider is misconfigured therefore strips the people who had claimed groups, at their next sign-in: fix the provider and have them sign in again.

Offboarding needs SCIM or deactivation. What groups give is refreshed only when the member signs in through that provider, and by SCIM groups. A member who signs in another way (a password, an identity at another provider, a personal access token) keeps what the groups gave them after the directory removed them from the group, or removed them altogether, until the next sign-in through the provider. Grants do not expire. To end a person’s access at once, connect the provider’s SCIM so the directory deactivates them or removes them from their groups, or deactivate the member by hand: deactivating ends their sessions and tokens.

Replacing the mappings runs them at once. The new list is run in the same transaction for every member who has signed in through the provider or is in one of its SCIM groups, from the groups they last claimed and their SCIM groups, so a mapping you remove stops granting immediately instead of at each member’s next sign-in. The answer counts what happened:

{ "granted": 12, "revoked": 3, "kept_instance_admin": 0 }

granted counts the grants made and the members made instance admin, revoked the grants removed and the members no longer instance admin, kept_instance_admin the members the run could not demote because they are the last active instance admin. A deactivated member keeps none of the provider’s grants and gains none.

Each source owns its own grants. A grant a mapping made has source sso and names the provider; a grant made by hand has source manual. They sit side by side: a mapping never skips a project because the member holds a role there by hand, a hand grant may be added beside a mapped one, and two providers may each grant the same role. A provider replaces and removes only its own.

  • A mapped grant cannot be removed by hand: DELETE /projects/{project}/grants/{grant} answers 409 sso_sourced. Change the mapping or the directory instead.
  • An instance admin a mapping made cannot be demoted by hand: PATCH /members/{member} with instance_admin false answers 409 sso_sourced. Only the provider that made them takes it away. An instance admin made by hand is never taken away by a provider, and a provider never demotes the last active instance admin: that is logged and counted in kept_instance_admin, and neither fails the sign-in nor the replacement.
  • A member who loses grant.manage in a project through a mapping loses, as through any other change, the grant of each invitation they issued to it (invitation.grant_revoked).
  • A provider whose mappings made a grant or an instance admin cannot be deleted (409 provider_in_use, used_by naming grants): disable it instead.

Replacing the mappings is audited as group_mappings.updated (the list before and after, and the counts) by the instance admin who did it. Every grant, revocation, promotion and demotion a mapping makes is audited as grant.created, grant.deleted, member.promoted or member.demoted with the provider as the actor (kind sso, named by its slug), and carries the source and the provider.

What a sign-in does

  1. The browser opens /sso/<slug>/start?return_to=<path>. The instance creates a sign-in attempt that lives ten minutes, sets the cookie __Host-flagnetic_sso (plain flagnetic_sso only where cookies cannot be Secure: on localhost, or when FLAGNETIC_INSECURE_COOKIES allows it) and sends the browser to the identity provider with a state, a nonce and a PKCE S256 challenge.
  2. The identity provider sends the browser back to /sso/<slug>/callback. The instance exchanges the code, verifies the ID token (signature, issuer, audience, expiry, nonce), and stores the verified claims on the attempt. Nothing about any member changes yet. An answer is taken once: a replayed one finds the attempt used.
  3. The browser is redirected to /sso/complete/<attempt>. The instance checks that the browser presents the attempt’s cookie, in constant time, then, in one transaction, resolves the person to a member, provisions or links as the provider allows, gives the member what their groups map to (group mappings), opens the session and redirects to return_to. A completion from any other browser changes nothing: no member, no identity, no session.

A SAML sign-in differs in its first two steps. The instance sends the browser to the identity provider’s single sign-on endpoint with an AuthnRequest, by the HTTP-Redirect binding, whose ID the attempt remembers and whose RelayState is the attempt’s state; the identity provider posts its response to /sso/<slug>/acs, where the instance verifies it as above and stores the claims on the attempt. The attempt is taken once there too, so the same response posted again finds it used. Completion is the same.

The session records the provider it opened through; GET /me/sessions answers method: oidc or saml and the provider’s slug.

return_to is honoured only when it is a path on the instance: one leading /, no backslash, no control or whitespace character, no scheme or host. Anything else, such as //evil.example or https://evil.example, is ignored and the sign-in lands on /.

Limits on starting. Opening /sso/<slug>/start writes an attempt and may sign a request or fetch the provider’s discovery document, so each replica answers one client address (an IPv6 client as its /64) at most 60 starts a minute, then 429 rate_limited with Retry-After. A discovery document that failed to load is not fetched again for 15 seconds, and simultaneous starts at one provider share one fetch.

What the instance asks of the identity provider. Every request to a provider (discovery, tokens, keys, metadata) times out after ten seconds, is read up to 1 MiB and follows at most three redirects, only on the host it asked and never to plain http away from a loopback address. A provider is named by an instance admin, so the instance reaches private networks and the endpoints a discovery document names may be on other hosts of the provider’s choosing (they must be https); a document that points the token endpoint at a host that is not the provider’s would receive the client secret. Point issuer only at a provider you control or trust. Testing a provider shows why a fetch failed by its status or its parsing error, never what the address answered.

An unknown or disabled provider answers 404 on all its addresses, and so does an address of the other kind: the ACS and the metadata of an OIDC provider, the callback of a SAML one. Disabling a provider keeps its members, identities and grants and stops its sign-ins. Adding, editing and enabling a provider, completing a certificate rotation and replacing group mappings need a signed-in session, as does changing the auth settings: an API token is refused 403 session_required. Disabling and deleting a provider take access away and stay open to a token.

A provider with identities, or whose group mappings made a grant, cannot be deleted (409 provider_in_use, used_by naming identities and grants); disable it instead. A provider an enforced domain names can be neither deleted nor disabled (used_by naming enforced domains).

A subject names a person only within one issuer or entity, so a provider with identities keeps them: changing the issuer of an OIDC provider, or the metadata of a SAML provider to that of another entity, is refused 409 provider_identities_linked while any identity is linked at it, since a subject of the new one equal to a linked one would sign in as the member who linked it. Unlink the identities first, or create a new provider beside it. Edits that leave the issuer or the entity as it is, and a refresh of the same entity’s metadata, are not affected.

Linking and unlinking identities

A member signed in with a password links a provider to their account, so they can sign in through it next time, from the console’s personal settings (Sign-in methods) or with the API below. A member’s ways in are their password and their identities, the subjects providers know them by.

  • GET /me/identities answers {password: {set, set_at}, identities}: each identity with its provider (provider, provider_name, kind, provider_enabled), the subject and when it was linked_at and last used (last_sign_in_at). An API token may read it.
  • POST /me/identities/<slug>/link (a session only) starts linking. It takes an optional return_to, honoured under the rules of a sign-in’s but falling back to /settings, answers {start_url}, the address to send the browser to, and sets the attempt cookie. The attempt is bound to the browser and to the session that started it: finishing it in another browser, in a session opened afterwards or after signing out links nothing. When the provider answers, the subject is linked to the member whatever its email, with no check against the provider’s domains, and the browser lands on return_to; only a member whose email domain is enforced to another provider is refused, landing on /settings?error=sso_required. Linking a subject that is already linked to the same member changes nothing. A disabled or unknown provider is 404, and one the instance cannot reach 502 provider_unreachable. Recorded as identity.linked. Starting needs a session that signed in in the last 15 minutes: an older one is refused 403 recent_sign_in_required and the member signs in again first, so a session someone borrowed for an afternoon cannot add a way in of their own. A way in linked in a session that was recent when it was hijacked still outlives the member’s password change: after a suspected takeover, review the member’s identities (GET /members/<member>/identities) and unlink any that are not theirs.
  • DELETE /me/identities/<identity> (a session only) unlinks an identity of the caller. An instance admin unlinks a member’s with DELETE /members/<member>/identities/<identity> and lists them with GET /members/<member>/identities, for example to undo a wrong link. Recorded as identity.unlinked.
  • What goes with the last identity at a provider. When no identity of the member remains at that provider, what it brought them is taken back in the same transaction: the groups they claimed there are forgotten, the grants and instance admin its group mappings gave for those groups are removed (what its SCIM groups give stays, and the last active instance admin stays), and the sessions opened through the provider end. identity.unlinked records it in after as group_claim_removed, access_revoked, kept_instance_admin and sessions_revoked. Unlinking one of several identities at the same provider takes back nothing.
  • The last way in stays. Unlinking an identity, or removing the password with DELETE /me/password (a session only, recorded as password.removed; Access covers it), is refused 409 last_auth_method when no other usable way in would remain. A usable way in is a password local login accepts for the member’s email, or an identity at an enabled provider that enforcement does not refuse them: an identity at a disabled provider is listed but signs nobody in, so unlinking it is always allowed. A password local login or enforcement refuses is not removed while no usable way in would remain, since flagnetic admin unlock makes it a way in again. A deactivated member signs in nowhere, so an instance admin may unlink their last identity. The identity of a provisioned member (one created through the provider’s SCIM token) at that provider is the directory’s: unlinking it is refused 409 member_provisioned. The identity at the provider the member’s email domain is enforced to is their only way in: unlinking it is refused 409 provider_enforced until the enforcement is lifted.

Where a link fails after the instance has identified its attempt, the browser lands on /settings?error=<code> (a state or completion token it cannot identify, or a provider disabled meanwhile, ends as a sign-in’s failure does): identity_linked when the subject is linked to another member, sso_required when the member’s email domain is enforced to another provider, attempt_mismatch for a browser or session that did not start the link, sso_failed or idp_error as at sign-in.

SSO enforcement and local login

An instance admin sends the members of an email domain to one auth provider, and may switch passwords off for everybody, in the auth settings. In the console that is Auth settings: the Local login switch, whose help text names flagnetic admin unlock, and the Enforced domains editor, which offers each domain the enabled providers vouch for and, for a chosen domain, the providers that vouch for it.

Setting Default Meaning
sso_enforced_domains none A list of {domain, provider}: an email in domain signs in through the provider whose slug is provider, and through nothing else.
local_login_enabled true Whether a password signs anybody in.
  • What enforcement refuses. For an email in an enforced domain, a password is no way in: signing in with one, accepting an invitation by setting one and completing a password reset are refused 403 sso_required, with the enforced provider’s slug in provider, and asking for a password reset by mail sends nothing (the answer is still 202, so it tells nobody which emails exist). Signing in through another provider, or linking an identity at another provider, lands on /sign-in?error=sso_required&provider=<slug> (on /settings for a link). The domain is the email’s whole domain after the @, compared without case: enforcing example.com does not enforce sub.example.com.
  • Local login off. With local_login_enabled false, every password is refused 403 local_login_disabled, at sign-in, invitation acceptance and reset completion, and no reset is mailed. An email in an enforced domain is still answered sso_required, which names where to go instead.
  • What a change must hold. Each domain is named once, must be one of its provider’s domains, and its provider must exist and be enabled; otherwise the change is refused 422 invalid_auth_settings, naming the domain or provider at fault. An instance admin who switches local login off, or changes the enforced domains while it is off, must hold an identity that signs them in under the new settings, at an enabled provider and, when their own email domain is enforced, at the provider it is enforced to, so they do not lock themselves out: otherwise 422 identity_required. A change to anything else is not judged by their ways in.
  • What it holds afterwards. While a domain is enforced to it, a provider can be neither disabled nor deleted, nor edited to drop that domain (409 provider_in_use, used_by naming enforced domains). While local login is off, the only enabled provider can be neither disabled nor deleted (used_by naming only way in). Neither a password nor an identity at another provider counts as a way in for a member whose email is enforced, so the last way in a member keeps is their identity at the enforced provider.
  • The sign-in page. GET /auth/methods?email=<email> answers local_login_enabled and, when the email’s domain is enforced, enforced_provider ({slug, display_name, kind}), the one way in to offer that email. password_reset_available is false while local login is off and for an enforced email. The console’s sign-in page uses it: while the instance has enabled providers and local login is on, it asks for the email alone, sends an email in an enforced domain to its provider and asks any other for its password. An invitation (GET /auth/invitations/<secret>) answers password_allowed: false whenever accepting it with a password would be refused, and, for an enforced email, its enforced_provider.
  • Sessions a change ends. Switching local login off, or changing the enforced domains, ends in the same transaction every session the new settings would not let sign in: a password session of an email that can no longer use a password, and a session through another provider of an email enforced to one. The caller’s own session is among them when it is one of these, so an instance admin who closes local login signs in again through their provider. Personal access tokens are no sign-in, so they keep working; revoke them separately. Disabling a provider ends every session it opened, whoever holds it.
  • Audit. Each change is part of the settings recorded as auth_settings.updated, before and after, with sessions_revoked in the after when it ended any.

If the enforced provider breaks, or local login is off and no provider works, an operator restores password sign-in from the command line with flagnetic admin unlock.

Sign-in errors

Every failure redirects to /sign-in?error=<code>:

Code Meaning What to do
sso_failed The sign-in could not be verified: the state was unknown, used or expired, the token’s signature, issuer, audience, expiry or nonce was wrong, the code exchange was refused (check the client secret), a SAML response failed one of the checks above (not signed by the provider’s certificate, another audience or destination, not an answer to the request, expired, replayed, wrapped), the provider could not be reached, or the attempt was gone when it was completed. Try again. If it repeats, POST …/test the provider and read the server’s log: a record single sign-on failed carries the cause.
idp_error The identity provider refused the sign-in itself, for example the person denied access. Ask the identity provider’s administrator.
member_not_found No member matches the person: their email is outside the provider’s domains or (OIDC) unverified, linking by email is off, or provisioning is off. Add the domain, switch link_by_email or auto_provision on, or invite the person.
member_deactivated The member was deactivated. The failure is audited as auth.sign_in_failed. An instance admin may reactivate them.
sso_required The person’s email domain is enforced to another auth provider, whose slug is in provider. Sign in through that provider.
attempt_mismatch The browser completing the sign-in is not the one that started it. Start again in the same browser.
identity_linked Only when linking, on the settings page: the provider’s subject is already linked to another member. An instance admin unlinks it from that member, or the person links a different account at the provider.

Audit and metrics

A first sign-in records member.provisioned or identity.linked (or both), and member.invitation_accepted for an invited member, unlinking an identity identity.unlinked, the access the member’s groups gave or took away as group mappings record it, and every sign-in auth.signed_in with its method (oidc or saml) and provider; a refused sign-in of a known member (one the subject is linked to, or one holding an email the provider vouches for) records auth.sign_in_failed with the reason: the member’s status when it refuses them (deactivated, invited), or not_linked for an active member when the provider does not link by email.

flagnetic_sso_sign_ins_total{kind,result} counts sign-ins that ended, by kind (oidc or saml, unknown when the sign-in failed before its provider was known) and result: succeeded, linked for a link that completed, or the code above.