Provider discovery
Every check the collage app makes on 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. compares it with values the collage app already holds. This lesson follows where most of those values come from: one document the photo service publishes, found from the issuer alone, and the checks that decide whether the collage app may believe it.
Finding the provider's configuration
When the collage app signs Ava in, Validating an ID token compared her 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. with values the collage app already held. The issuer had to be exactly https://auth.photos.example. The signing key had to come from the 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. at https://auth.photos.example/jwks. The audience had to include photo-collage, and the algorithm had to be one the collage app accepts. In When validation fails, a mismatch between those expected values and the provider's real ones was one of the commonest causes.
So where did the expected values come from? The client ID came from the collage app's registration with the photo service, which Registering a relying party returns to. The rest came from the photo service itself, which publishes them in a document the collage app can find from a single value.
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. that supports discovery publishes a JSONA text format for structured information, written as named values inside curly braces. APIs, tokens, and discovery documents all use it. document describing itself. Its entries are the provider's metadata, and the OpenID ConnectAn identity layer on top of OAuth 2.0 that lets an application sign people in with an account at another service. It adds the ID token, standard claims, and discovery to the OAuth exchange. Discovery specification says where the document lives: at the issuer identifier with /.well-known/openid-configuration added to the end. Paths under /.well-known/ are reserved for documents that software needs to find without being told where to look.
The collage app's developer started from one value, https://auth.photos.example. From it, the collage app builds the request:
GET /.well-known/openid-configuration HTTP/1.1
Host: auth.photos.exampleThe photo service answers with JSON. This copy is shortened to the entries this lesson needs:
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: public, max-age=86400
{
"issuer": "https://auth.photos.example",
"authorization_endpoint": "https://auth.photos.example/authorize",
"token_endpoint": "https://auth.photos.example/token",
"userinfo_endpoint": "https://auth.photos.example/userinfo",
"jwks_uri": "https://auth.photos.example/jwks",
"id_token_signing_alg_values_supported": ["RS256", "ES256"],
...
}Every address the collage app has used since Ava's first sign-in is here: where to send her browser, where to exchange the code, where to ask for her profile, and where to find the keys that sign ID tokens. Without discovery, a developer copies each value from the provider's documentation into the collage app's settings and hopes to notice when one changes. With it, the collage app's own settings for the photo service shrink to the issuer and what its registration gave it, such as its client ID and credential. Reading provider metadata goes through the rest of the document.
An issuer can include a path. A provider that runs a separate issuer for each organization it serves might name one https://login.example/org-7. Its document then lives after the path, at https://login.example/org-7/.well-known/openid-configuration, and if the issuer ends with a slash, that slash is removed first so the address does not contain two. 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. has a similar document for 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. servers that was generalized from this one, but it puts its well-known name before the path instead, so the two addresses differ whenever an issuer has a path. Authorization server metadata covers it in Advanced OAuth.
Checking the document
For 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., this document decides whose signatures count. Suppose the collage app accepted a copy that listed an attacker's key set under the photo service's name. The attacker could sign an ID token saying "sub": "user-2048", Ava's subject, and every check in Validating an ID token would pass: the right issuer, the right audience, and a valid signatureA value made with a private key that lets anyone holding the matching public key check that a message came from the key's holder and has not been changed. It proves origin and integrity; it does not hide the message. from a key in the configured set. The attacker would be signed in to the collage app as Ava, or as any other customer of the photo service.
Two checks keep the collage app from accepting such a copy. The first is HTTPSHTTP protected by TLS, so traffic is encrypted and checked for changes while it travels. It protects the connection, but does not prove that the site at the other end is honest. with ordinary certificateA signed statement that a public key belongs to a name, such as a website's hostname, for stated purposes and a limited period. A certificate authority signs it, so software that trusts the authority can connect the key to the name. validation for auth.photos.example, which establishes that the answer came from the host the collage app named. A relying party that turns certificate checks off, even "just for testing", hands that decision to whoever controls the network between it and the provider. The collage app also refuses to follow a redirect when it fetches the document, because the answer has to come from the address it built, not from wherever a redirect points.
The second is the issuer value inside the document. It must be identical to the issuer the collage app used to build the address, character for character, so https://auth.photos.example/ with a trailing slash fails. When the mismatch comes from the relying party's own setting, such as an issuer typed with a trailing slash, the fix is to correct the setting, never to loosen the comparison. The same string must also appear in every ID token from this provider, which makes one value the link between three places:
| Where the issuer appears | Value |
|---|---|
| The collage app's configuration | https://auth.photos.example |
issuer in the document fetched from https://auth.photos.example/.well-known/openid-configuration | https://auth.photos.example |
iss in every ID token the collage app accepts from this provider | https://auth.photos.example |
The check matters most where the expected issuer and the document's address can drift apart. Many libraries let a developer configure the address of the configuration document directly. If that address is wrong, through a typing mistake or a convincing fake setup guide, the document it leads to can claim to be https://auth.photos.example and list someone else's keys. A relying party that took its expected issuer from that document would then compare every ID token with values an attacker chose. When a library asks for the document's address, the relying party also configures the issuer it expects and requires the document's issuer to match it. A document that fails is discarded whole, never used in part.
The answer itself must be a 200 response containing a JSON object. An error page, or a document missing required entries such as jwks_uri, is a failure to report, not something to work around.
The document changes rarely, so the collage app does not fetch it for every sign-in. It loads it when it first needs it, keeps it, and fetches it again on a schedule. Here the schedule follows the photo service's Cache-Control header, whose max-age=86400 says a copy may be kept for 86,400 seconds, one day. Every refreshed copy goes through the same checks as the first. If a refresh fails, or produces a document that does not pass, the collage app keeps its last good copy for a while and alerts its operators. If it has never obtained a good copy, sign-in with the photo service is unavailable until it does, because the only alternative would be guessing at endpoints and keys. The key set at jwks_uri follows its own rhythm, fetched again with a limit when an unknown kid appears, as Signing keys and rotation described.
Where trust starts
Discovery fills in the details of a decision someone has already made. The collage company decided to accept sign-ins from the photo service, and a developer wrote https://auth.photos.example into the collage app's configuration. Everything in this lesson begins from that value. Discovery tells the collage app how to work with a provider. It never tells the collage app which providers to work with.
That rules out taking an issuer from anything that arrives during a sign-in. The iss claim in an ID token, the iss parameter on the callback, and a provider named in a link are all values someone else can write. Suppose the collage app fetched configuration for whatever issuer an ID token named. An attacker would put their own issuer in a token, publish a matching document and key set, and pass every check, because each check would compare the attacker's values with the attacker's values. Incoming values are compared with the issuer the collage app chose for the attempt. They never choose it.
The sign-in page follows the same rule. When Ava selects Continue with your photo account, the button sends the collage app a short name such as photos, and the collage app looks that name up in its own list of configured providers. It never takes an issuer address from the request.
Some relying parties let people bring an account from a provider nobody configured in advance. OpenID Connect Discovery describes an optional first step for them, issuer discovery: the person types an identifier such as an email address, and the relying party asks that address's domain which issuer serves it, using a protocol called WebFinger, a small lookup that a domain answers at its own /.well-known/webfinger address. It is rare in practice. A relying party that uses it is accepting providers it did not choose, so it has to decide what a sign-in from an unfamiliar provider is worth, and the issuer it finds still goes through every check in this lesson. Most relying parties, the collage app included, offer a short list of providers chosen in advance.
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
- Configure lab-collage from the issuer alone, and follow a moved endpointDerive every endpoint from one issuer value, check the discovery document the way the lesson requires, and watch a discovered configuration follow an endpoint move that breaks a hard-coded one.