Supporting several providers
A 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. that offers a second sign-in button takes on a second trust relationship. This lesson follows the collage app as it adds the mail service beside the photo service, keeps the two entirely apart, refuses a mixed-up response before its code goes anywhere, and records each account by 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.
Adding a second provider
Not everyone who makes collages keeps their photos at the photo service, and several customers have asked to sign in to the collage app with their mail account instead. So the collage app adds a second button, Continue with your mail account, beside Continue with your photo account. Ava happens to have both: her photo account, and the mailbox at the mail service that receives [email protected].
The mail service is an OpenID ProviderA service that authenticates users and tells other applications about the sign-in, so those applications never handle the users' passwords. In OpenID Connect it is called an OpenID Provider. with its own issuer, https://accounts.mail.example. The collage company registers the collage app there as a separate client. The mail service issues its own client ID, the random-looking c2d7a915-4e8b-4f03-a6d2-7b19e5f80c4d, and its own client secretA shared secret that a confidential client uses to prove itself to the authorization server, much like a password for an application. It belongs on a backend, never in code sent to browsers or phones., and the collage app gives this provider a return address of its own. Once discovery has filled in the rest, the collage app's configuration holds two independent entries:
Photo service
Issuer: https://auth.photos.example
Client ID: photo-collage
Return address: https://collage.example/signin/callback
Sends iss: yes, and its metadata says so
ID token algorithm: RS256
Mail service
Issuer: https://accounts.mail.example
Client ID: c2d7a915-4e8b-4f03-a6d2-7b19e5f80c4d
Return address: https://collage.example/signin/mail/callback
Sends iss: no
ID token algorithm: RS256Each entry has its own configuration document, fetched from its own issuer and checked against it, its own cached key setA JSON document, published at a fixed HTTPS address, that lists an issuer's current public keys so others can verify its signatures. It never contains private keys., and its own client secret. When an 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. arrives, the collage app validates it entirely with the entry for the provider the attempt was started with. The issuer must be that provider's issuer, the key must come from that provider's key set, and the audience must contain the client ID that provider issued. An 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. from the mail service names c2d7a915-4e8b-4f03-a6d2-7b19e5f80c4d in aud, not photo-collage, because each provider knows the collage app only by its own client ID.
The shortcut to avoid is merging the entries. A single combined list of trusted keys, for example, would let a key from the mail service's set verify a token that claims to come from the photo service. Key IDs do not prevent that: each provider chooses its own kid values, and two providers can easily publish keys with the same one. The collage app trusts the mail service to speak for mail service accounts and the photo service to speak for photo service accounts, and a merged configuration would let either speak for the other.
Keeping providers apart
A sign-in now begins with a choice, and the pending attempt records it. When Ava selects Continue with your mail account, the collage app's pending sign-in names https://accounts.mail.example as the expected issuer and https://collage.example/signin/mail/callback as the return address, along with the attempt's own state, 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 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. verifier.
With two providers, the collage app is exposed to the attack that Authorization server mix-up followed through a compromised Pixel Vault, and current guidance requires a defense from the moment a client works with a second server.
In a sign-in, the stakes are higher than they were for a photo connection. Suppose the mail service were compromised. When Ava chooses it, it sends her browser straight on to the photo service, using the collage app's photo service client ID and return address, her attempt's state, and the nonce and PKCE challenge from a sign-in the attacker started in their own browser. Ava approves at the photo service, which she trusts, and its genuine code returns to the collage app. A collage app that believed the mail service had answered would send that code to the mail service's token endpointThe authorization server address where clients exchange an authorization code, refresh token, or other grant for tokens, in a direct request rather than through a browser redirect.. The attacker could then inject it into their own waiting attempt, where the nonce and verifier match, and the collage app would sign the attacker in as Ava.
The ID token cannot catch this, even though it names its issuer. In the code flow, the ID token arrives in the token response, after the collage app has already chosen a token endpoint and sent the code there. The check has to happen at the callback, before the code goes anywhere. Two signals can make it, and the collage app uses whichever each provider supports:
- The photo service adds an
issparameter, its own issuer, to every authorizationDeciding whether a requested action is permitted, such as whether a signed-in account may delete a particular photo. Authentication says which account is asking; authorization decides what it can do. response, besidecodeandstate, and its metadata says so withauthorization_response_iss_parameter_supported: true. The collage app compares the value exactly with the attempt's expected issuer, and rejects a response for a photo service attempt that arrives without it. - The mail service does not send
iss. For its attempts, the collage app relies on the separate return address: a response for a mail service attempt must arrive athttps://collage.example/signin/mail/callback, and a response that arrives anywhere else ends the attempt.
In the attack above, the photo service's response arrived at the photo service's return address, carrying the photo service's issuer, for an attempt that expected the mail service. Either check stops it before any token request. Separate return addresses are the weaker of the two. An attacker who can register a client of their own at an honest provider, using the address the collage app gave another provider, can get around them. Current guidance therefore prefers iss wherever a provider offers it. Older integrations that receive an ID token directly in the callback can check that token's iss at the same point, as Response types, response modes, and older flows shows, and Advanced OAuthA framework that lets a person give an application limited access to their resources at another service, using tokens instead of sharing their password. OAuth is about access; OpenID Connect adds sign-in.'s Authorization response issuer identification group covers the rules for iss in detail.
Put together, the collage app's callback works in a fixed order:
- Find the pending attempt by
state, and confirm that it belongs to this browser's session. - Confirm that the response arrived at the attempt's return address, and that
issmatches the expected issuer when that provider sends it. - Exchange the code at the token endpoint from that provider's configuration, with the credential that provider issued.
- Validate the ID token with that provider's issuer, key set and client ID, and with the attempt's nonce.
A response can only confirm the provider the attempt expected or end the attempt. It never chooses which provider's entry the collage app uses next.
The same subject in two places
Suppose Ava signs in once with each button. After validation, the claims that identify her look like this, with the others left out:
Signed in with the photo service:
{
"iss": "https://auth.photos.example",
"sub": "user-2048",
"aud": "photo-collage"
}
Signed in with the mail service:
{
"iss": "https://accounts.mail.example",
"sub": "a94f1c07e2",
"aud": "c2d7a915-4e8b-4f03-a6d2-7b19e5f80c4d"
}One person has two subjects, and nothing in either token says they belong together. Each provider chose its identifier for Ava independently, and neither knows about the other.
The reverse can happen too. A subject is unique only within its issuer. Nothing stops the mail service from giving the identifier user-2048 to someone else entirely, and that person's ID token would be just as valid as Ava's. If the collage app looked customers up by sub alone, that stranger would arrive in Ava's collage account. So the collage app records each sign-in link as the pair of issuer and subject:
| Issuer | Subject | Collage account |
|---|---|---|
https://auth.photos.example | user-2048 | Ava's account |
https://accounts.mail.example | a94f1c07e2 | Not linked yet |
Ava
- iss
- auth.photos.example
- sub
- user-2048
- By sub alone
- Ava's account
- By iss and sub
- Ava's account
Ava's account
Ava
- iss
- accounts.mail.example
- sub
- a94f1c07e2
- By sub alone
- No account
- By iss and sub
- No account
Not linked yet
Someone else
- iss
- accounts.mail.example
- sub
- user-2048
- By sub alone
- Ava's account
- By iss and sub
- No account
A stranger in Ava's account, if keyed by sub alone
A subject is unique only within its issuer.
Whether Ava's mail sign-in should open the same collage account as her photo sign-in is a question the subjects cannot answer. The obvious clue is an email address, since both providers can report [email protected]. Linking accounts explains why a matching address is not enough on its own, and Connecting a sign-in to an account shows how the collage app stores the pair.
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
- Run one relying party against two providers and stop a mix-up at the callbackSign the collage app in with Lab Photos and Lab Mail from fully separate configurations, refuse a mixed-up response before the code goes anywhere, and key accounts by issuer and subject.