Account Linking
Two sanctioned ways to merge identities, plus unlink, all on one dedicated identity so the contrast is visible in one place. A Post-Login Action detects a same-email match and signals it via an ID token claim — detection only, nothing linked yet. Linking, whether suggested or user-initiated, always requires a real second login into the candidate identity, verified server-side, before any Management API write. Isolated from every other demo in this suite — its own Auth0 application, own test identity.

Not signed in
Sign up a fresh @atko.email address on Email & Password, then sign in again with Google using the same email to see the suggestion appear here — or sign in once and use the link/unlink controls below directly.
Detection is automatic, linking never is — a Post-Login Action only stamps a claim when it finds a same-email, both-sides-verified candidate, which is what drives the suggested-linking banner above. The "Link another login method" control below has no email check at all — it's deliberately scoped to "prove you can authenticate into both," not "these happen to share an email." Either way, the actual POST /identities Management API call only fires after a real second login succeeds — same shared code path, just a different trigger.
An earlier design used Auth0's suspended-transaction redirect primitives (api.redirect.sendUserTo/encodeToken/the /continue resume endpoint) for the suggested-linking consent screen, matching the mechanism the felixcolaci/cic-account-linking reference repo reimplements by hand. Abandoned after adversarial review found that re-authenticating into the candidate identity while the primary login's transaction is suspended risks Auth0 clobbering that suspended transaction server-side. This demo never suspends anything — see the Security Implications panel below.
Strengths
- Detection and linking are two separate steps, and only detection is automatic. A Post-Login Action finds a same-email, both-sides-verified candidate and stamps an ID token claim — nothing is linked yet. Whether the user gets there via the suggested banner or the "link another login method" control, the actual Management API link call only fires after a full, ordinary /authorize round trip into the candidate identity succeeds — the "both accounts authenticated before linking" posture Auth0's own Account Linking guidance calls for, not an email-match-plus-consent shortcut. Closes the exact takeover vector /demo/google-one-tap's own notes warn about (an attacker who merely controls a second account with a matching address consenting as themselves).
- The same-email requirement is specific to the suggested-linking path (that's what the Post-Login Action is matching on). The user-initiated "link another login method" control deliberately has no email check at all — verifySecondaryIdentity() only checks sub/provider and, when a candidate is expected, the connection; it never reads the secondary token's email claim. A signed-in user can link an identity with a completely different email address, by design: proving you can authenticate into both accounts is the actual trust boundary here, not whether the emails happen to match. Worth being explicit about, since a reader skimming only the suggested-linking half could otherwise assume every link on this page requires a matching email.
- Both paths share one hardened link-callback implementation (lib/account-linking.ts) rather than each rolling its own verification. It binds the flow to the initiating browser via an HttpOnly, short-lived signed cookie (not a server-side map keyed only by state) and re-checks that cookie's primary user id against the session actually completing the callback — closes a login-CSRF path where an attacker's own "Link" URL could otherwise be reused to attach a victim's freshly-authenticated secondary identity to the attacker's account. Caught on adversarial review of the first draft, which used a bare state map.
- Unlinking is blocked on two identities, not one: the primary (Auth0's own hard constraint — "Main identity cannot be removed") and, separately, whichever identity actually authenticated the current session even when that isn't the primary — unlinking it would instantly orphan the session mid-use. Both rows show a specific, visible reason rather than a generic disabled state or a surprise error.
Risks & Considerations
- A user who repeatedly dismisses the suggestion is re-prompted on every subsequent login until a decision is recorded in app_metadata — intentional, not a bug, but worth knowing if this demo is left logged-in-and-dismissed across a presentation.
- email_verified: true on both sides is a precondition for suggesting a match, not proof of common ownership — it only narrows false positives from typos/unverified signups. The actual ownership proof is the secondary login that happens before any link call, not the email match itself.
- If a user's only secondary identity is unlinked and the primary later becomes unusable (revoked OAuth grant, deleted account on the provider side), there is no account-recovery path in this demo — stated here explicitly rather than left for someone to discover by locking themselves out.
- A successful Management API link does not retroactively update the current session's already-issued ID token — the link-callback route re-fetches identities server-side for display rather than relying on anything cached in the session, specifically to avoid showing stale "not yet linked" state right after a link that actually succeeded.
- "Real re-authentication before linking" is not absolute. The /authorize call sets prompt=login, which forces Auth0's own session layer to re-check — but for a federated social connection (google-oauth2), if the browser already holds a live session with the upstream IdP itself (e.g. two already-signed-in Google sessions in the same browser), Google can silently re-assert that session back to Auth0 without ever showing its own credential prompt. prompt=login does not reliably propagate to force the upstream IdP's own prompt. In that specific case, this flow can complete without the user seeing any login screen at all — confirmed live, not a theoretical edge case. Forcing Google's own prompt specifically would need an upstream, connection-level parameter (e.g. Google's own prompt=select_account), not implemented here.
Hardening Checklist
- This demo originally attempted Auth0's native suspended-transaction redirect primitives (api.redirect.sendUserTo / encodeToken / onContinuePostLogin / the /continue resume endpoint) for the suggested-linking consent screen, matching the mechanism the felixcolaci/cic-account-linking reference repo reimplements by hand. That design was abandoned after adversarial review (two independent frontier models, 2026-11-05) found that re-authenticating into the secondary account while the primary transaction is suspended risks Auth0 clobbering the suspended transaction server-side — the state parameter alone does not isolate the two logins. The final design never suspends the primary login at all: the Action only signals a candidate match via a claim, and linking happens afterward as an ordinary step, the same way the user-initiated path always worked. Worth citing directly as a non-obvious Auth0 behavior, not just an internal design note.
- The M2M (client-credentials) path is used for the actual POST/DELETE /identities calls, not the user-token link_with path — deliberate, since the real authentication proof (the fresh /authorize round trip) already happened before the Management API call fires; the M2M call only persists a decision a human already proved by logging in, not a substitute for that proof.
- Every external ID token this flow accepts is verified against the tenant's real JWKS (RS256 pinned, issuer/audience checked) before anything is extracted from it — same discipline as this suite's other external-token demos (Firebase CTE, Google One Tap), not trusted unchecked from the SDK.