Validating aggregated and distributed claims
A statement from another claims provider is only a string until it has been checked. This lesson follows the collage app from Ava's UserInfoAn OpenID Provider endpoint that returns claims about the signed-in person to a client presenting an access token. Its sub must match the ID token's before the client uses anything it returns. response to a student discount: deciding whom it trusts for which fact, validating Northfield's statement in a fixed order, calling Northfield's endpoint only where it agreed to, and failing safely when the statement does not hold up.
Two signers, two decisions
The collage app has Ava's UserInfo response, and Northfield's statement is in it, or a reference to it is. Its sign-in code has already checked the response the usual way: it came from the photo service over 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., in answer to the collage app's own access tokenA token that a client presents to an API to use access it has been granted, usually limited in what it allows and how long it lasts. It authorizes API calls; it does not tell the client who signed in., and its sub matches the 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.. The discount now depends on Northfield's statement.
Decoding a JWTA JSON Web Token: a compact token made of Base64url-encoded parts that carries claims and is usually signed. Anyone holding it can decode and read the claims, so the signature shows who issued it but hides nothing. takes one line of code, and the decoded claim says true. Applying the discount at that point would mean trusting a statement nobody has checked. The photo service did not sign it, and nothing so far shows that Northfield did either. To the collage app the JWT is a string inside a response, and a string can say anything, including a header with "alg": "none" and no signature at all.
The response combines statements from two parties, and the collage app trusts each one for something different:
| Question | Who answers it | How the collage app checks |
|---|---|---|
| Which photo account signed in? | The photo service | The validated ID token, and a UserInfo response whose sub matches it. |
| Whose enrollment does the statement describe? | The photo service, by placing the statement or reference in this response | The same checks. Northfield's JWT does not name Ava in the photo service's terms. |
| Is that person enrolled, and until when? | Northfield | Northfield's signature, issuer and expiry, checked against the collage app's own configuration. |
The second row is easy to miss. The collage app relies on the photo service to have attached the right statement to the right person. It can check Northfield's signature, but not that the photo service picked Ava's statement rather than a classmate's. That is acceptable only because the collage app already trusts the photo service to identify her, and it is a reason to accept Northfield statements only from providers the collage app has agreed to take them from. If the mail service, which the collage app also offers for sign-in, began including Northfield statements, the collage app would ignore them until it had made the same arrangement with the mail service.
The third row needs a trust relationship of its own. Trusting the photo service gives the collage app no reason to trust Northfield, so it configures Northfield separately, as it would any issuer. In this example Northfield publishes discovery metadata like 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.. The collage app fetched it from https://id.northfield.example/.well-known/openid-configuration, took 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. address from its jwks_uri, and recorded that Northfield signs with ES256 and may vouch for https://id.northfield.example/enrolled.
Checking the statement
For each claim from another source that it wants, the collage app works through the same steps. For an aggregated claim the JWT is already in the response. For a distributed claim it comes from Northfield's endpoint, as the next two sections show, and then gets exactly the same checks.
- Follow the reference from
_claim_namesto its source in_claim_sources. AJWTmember is the statement. Anendpointmember means fetching it first. A missing source, or one with neither member, means the claim is absent. - Check the issuer before using any key. Read
isswithout trusting it yet, and compare it exactly with the claims providers in the collage app's configuration that may vouch for this claim name. Stop if it is not one of them. The collage app never fetches keys from an issuer just because a JWT names it. - Verify the signature with a key from that issuer's configured key set, selected by
kid, using the algorithm configured for that issuer.nonefails here, and so does any key the JWT tries to bring with it. - Check the time.
expmust not have passed, andiatmust not be in the future, allowing a small tolerance for clock differences. The collage app can add a limit of its own as well, such as refusing statements made before the current term began. - Check the audience, if there is one. The specification does not say whom these JWTs are addressed to, so the arrangement with each claims provider settles it. Another provider might address its statements to the photo service or to the collage app, and the collage app would then require exactly that audience. Northfield's statements carry no
aud, so a Northfield JWT that names any audience is rejected. That rule stops a different kind of Northfield JWT being passed off as a statement. 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. that Northfield issued to some other application is also signed with Northfield's key, may even contain the enrolled claim, and names that application inaud. - Read only the claims that were named. The JWT must contain every claim that
_claim_namespoints to it. The photo service may leave some of a claims provider's claims out of_claim_names, for example because Ava did not agree to share them, and the collage app leaves those alone even if the JWT contains them.
As a sketch, for an aggregated claim:
source = response._claim_sources.get(response._claim_names.get(ENROLLED))
if source is None or "JWT" not in source:
return not_available()
statement = decode_without_trusting(source.JWT)
provider = claims_providers.get(statement.iss) # the collage app's own configuration
if provider is None or ENROLLED not in provider.claim_names:
return rejected("unexpected_issuer")
key = provider.keys.find(statement.header.kid) # refetches Northfield's jwks_uri, within a limit, for a new kid
if key is None or statement.header.alg not in provider.algorithms:
return rejected("unknown_key_or_algorithm")
if not verify(key, source.JWT):
return rejected("bad_signature")
if expired(statement.exp) or issued_in_future(statement.iat):
return rejected("stale_statement")
if "aud" in statement: # this arrangement expects none
return rejected("unexpected_audience")
if ENROLLED not in statement:
return not_available()
return statement[ENROLLED]The helper names are illustrative. The order is the point: nothing reads the enrolled claim until the issuer, key, signature and time have all passed.
Before calling the endpoint
Suppose the photo service sends a reference instead. At 09:20 Ava reaches the checkout with a poster and chooses the student discount, she agrees to share her enrollment, and a few seconds later the collage app's UserInfo response points to Northfield's claims endpoint, with a token to ask with.
That address came out of a response. The collage app has checked the response, including that its sub matches the ID token, but the photo service is still asking the collage app to send a request, with a credential, to a server the collage app did not choose. Two things can go wrong.
The first is server-side request forgery, where an attacker gets a server to send requests on the attacker's behalf. If the collage app called whatever address arrived, a mistaken or compromised provider could point it at http://10.0.0.12/claims on the collage company's internal network, or at a slow server that ties up the collage app's workers while Ava waits. The second is the token. Sending demo-northfield-token-4 to any address other than Northfield's would hand a credential for Ava's enrollment status to whoever runs that address.
So the collage app checks the endpoint against its own configuration before calling it. Its Northfield entry gains one more item: the endpoints it has agreed to call, here exactly https://id.northfield.example/claims. The endpoint must use HTTPS and must match exactly. An address the collage app has not agreed to call is treated as though the claim were missing. The call gets a short timeout and a limit on the response size. It does not follow redirects either: an approved address that answered with a redirect could otherwise send the token on to a server the collage app never agreed to call.
Fetching the claim
The collage app sends the token as a bearer tokenA token that works for whoever presents it: the API checks that the token is genuine and current, not who is holding it. That is why bearer tokens must be kept from being copied., and Northfield answers with a JWT, shortened here for display:
GET /claims HTTP/1.1
Host: id.northfield.example
Authorization: Bearer demo-northfield-token-4
HTTP/1.1 200 OK
Content-Type: application/jwt
eyJhbGciOiJFUzI1NiIsImtpZCI6Im5vcnRoZmllbGQtMjAyNi0wOCIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2lkLm5vcnRoZmllbGQuZXhhbXBsZSIs...Because the endpoint must return the claim as a JWT, a plain JSONA text format for structured information, written as named values inside curly braces. APIs, tokens, and discovery documents all use it. body is refused, however reasonable it looks. Decoded, the JWT's claims read:
{
"iss": "https://id.northfield.example",
"iat": 1790846405,
"exp": 1790846705,
"https://id.northfield.example/enrolled": true
}This statement is five seconds old. iat is 09:20:05 UTC and exp is five minutes later, because Northfield expects each application to ask again when it next needs to know.
The collage app validates it with the checks from Checking the statement, in the same order: the issuer against its own configuration first, then Northfield's key and signature, the times, the audience the arrangement expects, and the claim that _claim_names pointed to. Fetching from Northfield's own address over HTTPS does not replace those checks. The connection shows which server answered while it lasts. The signature shows what Northfield stated, and keeps showing it after the connection closes, for example when the checkout service that applies the discount is not the one that made the request.
Whose statement, about whom
The collage app links Ava's account to the pair https://auth.photos.example and user-2048, as Connecting a sign-in to an account described. Northfield's statement changes nothing about that, whichever way it arrived. An embedded statement belongs to whoever the photo service's response describes. A fetched one describes whoever the access token stands for, and the collage app relies on the photo service to have provided a token for Ava's enrollment record. Either way, the discount belongs to the collage account the photo service signed her into.
Some claims providers include a sub after all, which should then be the person's identifier at the claims provider. If Northfield sent "sub": "s-551207", that would be Ava's identifier at Northfield, and it would not match user-2048. The mismatch is expected. Subjects are scoped by their issuer, as Supporting several providers explained, so the collage app never compares a Northfield subject with a photo service subject, and never uses one to find or create an account.
A Northfield subject could still have a use. A collage app worried that one enrollment might unlock discounts on many accounts could record it, under Northfield's issuer, to notice the same student record appearing again. Its privacy cost is a reason to leave the subject out, though: an identifier that is the same for every application Ava shares it with lets those applications recognize her across all of them. Unless the arrangement calls for it, the collage app does not store it.
When the statement fails
A failed check on Northfield's statement is not a failed sign-in. The ID token and the UserInfo response were valid, and Ava is still signed in to the same account. Only the discount is in question. A claims provider may also decline to return a claim, and the specification says 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. should treat a claim missing from the endpoint's answer like any other requested claim that was not returned. More can go wrong with a fetch than with an embedded statement, because more parties must be working at the moment Ava checks out:
| Situation | What the collage app does |
|---|---|
| No Northfield statement or reference in the response | Not an error. Ava may have declined to share it. No discount, and the card upload is offered instead. |
Unknown kid | Northfield may have started signing with a new key. Fetch Northfield's key set again, with the usual limit on how often, and verify again. |
| Northfield's key set cannot be fetched | The statement cannot be checked right now. No discount for the moment, with an offer to try again later. |
| Expired statement | Treated as missing. Ava can renew her student status with the photo service. |
| Endpoint not in the configuration | A change at the provider, or something worse. Do not call it. Treat the claim as missing and record the event. |
401 with WWW-Authenticate: Bearer error="invalid_token" | The endpoint rejected the credential, for example because it expired. No refresh is possible, because the collage app holds no refresh token for Northfield. Offer to confirm Ava's student status again through the photo service, which issues a new reference. |
| Timeout or server error from the endpoint | Northfield is down or slow. No discount for now. Let Ava finish the order without it, or try again shortly. |
| A valid JWT without the claim | Northfield declined to release it. No discount, as with any claim that was not returned. |
| Bad signature, unexpected issuer or audience, or JSON instead of a JWT | The statement was altered or forged, it is the wrong kind of JWT, or something is misconfigured. Reject it and record a security event. |
None of these rows signs Ava out or changes her account, and nothing falls back to the decoded value. The discount waits for a statement that passes every check. The collage app's log records the stage, the failed check or HTTPThe Hypertext Transfer Protocol, the rules browsers, apps, and servers use to send requests and responses on the web. status, the claims provider's issuer or the endpoint's host, the kid and a correlation ID that ties the entry to its request, never the access token or the JWT.
Asking as little as possible
Every fetch tells Northfield that the collage app asked about Ava, and when. Over many orders, those requests would build a record at the university of where she shops and how often, which she never meant to share. The collage app keeps that record small by asking only when the answer matters: once, when she chooses the discount, rather than at every sign-in or on every page.
It keeps what it learns small too. Once a statement passes, the verified result, that Northfield confirmed Ava's enrollment and when, is enough to price this order. A later order, or an embedded statement that has since expired, means a new question rather than a reused answer. The access token is discarded once it has been used, or when it expires, whichever comes first. If the collage company needs evidence for a later dispute about the discount, it keeps the signed JWT with the order. Otherwise it has no reason to keep it.
The photo service has a part to play as well. It includes a statement or reference only when Ava has agreed to share the claim with this relying party, and it asks Northfield for a token that works only briefly and only for this claim. As Combining claims from multiple sources showed, that limit has to live in the token, because nothing the collage app does afterward can narrow a broader one.
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
- Fetch and validate a claims statement without forwarding its credentialCheck Lab Photos' sign-in, call only the claims endpoint you approved, validate Lab Mail's signed statement against your own configuration, and handle an expired reference and a declined share without breaking sign-in.