Skip to content

Phase 4c: Intercept non-SSO logins for enforced domains#2798

Open
GregorShear wants to merge 2 commits intogreg/sso-phase-4/bfrom
greg/sso-phase-4/c
Open

Phase 4c: Intercept non-SSO logins for enforced domains#2798
GregorShear wants to merge 2 commits intogreg/sso-phase-4/bfrom
greg/sso-phase-4/c

Conversation

@GregorShear
Copy link
Contributor

@GregorShear GregorShear commented Mar 20, 2026

  • Add enforce_sso boolean column to tenants.
  • GoTrue customize_access_token hook (check_sso_requirement) blocks social login for users whose email domain matches an SSO-enforcing tenant's configured domain in auth.sso_domains.
  • The hook checks auth.users.is_sso_user — SSO users always pass through (important for token refresh).
  • Blocked logins receive a 403 error with message: 'sso_required:<domain>' — the frontend parses the domain and calls supabase.auth.signInWithSSO({ domain }) to redirect the user to their IdP.

Users whose email domain does NOT match an enforcing tenant's SSO domain (e.g., contractors with @gmail.com) are not blocked by the hook. Their grants on enforcing tenants are handled by grant filtering in 4d instead.

Activated by enforce_sso = true. Tenants configure SSO first, then communicate the transition to their users. enforce_sso is flipped on a hard cutoff date.

Verify:

  • Social user with matching email domain on enforcing tenant → blocked with sso_required:<domain>
  • Social user with matching domain, enforce_sso = false → not blocked
  • Social user with non-matching domain (e.g. @gmail.com) → not blocked (grants handled by 4d)
  • SSO user (is_sso_user = true) with matching domain → not blocked (token refresh works)
  • Blocked user redirected via signInWithSSO({ domain }) → authenticates via IdP → grant migration trigger fires
  • Malformed hook input → exception caught, login not blocked, warning logged

@GregorShear GregorShear force-pushed the greg/sso-phase-4/b branch 3 times, most recently from 0adfd5f to 825b209 Compare March 20, 2026 17:03
@GregorShear GregorShear force-pushed the greg/sso-phase-4/b branch 5 times, most recently from bb22086 to 7cb615f Compare March 23, 2026 21:22
@GregorShear GregorShear force-pushed the greg/sso-phase-4/c branch 4 times, most recently from 8a8f8f5 to 9479354 Compare March 24, 2026 00:35
@GregorShear GregorShear changed the title Phase 4c: Soft SSO login nudge (access token hook) Phase 4c: Login intercept Mar 24, 2026
@GregorShear GregorShear requested review from jshearer and psFried March 24, 2026 00:37
@GregorShear GregorShear marked this pull request as ready for review March 24, 2026 00:48
exception when others then
-- Never block login due to a bug in this hook.
raise warning 'check_sso_requirement failed for user %: %', target_user_id, SQLERRM;
return event;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking for input here - should we block or pass users on exception? do we favor breaking login, or adding a security hole?

either way i'll need help setting up an alert for that warning.

@GregorShear GregorShear changed the title Phase 4c: Login intercept Phase 4c: Intercept non-SSO logins for enforced domains Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant