fix(platform): route SSO login to the org matching the user's email (#2082)#2125
Open
larryro wants to merge 2 commits into
Open
fix(platform): route SSO login to the org matching the user's email (#2082)#2125larryro wants to merge 2 commits into
larryro wants to merge 2 commits into
Conversation
added 2 commits
June 24, 2026 16:15
…2082) Multi-org deployments key each OIDC/OAuth2 connection per organization, but the login flow ignored the entered email and the server fell back to the first enabled connection, so second-org users landed at the wrong IdP. - log-in: resolve the org+protocol from the email via /api/sso/discover before starting the flow; thread organizationId to /authorize and SAML login; branch SAML-vs-OIDC on the discovered protocol with the global status as fallback. - authorize_handler: scope resolveSignInConfig by organizationId and carry the resolved org in the signed state. - callback_handler: resolve the same org from state (and on seamless/step-up retries) so the code is exchanged against the correct IdP. - add internal_queries tests for per-org resolveSignInConfig and discoverByEmail routing.
Collaborator
Author
Desk Review — #2082 multi-org SSO routingVerdict: READY TO MERGE. Reviewed branch CI & tests
What the fix does (all three issue points implemented)
Correctness — verified across branches
Security
Non-blocking notes (for awareness, not required for merge)
None of the above blocks merge. READY TO MERGE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2082 — OIDC/OAuth2 SSO login ignored the user's email and always routed to the first enabled connection, so on multi-org deployments second-org users landed at the wrong org's IdP.
Each SSO connection is scoped per organization (the tenant boundary), but the login flow never told the server which org to use:
handleSsoLoginhit/authorizewith no email/org, and both the authorize and callback handlers calledresolveSignInConfig({})which falls through toloadSingleEnabled(first enabled row). The email was only forwarded as an OIDClogin_hint. The email-domain router (discoverByEmail/POST /api/sso/discover) already existed but had zero frontend callers.Changes
app/routes/_auth/log-in.tsx—handleSsoLoginnow POSTs the entered email to/api/sso/discoverfirst, then routes to the resolved org. It threadsorganizationIdto/authorize(andorgto SAML login), and branches SAML-vs-OIDC on the discovered protocol, falling back to the deployment-global status when discovery doesn't resolve (empty email / single-org / network failure).convex/enterprise_sso/login/authorize_handler.ts— readsorganizationIdfrom the query, scopesresolveSignInConfigto it, and carries the resolved org in the signedstate.convex/enterprise_sso/login/callback_handler.ts— recoversorganizationIdfromstateand resolves the same connection (including on seamless/step-up retries) so the code is exchanged against the correct IdP.convex/enterprise_sso/internal_queries.test.ts— new tests for per-orgresolveSignInConfigscoping anddiscoverByEmaildomain routing + fallback.Verification
tsc --noEmit— cleanoxlint --type-awareon changed files — cleanvitest --project server enterprise_sso— 46 passed (incl. 3 new)Single-org self-hosted deployments are unaffected: discovery falls back to the single enabled connection exactly as before.