Beta

Create a tenant

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

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 UserInfo 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 HTTPS, in answer to the collage app's own access token, and its sub matches the ID token. The discount now depends on Northfield's statement.

Decoding a JWT 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:

What the collage app trusts each party to answer
QuestionWho answers itHow the collage app checks
Which photo account signed in?The photo serviceThe 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 responseThe same checks. Northfield's JWT does not name Ava in the photo service's terms.
Is that person enrolled, and until when?NorthfieldNorthfield'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 Provider. The collage app fetched it from https://id.northfield.example/.well-known/openid-configuration, took the key set 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.

  1. Follow the reference from _claim_names to its source in _claim_sources. A JWT member is the statement. An endpoint member means fetching it first. A missing source, or one with neither member, means the claim is absent.
  2. Check the issuer before using any key. Read iss without 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.
  3. Verify the signature with a key from that issuer's configured key set, selected by kid, using the algorithm configured for that issuer. none fails here, and so does any key the JWT tries to bring with it.
  4. Check the time. exp must not have passed, and iat must 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.
  5. 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 token that Northfield issued to some other application is also signed with Northfield's key, may even contain the enrolled claim, and names that application in aud.
  6. Read only the claims that were named. The JWT must contain every claim that _claim_names points 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 token, 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 JSON 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.

The photo service supplies only the reference. The statement comes from Northfield, and the collage app checks both where it sends the token and what comes back.

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 party 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:

What the collage app does when Northfield's statement cannot be used
SituationWhat the collage app does
No Northfield statement or reference in the responseNot an error. Ava may have declined to share it. No discount, and the card upload is offered instead.
Unknown kidNorthfield 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 fetchedThe statement cannot be checked right now. No discount for the moment, with an offer to try again later.
Expired statementTreated as missing. Ava can renew her student status with the photo service.
Endpoint not in the configurationA 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 endpointNorthfield is down or slow. No discount for now. Let Ava finish the order without it, or try again shortly.
A valid JWT without the claimNorthfield 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 JWTThe 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 HTTP 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.

The ID token and UserInfo response check out, but the Northfield JWT inside the response has "alg": "none". What should the collage app do? 1 of 4

Choose one answer.

A validated UserInfo response points the collage app to the endpoint http://admin.internal.collage.example/claims, an address on its own network, with an access token. What should it do? 2 of 4

Choose one answer.

At checkout the collage app calls Northfield's approved claims endpoint over HTTPS with the token, and gets back a plain JSON body saying the enrolled claim is true. What should it do? 3 of 4

Choose one answer.

The mail service, which the collage app also offers for sign-in, starts adding Northfield enrollment statements to its UserInfo responses. Their Northfield signatures are valid. What should the collage app do? 4 of 4

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