Repository navigation
Conversation
…tity linkIdentityToUser sent a signup confirmation email (to an empty address) and returned 422 email_not_confirmed whenever the user being linked to had no email and the new identity's email wasn't verified. This is correct for most providers, but a custom OIDC provider can set email_optional (e.g. only requesting the openid scope), and its identities never carry a verified email. The sign-in path already accounts for this; the linking path did not, so an anonymous user (or one whose only identity is email-less) could never link such an identity. Pass emailOptional through from both callers and skip the confirmation requirement when it's set and the user still has no email after the link, matching the sign-in path's behavior. Fixes supabase#2925
This branch has not been deployed
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 #2925.
linkIdentityToUseronly looked atuserData.Metadata.EmailVerifiedto decide whether to send a signup confirmation before linking a new identity to an existing user. For a custom OIDC provider configured withemail_optional: true(for example one that only requests theopenidscope, like LINE), the linked identity never carries an email, so this check was always true, and the server tried to email an empty address, then returned422 email_not_confirmed— permanently blocking the link (and leaving anonymous users unable to convert).The sign-in path (
createAccountFromExternalIdentity) already handles this correctly:but
emailOptionalwas never threaded through to the linking path.Change
linkIdentityToUsernow takes anemailOptional boolparameter.external.go's OAuth callback andtoken_oidc.go'sIdTokenGrant) already haveemailOptionalin scope fromgetProvider/getExternalProviderType, so it's passed straight through.linkIdentityToUser, the confirmation-required check is nowhasEmail := !emailOptional || targetUser.GetEmail() != ""— mirroring the sign-in path. When the provider isemail_optionaland the user still has no email after the link (UpdateUserEmailFromIdentitiesfound none), linking proceeds without a confirmation email, exactly like sign-in does.email_optionalproviders are unaffected (hasEmailis alwaystruefor them, so behavior is unchanged).Test plan
TestLinkIdentityToUserEmailOptionalWithoutEmail: links an email-less,email_optionalidentity to an anonymous user and asserts the call succeeds, the user is converted from anonymous, and the user ends up confirmed (previously this returned the 422).linkIdentityToUsercall sites/tests updated to passemailOptional=false, preserving current behavior for standard (non-email-optional) providers — e.g.google,facebook,email,test.go build ./...,go vet ./internal/api/..., andgo test ./internal/api/...(full package, local Postgres) all pass.