Repository navigation
feat(account): make email optional for OAuth2 account linking - #13255
Merged
Merged
Conversation
Only the OAuth2 provider user ID is now required, matching how name is optional. When a provider returns no email, the flow skips email policy enforcement, email-based account matching, email conflict checks, email parsing, and the email messaging target; users are created with a null email like anonymous accounts. This also fixes false positives where empty-string providerEmail queries could match other email-less identities, and a crash (GENERAL_INVALID_EMAIL) when an email-less user linked an email-less provider. Also adds explicit duplicate-identity protection: linking an OAuth2 identity (provider + providerUid) already connected to another user now fails cleanly with USER_ALREADY_EXISTS instead of surfacing a raw Duplicate from the unique index, checked early in the linking flow before the current session is deleted, with a try/catch backstop at identity creation for races. Adds a mock-no-email provider (excluded from SDK enums like the other mocks) and an e2e test covering account creation without email, re-login resolving to the same account, and the duplicate-identity protection. Co-Authored-By: Claude Fable 5 <[email protected]>
Meldiron
marked this pull request as ready for review
August 17, 2026 12:23
Contributor
Greptile SummaryThe PR allows OAuth providers without email addresses while preserving identity uniqueness and email-target consistency.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Reviews (4): Last reviewed commit: "Merge branch 'main' into feat-oauth2-opt..." | Re-trigger Greptile |
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Clean up the user (and email target) created within the same request when identity creation loses the (provider, providerUid) unique index race, so concurrent first logins with the same OAuth2 identity no longer leave an orphan account. Create the email messaging target when a later OAuth2 login backfills the email of a previously email-less user, so messaging can resolve the recipient; tolerate an existing target with the same identifier via the unique index. Extends the e2e test to cover the backfill path: an email-less OAuth2 user links a provider that returns an email and gains both the account email and the messaging target. Co-Authored-By: Claude Fable 5 <[email protected]>
Contributor
Author
|
Addressed both Greptile P1 findings in 613d37f:
The e2e test was extended to cover the backfill path (email-less OAuth2 user links |
TorstenDittmann
approved these changes
Aug 24, 2026
Reconcile the canonical-email guard: keep this branch's !empty($email) check for email-less OAuth providers alongside main's delivery-safe canonicalization (!$canonicalize) exemption, and initialize $canonicalize for the provider-without-email path. Co-Authored-By: Claude Fable 5 <[email protected]>
2 tasks done
2 of 3 tasks
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.
What does this PR do?
Makes email optional in the OAuth2 session/linking flow — only the provider's user ID remains required, matching how name is already optional. Also adds explicit protection so the same OAuth2 identity (provider + providerUid) cannot be connected to two accounts.
Email is now optional
USER_UNAUTHORIZED: 'OAuth provider failed to return email'failure when creating a new user.email = null(mirroring anonymous users) andemailVerification = falseeven if the provider claimsverified: true.providerEmail = ''queries could match other email-less identities, and a crash (GENERAL_INVALID_EMAILvianew Email('')) when an email-less user linked an email-less provider.Duplicate OAuth2 identity protection
The DB has always had a unique
(provider, providerUid)index onidentities, but nothing checked it at the application level. Linking an identity already connected to another user now fails cleanly withUSER_ALREADY_EXISTS:Duplicatetry/catch backstop at identity creation to cover races.Test infrastructure
Adds a
mock-no-emailprovider (excluded from SDK enums like the other mocks) plustestCreateOAuth2SessionWithoutEmailcovering: account creation without email, re-login resolving to the same account, and a second user being blocked from linking the already-connected identity.Test plan
testCreateOAuth2AccountSession,testCreateOAuth2AccountSessionLoopback,testOAuth2TokenSessionProviderAccessToken,testCreateOidcOAuth2Token,testConvertAnonymousAccountOAuth2,testOAuthUnverifiedEmailCannotLinkToExistingAccount,testOAuthVerifiedEmailCanLinkToExistingAccount.Notes for reviewers
Cookie sessions still record
factors: ['email', 'oauth2']for email-less users — left unchanged deliberately since theoauth2factor is what bypasses MFA; happy to make it conditional if preferred.🤖 Generated with Claude Code