Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Supporting several providers

A relying party 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 issuer 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 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 secret, 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: RS256

Each entry has its own configuration document, fetched from its own issuer and checked against it, its own cached key set, and its own client secret. When an ID token 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 token 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, nonce and PKCE 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 endpoint. 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 iss parameter, its own issuer, to every authorization response, beside code and state, and its metadata says so with authorization_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 at https://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 OAuth'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:

  1. Find the pending attempt by state, and confirm that it belongs to this browser's session.
  2. Confirm that the response arrived at the attempt's return address, and that iss matches the expected issuer when that provider sends it.
  3. Exchange the code at the token endpoint from that provider's configuration, with the credential that provider issued.
  4. 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:

The collage app's sign-in links, keyed by issuer and subject
IssuerSubjectCollage account
https://auth.photos.exampleuser-2048Ava's account
https://accounts.mail.examplea94f1c07e2Not 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.

Three ID tokens reach the collage app. Only the pair of issuer and subject keeps the mail service's user-2048 out of Ava's account.

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.

Ava selects Continue with your mail account. A response with that attempt's state arrives at https://collage.example/signin/callback, the photo service's return address, with iss naming the photo service. What should the collage app do? 1 of 3

Choose one answer.

The mail service sends a valid ID token whose sub is user-2048, the same value as the subject of Ava's photo account. What should the collage app conclude? 2 of 3

Choose one answer.

To save work, a developer proposes one list of trusted keys for the collage app, holding both providers' key sets. Why is that a mistake? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity