Skip to content

identity: respect email_optional when linking an email-less OIDC identity - #2939

Open
rnikhori wants to merge 1 commit into
supabase:masterfrom
rnikhori:fix/link-identity-email-optional-oidc
Open

rnikhori wants to merge 1 commit into
supabase:masterfrom
rnikhori:fix/link-identity-email-optional-oidc

Conversation

@rnikhori

Copy link
Copy Markdown

Summary

Fixes #2925.

linkIdentityToUser only looked at userData.Metadata.EmailVerified to decide whether to send a signup confirmation before linking a new identity to an existing user. For a custom OIDC provider configured with email_optional: true (for example one that only requests the openid scope, 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 returned 422 email_not_confirmed — permanently blocking the link (and leaving anonymous users unable to convert).

The sign-in path (createAccountFromExternalIdentity) already handles this correctly:

hasEmails := providerType != Web3Provider && (!emailOptional || decision.CandidateEmail.Email != "")

but emailOptional was never threaded through to the linking path.

Change

  • linkIdentityToUser now takes an emailOptional bool parameter.
  • Both call sites (external.go's OAuth callback and token_oidc.go's IdTokenGrant) already have emailOptional in scope from getProvider/getExternalProviderType, so it's passed straight through.
  • Inside linkIdentityToUser, the confirmation-required check is now hasEmail := !emailOptional || targetUser.GetEmail() != "" — mirroring the sign-in path. When the provider is email_optional and the user still has no email after the link (UpdateUserEmailFromIdentities found none), linking proceeds without a confirmation email, exactly like sign-in does.
  • Non-email_optional providers are unaffected (hasEmail is always true for them, so behavior is unchanged).

Test plan

  • Added TestLinkIdentityToUserEmailOptionalWithoutEmail: links an email-less, email_optional identity 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).
  • Existing linkIdentityToUser call sites/tests updated to pass emailOptional=false, preserving current behavior for standard (non-email-optional) providers — e.g. google, facebook, email, test.
  • go build ./..., go vet ./internal/api/..., and go test ./internal/api/... (full package, local Postgres) all pass.

…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
@rnikhori
rnikhori requested a review from a team as a code owner November 18, 2026 06:49

This branch has not been deployed

No deployments
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.

linkIdentityToUser ignores email_optional for custom OIDC providers → linking an email-less identity to an email-less user always returns 422

1 participant