External auth providers

A realm may declare external authentication providers (OAuth2 explicit endpoints or OIDC discovery). They are optional: when none are configured, the realm only accepts local password (+ TOTP) logins as before.

How it works

  • A provider is an external_auth_provider entity (/api/providers, providers.read / providers.write / providers.delete). New permissions providers.read, providers.write, providers.delete were added; the ipseity-admin-platform role grants them, and every realm receives an ipseity-admin-providers role.
  • The account key is the email address. During a provider login Ipseity resolves the identity document's email (the email_claim, default email) and signs into the local principal whose email matches — any provider that reports the same email signs into the same account ("multiple paths to the account that is unique by email"). Principal email is unique within a realm (enforced on write).
  • Auto-provisioning. When no principal has that email and the provider has auto_provision enabled (default), Ipseity creates a principal on first login, named deterministically from the email (ext-<sha256(email)>) with the login permission, the provider's default_groups / default_roles, and the email retained. Structured names from the identity document are captured: given_name / family_name are stored (from userinfo, falling back to the id_token claims), and display_name is the provider's name claim, or is synthesized as "given family" when no name is present. The old identity is never deleted, so an external identity cannot be "re-created" under the same email.
  • Blacklisting still applies. A principal without the login permission is banned from every authentication source, including external providers (ipseity.super does not imply login).

Supported source types

Source type Endpoints Notes
oauth2 explicit authorization_endpoint, token_endpoint, userinfo_endpoint; optional issuer and jwks_uri userinfo supplies the email; when the provider returns an id_token (e.g. Google with an openid scope) it is verified against the provider JWKS — see below
oidc discovery_url (or issuer) discovery document resolves endpoints + JWKS; id_token signatures are verified (RS256 via the provider JWKS, HS256 via client secret) against the correct iss / aud / exp

Each can be a public client (PKCE, no secret — the server generates and holds the PKCE verifier across the hop) or a private client (client_secret, encrypted at rest, sent over the server-to-server token exchange).

Verifying oauth2 id_tokens

An oauth2 provider may still return an RS256 id_token (any provider that honours an openid scope — Google does). To verify it the server needs the provider's JWKS document. jwks_uri is resolved in this order:

  1. the provider's explicit jwks_uri, then
  2. the provider's issuer — the server fetches <issuer>/.well-known/openid-configuration (cached for one hour) and uses the advertised jwks_uri (this also fills a missing issuer for the iss check).

So an oauth2 Google provider configured with explicit endpoints works as long as its Issuer is set to https://accounts.google.com (the console exposes Issuer and JWKS URI fields on the provider form). A non-discoverable provider should set jwks_uri explicitly. If neither is available and an id_token needs verifying, the callback reports that jwks_uri is required.

Flow

  1. The login page advertises your providers automatically. When a realm has at least one enabled provider, GET /oauth/authorize renders a "Sign in with …" button for each one (using the provider's display_name, falling back to its name) right below the username/password form. Clicking a button re-issues the same authorize request with external_provider=<name>, so users never have to construct the URL by hand. Disabled providers are hidden.
  2. The user starts a normal authorization request and adds external_provider=<name> to GET /oauth/authorize (or clicks the button). Ipseity validates the ipseity client / redirect URI / scope / PKCE challenge, persists the pending authorization in the realm's KV under a random state token, and redirects the browser to the provider (authorization_code + PKCE for public clients).
  3. The provider redirects back to GET /oauth/extlogin/callback with a code and the opaque state (which carries the realm so the callback can route without realms appearing in the URL path). Ipseity exchanges the code, fetches userinfo, verifies the id_token (OIDC), and resolves / provisions the principal by email.
  4. Ipseity issues an ipseity authorization code bound to the original authorize request and redirects the browser back to the client's redirect_uri — the rest of the OAuth/OIDC flow is unchanged.

The pending authorize state survives until the callback (TTL IPSEITY_EXTERNAL_LOGIN_TTL_SECONDS, default 15 minutes — deliberately longer than the auth-code TTL so the user has time to complete the IdP's own screens, including MFA and scope approval). Browser failures, including expired state, provider refusal and DNS/connection/discovery/JWKS failures, return to the original login form with a readable error. The client, scopes, application state, nonce, PKCE and validated theme are preserved, and the provider is not automatically restarted. Recovery-only KV records outlive the pending state; see browser login recovery for TTLs and fallback behavior.

A transport failure during the code exchange keeps the pending state. Low-level non-navigation callers retain the existing diagnostic page and retry URL. A provider refusal (error=access_denied and friends) consumes the pending state; state is also consumed once the provider has accepted the code, including when a later userinfo/JWKS request fails. Recovery always requires a fresh sign-in and does not bypass this single-use behavior.

Administration

  • GET/POST /api/providers, GET/PUT/DELETE /api/providers/<name> under the realm's providers.* permissions (cross-realm via X-Ipseity-Realm for ipseity.super principals).
  • Provider client_secret is encrypted at rest and redacted from API responses.
  • Disabling a provider (enabled: false) rejects new logins through it; existing accounts and tokens are unaffected.
  • A providers management page is in the console (list, create, edit, delete).