feat(identity): /api/auth/idp/* — signed-state OIDC surface for the Zitadel-first flow (#131, task 2.1, IDA-01/03/10) #132

Merged
amiryahaya merged 1 commit from feat/131-idp-flow into main 2026-11-09 15:27:43 +01:00
Owner

Dev plan task 2.1 (Phase 2 / M2): the Zitadel-first OIDC surface that replaces the legacy per-provider flows at decommission. Tracking issue #131.

authorize — GET /api/auth/idp/authorize?redirect_uri=&invite_token=&pairing_code=:

  • redirect_uri against the Idp:RedirectUris exact-match allowlist (B-6 #37 discipline)
  • PKCE S256; the verifier is bound INSIDE the IDA-10 signed state (safe for a confidential client — the verifier alone can't exchange the code)
  • state = base64url(payload JSON) + "." + base64url(server-identity signature via IKeyStore — asymmetric per IDA-10); payload: nonce + redirect binding + invite_token + pairing_code + verifier + created_at; TTL 10 min, single-use via spent-nonce rows (idp_state_nonces + migration, swept at 15 min)

callback — GET /api/auth/idp/callback?code=&state=&redirect_uri=:

  • fail-closed consume: signature → TTL → redirect binding → nonce replay
  • code exchange with the state-bound verifier; id_token validated via the new 'idp' provider (validator + exchanger config: Idp:ClientId/MetadataUrl/Issuer/ClientSecret/AuthorizeUrl/TokenUrl)
  • IDA-09: email_verified != true → 401 + security.idp_unverified_email audit (the enforcement the legacy flow deferred to task 2.8 is enforced here from day one)
  • identity resolution sub-primary: existing IdP login → auto-link by VERIFIED email (IDA-03 — never onto unverified local addresses or service accounts) → open registration Active+no_workspace (IDA-04) → invite provisioning through Org's UserProvisioningService (the sanctioned Identity→Org seam, #90 invariants apply to state-carried invites)
  • ADR-012 amr-first admin gate; JSON response { session_token, account_id, email, display_name, is_new_account, mfa_required, totp_setup_required, redirect_uri, requires } (org_state / totp_setup) per 02-architecture §4
  • flag-gated Auth:IdpEnabled (§16 rollout); SEC-04 registry + AuthzMatrix rows; IdpCallback added to the ModuleMap sanctioned seam

Tests: 12 new (IdpFlowTests): authorize contract + lookalike rejection + flag-off; tampered/expired/replayed/wrong-binding states; unverified-email rejection; existing-login + passkey-at-IdP full session (ADR-012); open-registration no_workspace; auto-link no-duplicate; invite-in-state lands in tenant. Suite 970/0/39 (Release+Debug), coverage gate 87.97%. Closes #131.

Dev plan **task 2.1** (Phase 2 / M2): the Zitadel-first OIDC surface that replaces the legacy per-provider flows at decommission. Tracking issue #131. **authorize** — GET /api/auth/idp/authorize?redirect_uri=&invite_token=&pairing_code=: - redirect_uri against the **Idp:RedirectUris exact-match allowlist** (B-6 #37 discipline) - PKCE S256; the verifier is bound INSIDE the IDA-10 signed state (safe for a confidential client — the verifier alone can't exchange the code) - state = base64url(payload JSON) + "." + base64url(**server-identity signature via IKeyStore** — asymmetric per IDA-10); payload: nonce + redirect binding + invite_token + pairing_code + verifier + created_at; **TTL 10 min, single-use** via spent-nonce rows (idp_state_nonces + migration, swept at 15 min) **callback** — GET /api/auth/idp/callback?code=&state=&redirect_uri=: - fail-closed consume: signature → TTL → redirect binding → nonce replay - code exchange with the state-bound verifier; id_token validated via the new **'idp' provider** (validator + exchanger config: Idp:ClientId/MetadataUrl/Issuer/ClientSecret/AuthorizeUrl/TokenUrl) - **IDA-09: email_verified != true → 401** + security.idp_unverified_email audit (the enforcement the legacy flow deferred to task 2.8 is enforced here from day one) - identity resolution sub-primary: existing IdP login → **auto-link by VERIFIED email** (IDA-03 — never onto unverified local addresses or service accounts) → open registration Active+no_workspace (IDA-04) → invite provisioning through Org's UserProvisioningService (the sanctioned Identity→Org seam, #90 invariants apply to state-carried invites) - ADR-012 amr-first admin gate; JSON response { session_token, account_id, email, display_name, is_new_account, mfa_required, totp_setup_required, redirect_uri, **requires** } (org_state / totp_setup) per 02-architecture §4 - flag-gated **Auth:IdpEnabled** (§16 rollout); SEC-04 registry + AuthzMatrix rows; IdpCallback added to the ModuleMap sanctioned seam **Tests:** 12 new (IdpFlowTests): authorize contract + lookalike rejection + flag-off; tampered/expired/replayed/wrong-binding states; unverified-email rejection; existing-login + passkey-at-IdP full session (ADR-012); open-registration no_workspace; auto-link no-duplicate; invite-in-state lands in tenant. Suite **970/0/39** (Release+Debug), coverage gate 87.97%. Closes #131.
feat(identity): /api/auth/idp/* — signed-state OIDC surface for the Zitadel-first flow (#131, task 2.1, IDA-01/03/10)
All checks were successful
Security CI / security-scan (pull_request) Successful in 3m7s
API CI / build-and-test (pull_request) Successful in 11m38s
929d050ded
authorize: exact-match redirect allowlist (Idp:RedirectUris), PKCE S256,
and an IDA-10 signed state — payload JSON (nonce, redirect binding,
invite_token, pairing_code, PKCE verifier, created_at) signed with the
SERVER IDENTITY KEY via IKeyStore (asymmetric; the verifier is bound in
the state, safe for a confidential client), TTL 10 min, single-use via
spent-nonce rows (idp_state_nonces + migration, swept at 15 min).

callback: state consume (signature/TTL/redirect-binding/nonce-replay all
fail-closed), code exchange with the state-bound verifier, id_token
validated via the new 'idp' provider, IDA-09 email_verified != true
REJECTED (with security.idp_unverified_email audit), identity resolution
sub-primary: existing IdP login → auto-link by VERIFIED email (IDA-03,
never onto unverified local addresses, never onto service accounts) →
open registration Active+no_workspace (IDA-04) → invite provisioning via
Org's UserProvisioningService seam when the state carries an invite.
ADR-012 amr-first admin gate. JSON response with requires[] client
navigation (org_state / totp_setup). Flag-gated Auth:IdpEnabled.

SEC-04: both routes registered public; AuthzMatrix rows added.
Architecture: IdpCallback joins the sanctioned Identity→Org seam
(ModuleMap — the seam task 2.1 formalizes as Org's public interface).
Sweep: spent nonces removed at 15 min (precomputed DateTimeOffset cutoff).

12 new tests (IdpFlowTests): authorize contract + lookalike rejection +
flag-off; tampered/expired/replayed states; wrong redirect binding;
unverified-email rejection; existing-login + passkey-at-IdP full session;
open registration no_workspace; auto-link without duplicates;
invite-in-state lands in tenant. Suite 970/0/39 Release+Debug,
coverage 87.97%.
Sign in to join this conversation.
No description provided.