Reworks the org-scoped exchange-token endpoint into a root-gated create-session route,
addressing the review on the earlier version:
- Requires a ROOT API key holding the createIdpSession action, not an org-scoped key.
Minting a session is impersonation, so it is deliberately root-only.
- Gated behind flags.enable_idp_create_session (off by default, self-hosted only;
refused when build === "saas").
- Drops orgId entirely: the user must belong to the identity provider, not an
organization. The route becomes /idp/:idpId/oidc/create-session.
Removes the now-unused org-scoped createSessionForIdpUser helper.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add POST /v1/org/:orgId/idp/:idpId/oidc/exchange-token to the Integration
API so a trusted backend (e.g. an external IdP) can bridge an already-
authenticated external IdP session into Pangolin without the interactive
browser OIDC flow. Returns a Pangolin user session token { token, expiresAt }
in the JSON body, and registers the route in the OpenAPI spec with described
path parameters, request body, success response and error responses.
The endpoint is org-scoped and least-privilege: the caller holds an org-scoped
API key granted only the createIdpSession action, one org per deployment.
Guarded with verifyApiKeyOrgAccess + verifyApiKeyIdpAccess +
verifyApiKeyHasAction(createIdpSession) + logActionAudit, matching the other
/org/:orgId/idp/:idpId integration routes. orgId comes from the path;
verifyApiKeyIdpAccess confirms the org owns :idpId. Registration is gated
behind build !== "saas". A new createIdpSession action is added to ActionsEnum
(auto-seeded by ensureActions on self-hosted builds).
Claim-mapping/autoprovision is intentionally out of scope: the helper only
verifies the user exists, that users.idpId matches, and that a userOrgs
membership row exists for orgId, rejecting 401/404 otherwise. The caller must
pre-provision the user.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Pangolin consults the IdP only at login and keeps its own session
afterwards, so disabling a user or revoking their sessions in the IdP
does not end their Pangolin sessions.
Store the IdP refresh token at OIDC login as a grant and redeem it at
most every server.idp_session_revalidation_minutes (default 5). If the
IdP rejects it with invalid_grant, the grant is marked revoked and all
sessions backed by it and their resource sessions are deleted. Other
errors (IdP unreachable or slower than 10 seconds, invalid_client after
a secret change) keep the sessions valid and are retried after at most
a minute instead of on every request.
Only the instance holding a lease on the grant in the primary database
redeems its refresh token, and it writes the result only while it still
holds the lease, so instances never redeem the same token concurrently.
The per-request lookup reads from a replica through safeRead.
Device logins of the Pangolin clients share the grant of the browser
session that approved them, read from the primary database, so a rotated
refresh token is never redeemed twice by separate sessions.
The Entra ID provider type hardcodes its scopes, so it now requests
offline_access to get a refresh token.