Linking accounts
Linking lets a provider sign-in open an account that already exists. Every link is a new way into that account, so the relying partyAn application that accepts and relies on a sign-in from another service, the name used in OpenID Connect and for passkeys. SAML calls the same role a service provider. asks for proof of control on both sides, never just a matching email address, and treats removing a link with nearly the same care.
Two ways into one account
All domains, identifiers and tokens in these examples are fictional.
Ava opened her collage app account in November 2025, long before the app offered a photo sign-in. It is account 8812, registered with [email protected] and a password, and it holds her collages, her past print orders and her delivery address. So when the registration page asks whether to create a new account or connect an existing one, she chooses to connect.
The collage app can see that the email address the photo service reported, [email protected], is the address on account 8812. Linking the two on that basis alone would be easy. Trust across systems showed why the shortcut fails when a provider never checks addresses. The harder cases are the ones where the provider did check.
Linking adds a row to the sign-in identities table for an account that already exists: the pair https://auth.photos.example and user-2048, pointing at account 8812. Afterward, either Ava's password or her photo account opens the same account, with the same collages and addresses. Later she might link her mail service account as a third way in, with its own row for https://accounts.mail.example and a94f1c07e2.
Every row is a way into the account, so adding one is the same kind of change as enrolling a new security keyA small physical device, plugged in or held near a phone or computer, that holds credentials and uses them to prove you have it. It is an authenticator that resists phishing.. Enrollment, replacement, and recovery set the rule for that: a new way in needs proof from the person who already controls the account, and knowing its email address is not proof. Whoever links has to show control of both sides, the photo account through the validated ID tokenIn OpenID Connect, a signed JWT from the provider, addressed to one client, saying which account authenticated, when, and in answer to which request. It reports a sign-in and is not used to call APIs. and account 8812 through its own sign-in.
Why matching emails is not enough
Suppose the collage app linked automatically whenever a sign-in arrived with email_verified set to true and an address matching an existing account. Each of these situations would then give an account to the wrong person:
| Situation | What the collage app sees | What actually happened |
|---|---|---|
| Someone registered first | A verified photo sign-in for [email protected], and a collage app account with that address | Before Ava ever used the collage app, someone else registered [email protected] there with a password of their own. Nobody confirmed the address, and the app kept the account anyway. |
| The address was reassigned | A verified mail service sign-in for [email protected] | Ava stopped using the address, and the mail service later gave it to someone new, under a different subject. |
| The verification is old or weak | A photo sign-in with email_verified set to true | The provider checked the address once, years ago, by a process the collage app has never assessed. |
The first case is known as account pre-hijacking, and it surprises people because nothing about the photo sign-in is wrong. Ava signs in with her photo account, the collage app links her to what looks like her account, and she adds a delivery address and a card. The person who created the account still knows its password. They sign in whenever they like and see everything she added. The collage app joined a genuine sign-in to an account whose owner it had never established.
The defense starts with the collage app's own records. An account whose address the app never confirmed has no owner it can name, so it is never a candidate for linking. The flow below would have stopped Ava anyway, by asking for a password she never set. Resetting that password through her mailbox would then give the account to whoever controls the address, which is Ava, and should end every sessionThe ongoing connection between later requests and an earlier sign-in, so you are not asked for your password on every click. It is often tracked with a cookie holding an unpredictable session identifier. its creator still had.
The second case is the reuse Claim stability and privacy warned about. The new holder of the address has their own subject at the mail service, so nothing but the email connects them to account 8812, and only email matching would let them in.
The mail service is a closer call, because it runs mail.example. Its verification describes a mailbox it operates, which is stronger evidence than another provider can offer. It still says nothing about who created the collage app account with that address, and it is the very provider that can give the address to someone else, so the collage app asks for proof here too.
A safe linking flow
Ava's path through the collage app shows the safe version. Both sides are authenticated in the same browser session before anything is written:
- The photo side. Her photo sign-in completed normally, with
state, the nonceA random value used for one attempt only. In OpenID Connect, the client sends one in its sign-in request and checks that the same value comes back inside the ID token, showing the token answers this attempt. and the full ID tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. validation. The validated pair waits in the pending registration attached to her session. - The collage app side. She chooses to connect an existing account, and the app asks her to sign in to it with its own method: her password, and the second factor if she has enrolled one. The account to be linked is the one this sign-in proves, not one picked by the email match or named in a form field.
- A check for conflicts. The app confirms that the pair isn't already linked to a different account. If it were, the app would stop and explain rather than move it, because moving a way in from one account to another needs proof for both accounts.
- Confirmation. The app says plainly what will happen: allow the photo account Ava Archer, [email protected], to sign in to this collage app account. Her answer is a POST from the app's own page, protected against cross-site requests.
- The record. In one transaction, the app inserts the identity row and an audit entry recording the account, the issuerThe party that creates and signs a token, assertion, or certificate, named in a token's iss claim. A recipient must check that the issuer is exactly the one it expected and trusts. and subject, the time, and how each side was authenticated.
- Notice. It emails the address it confirmed for account 8812, which need not be the address the photo service reported, and lists the photo account under Sign-in methods with a Remove button.
Starting from the other side works the same way. If Ava were already signed in with her password and chose Link photo account under Sign-in methods, the app would ask for the password again unless she had just entered it, then start a new authenticationChecking evidence that someone, or some application, controls an account, such as a password or a passkey. It establishes which account is being used, not what that account may do. request with fresh state, nonce and PKCEProof Key for Code Exchange, pronounced pixie: the client creates a secret for each authorization attempt, sends only a hash of it at the start, and proves it holds the secret when redeeming the code, so a stolen authorization code is useless to anyone else. values. The pending attempt records that it is for linking, and the account to link comes from her session, never from anything in the request.
Request correlation and CSRF showed an attacker delivering a callback for their own photo account into someone else's browser. Against a linking flow, success would give the attacker's photo account a permanent way into Ava's collage app account. The session-bound state and the nonce stop that forged callback. The confirmation is a second barrier, since no link is created without Ava seeing which photo account is being added, and the notice tells her if one was created anyway.
Removing a link
Some months later, with her mail service account linked as well, Ava decides to stop signing in with the photo one. Removing a link takes away a way in, and it deserves nearly as much care as adding one.
The collage app asks her to prove control again before removing anything, since a session left open on a shared computer shouldn't be enough to change how the account is protected. Asking the provider itself for a fresh sign-in, instead of the app's own password, is covered in Session age and reauthentication.
It also makes sure a way in remains. Ava still has a password and the mail service, so removing the photo account is safe. A customer who signed up through the photo service and never set a password has only that one row, and removing it would leave an account nobody can open. The app refuses that removal until another method exists.
Then it deletes the row, writes an audit entry and sends a notice, as it did for the link. It can also end any collage app sessions that were opened through the removed identity, which is one reason the session record in Establishing an application session notes how each session began.
Some things stay as they were. The sign-in link and any connection that lets the app read Ava's photos are separate records, so stopping photo sign-in doesn't cancel that photo access, and disconnecting the photo access doesn't lock her out. Removing the link also tells the photo service nothing: the collage app stays on her photo account's list of connected applications until she removes it there.
The next time anyone signs in with user-2048, the lookup finds no row, and the collage app treats it as a first sign-in: create an account, or connect an existing one by proving control of it. The matching email is no more a reason to restore the link quietly than it was to create it.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Connect Lab Mail to Ava's account, then remove it with careTrust Lab Mail as an identity provider for Lab Photos, see the tenant ignore a matching email and refuse to connect without a fresh sign-in, connect Ava's Lab Mail account, then remove it while another way in remains.