Social Login Account Linking: Don’t Merge Users by Email
Do not link a social-login identity to an existing account just because the email claims match. Treat the match as an account collision. The safe flow requires an authenticated session for the existing account, a fresh authentication with the identity provider, and a link stored under the OpenID Connect combination of iss and sub. Email is useful profile data. Even email_verified: true is not permission to merge two accounts.
The dangerous merge fits in one query
This hypothetical callback contains the mistake:
const existing = await users.findByEmail(claims.email);
if (existing) {
await identities.link(existing.id, claims.sub);
return signIn(existing.id);
}
The code authenticates one federated identity, searches for a different local identity by a mutable attribute, then connects them without proving that the same person controls the existing account. It also loses the provider boundary because sub is unique only within its issuer.
OWASP’s federated account-linking guidance is explicit: use iss and sub together, do not auto-link on matching email or username claims, and require an authenticated session with the existing account before changing links.
A matching email can still help you present the right next step. It cannot silently choose the account that receives the new login method.
Make issuer and subject the login key
OpenID Connect Core section 5.7 says that iss plus sub is the only claim combination a relying party can depend on as a stable identifier. Other claims, including email, can change over time and are not guaranteed to be unique.
I would keep linked identities in their own store with user_id, validated issuer, validated subject, the observed profile email, and an audit timestamp. Enforce one unique constraint on (issuer, subject). A federated identity must not point to two local accounts. When the provider later changes the email claim, login should still resolve through the same federated key. Treat the new email as a profile update that needs its own policy, not as an instruction to move the link.
Use one documented email comparison policy when you detect collisions. The guides to email case sensitivity, Gmail dot variants, and plus addressing explain why broad canonicalization can merge distinct addresses. Collision detection should be consistent. Account linking still needs authentication.
Route each collision to one explicit action
The useful decision is not “Do these emails match?” It is “Which identity has been authenticated, and what may this request change?”
| Observed state | Action | Reason |
|---|---|---|
(iss, sub) is already linked |
Sign in to that linked local account | The stable federated key already owns the relationship |
| No link and no local email collision | Create a new account if signup policy allows | There is no existing identity to merge |
| No link, email collision, user is signed out | Do not link; offer the normal sign-in or recovery path | The callback proved the new identity, not control of the existing account |
| No link, user is signed in to the intended account | Run the explicit linking ceremony | Both sides can now be authenticated |
| Federated key is linked to another local account | Stop and require account recovery or support review | Moving the key would transfer a login method between accounts |
Keep the signed-out collision response generic. Revealing that the matching email already has an account turns the callback into another enumeration surface. The existing email-enumeration guide covers the public-response boundary.
Link only inside a two-authentication ceremony
NIST SP 800-63C-4 requires an authenticated session for all account-linking functions and says that session should authenticate with an existing federated identifier before a new one is attached. For an account that also supports passwords or passkeys, apply the same principle with a fresh authentication appropriate to that account.
- Start in account settings. The user must already have an authenticated session for the account that will receive the link.
- Require fresh authentication. Do not let a long-lived or stolen session add a new login method without re-authentication.
- Create a short-lived linking transaction. Bind it to the local user, intended provider, current session, and one-time state value.
- Authenticate the new identity. Use a maintained OIDC library and validate the ID token’s signature, issuer, audience, expiry, and nonce.
- Check the federated key. Reject the operation if
(iss, sub)belongs to another local account. - Commit once. Insert the link and consume the linking transaction in one database transaction so callback retries cannot create a different result.
- Notify the user. Send a security notice after a login method is added or removed. NIST requires notice for those account-link events.
Bind the callback to the linking transaction, not merely to whichever user happens to have a browser session when the callback arrives. That prevents a normal sign-in response from being mistaken for authorization to modify account credentials.
What does email_verified: true change?
It changes how much you can trust the email claim, but not who may authorize an account merge. OpenID Connect defines email_verified: true to mean the provider took affirmative steps to verify control of the address at the time of verification. The specification also says the method is context-specific and depends on the provider’s trust framework.
The strongest objection is reasonable: if both accounts show the same verified email, why make the user sign in twice?
Because the two proofs have different scope. The provider authenticated its subject and reported an email attribute. Your application still needs authorization from the existing local account before adding a new credential to it. The extra step is not another email-quality check. It is proof that the current account holder chose the link.
Email verification belongs earlier, when a person types an address for native registration or changes the address on an account. The current emailverifier.dev API returns address status, an allow/review/block action, and the underlying signals. It can catch a confirmed failure or preserve an inconclusive result as unknown. It does not prove inbox ownership, real-world identity, or permission to link accounts.
If you collect a new recovery address during the linking flow, handle it through the separate email-change process. Do not copy an identity-provider claim into the primary recovery field as a side effect of linking.
Unlinking must leave a safe way back in
Removing a linked identity is also a credential change. Require fresh authentication, disallow future access through the removed (iss, sub), and notify the user.
Before deletion, prove that the account will retain another usable login or recovery method. If the link being removed is the only authenticator, add and verify a replacement first or move the account into a deliberate recovery flow. Do not leave an active account with no way for its owner to return.
Before shipping, run three integration tests. A matching email while signed out must never create a link. A signed-in linking transaction must bind the intended (iss, sub) once, even if the callback is retried. After unlinking, that federated identity must stop logging in while the account’s remaining credential still works.