Skip to content

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

Open

Description

@tjinghahaha

Describe the bug

Custom OAuth/OIDC providers support email_optional. The sign-in path respects it, but the identity-linking path does not. As a result, a custom OIDC identity without an email (for example LINE with only the openid scope) cannot be linked to a user who has no email (for example an anonymous user, or a user whose only identity is Sign in with Apple).

Where (master 8872586)

internal/api/external.go → createAccountFromExternalIdentity takes emailOptional and skips the confirmation when there is no email (hasEmails := … (!emailOptional || …), around line 410).
internal/api/token_oidc.go reads emailOptional from getProvider, but only passes it to createAccountFromExternalIdentity (line 339). The link branch calls a.linkIdentityToUser(r, ctx, tx, userData, providerType) (line 337) without it.
internal/api/identity.go → linkIdentityToUser (lines 199–210): when targetUser.GetEmail() == "" and !userData.Metadata.EmailVerified, it calls sendConfirmation and returns NewCommitWithError(422 email_not_confirmed).

For a generic OIDC token without an email, parseGenericIDToken leaves EmailVerified=false, so this branch is always taken. (Apple is not affected, because parseAppleIDToken marks its emails as verified.)

To reproduce

Create a custom OIDC provider, e.g. custom:line (issuer https://access.line.me, scopes openid, email_optional: true).
Sign in a user who has no email (anonymous, or Apple-only).
Call supabase.auth.linkIdentity({ provider: 'custom:line', token: <id_token>, nonce }).

Actual

The server tries to send a signup confirmation email to an empty address.
With a Send Email Hook configured, the hook receives email_action_type: "signup" with no recipient; when it rejects that, the whole request fails with 500 and the link is rolled back.
Without a hook, the request returns 422 email_not_confirmed, and an anonymous user is never converted (is_anonymous stays true).

Expected

When the provider is email_optional and the identity carries no email, linking should behave like the sign-in path: no confirmation email, the identity is linked, and anonymous users are converted.

Suggested fix

Pass emailOptional into linkIdentityToUser, and skip sendConfirmation when it is true and the identity has no email.

Activity

  1. added
    bug
    on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions