Trust and validation
A 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. that exchanged any token it was shown would let anyone with a stolen token turn it into tokens for services it was never meant to reach. This lesson works through what the photo service's authorization serverIn OAuth, the service that handles a person's sign-in and approval and decides which tokens to issue to a client. It may belong to the same company as the API, but its job is separate. checks before it exchanges Ava's token, from which clients may exchange at all to the lifetime of the result, and then what the storage service checks on the token it receives.
Who may exchange
The exchanges in Scopes, resources, and audiences were refused for their target or scope. Earlier checks decide whether a request gets that far. The specification leaves the trust model to each deployment, so these checks belong to the 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. server's own policy.
Client authenticationChecking evidence that someone, or some application, controls an account, such as a password or a passkey. It establishes which account is being used, not what that account may do. comes first. The specification lets each server decide whether to accept exchanges from unauthenticated clients, and warns of the cost: without client authentication, anyone who obtains a token can use the token service to turn it into other tokens. The photo service requires authentication, and permits the token exchangeAn OAuth grant, RFC 8693, in which a client trades a token it holds for a new one, usually for another audience, with narrower access, or acting for someone. It lets a service call the next service without passing the original token along. grant only for clients registered to use it. photo-api is one. The printer is not, so if it sent the same exchange with its own perfectly valid token, the server would refuse with unauthorized_client.
The subject token must also belong with the client presenting it. The printer's token for Ava was issued for the photo APIAn application programming interface: a defined way for software to interact with a service. A web API offers endpoints where other programs send HTTP requests., so the photo service accepts it as a subject token only from photo-api, the client registered for that API. Without this check, a client allowed to exchange tokens for one purpose could exchange any token that reached it. The storage service, which exchanges tokens of its own as photo-storage, could take a photo API token that a caller sent it by mistake and swap it for access its real recipient never asked for. Where a subject token carries may_act, the server compares it with the client or the actor token as well.
The printer, with its own token
- Authenticated
- Yes
- Allowed the grant
- No
- Token for its API
- Not reached
unauthorized_client
Storage, with a token sent by mistake
- Authenticated
- Yes
- Allowed the grant
- Yes
- Token for its API
- No: the photo API
Refused
The photo API
- Authenticated
- Yes
- Allowed the grant
- Yes
- Token for its API
- Yes
New token issued
Without this check, a client allowed to exchange tokens for one purpose could exchange any token that reached it.
All identifiers in this example are fictional. The photo service keeps these decisions in an exchange policy for each client, much as it keeps a registration:
Client: photo-api
Grant types: urn:ietf:params:oauth:grant-type:token-exchange
Subject tokens accepted: access tokens from https://auth.photos.example
whose audience is https://api.photos.example
Targets: https://storage.photos.example
Scope mapping: photos.read to storage.read, photos.delete to storage.delete
Actor: record this client in act (delegation)
Lifetime: 60 seconds, never past the subject token's expiryEach line becomes a check, and anything the policy does not mention is refused.
Validating an exchange request
With the client authenticated and permitted to exchange, the authorization server works through the request:
- Read the subject token by its type. Refuse a type this client may not present, or a token that does not parse as the type claimed.
- Validate it as its type requires. For its 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., the photo service checks the 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. with its own key, that the token has not expired or been revoked, and that its audience is the API registered as the client presenting it. A token from another 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. needs a trust arrangement set up in advance, exactly as for assertion grants: which issuers, which keys, and which subjects each may speak for.
- Validate any actor token the same way, and check that this actor may act for this subject, through
may_actor the server's own policy, such as an agent's current role. - Check the target. This client must be allowed to obtain tokens for the named resource or audience.
- Work out the scope. It must be no more than the policy maps from the subject token's scope, no more than was requested, and no more than the subject's own rights allow.
- Set the lifetime. Short, and never later than the subject token's own expiry.
- Decide how to record the actor, as delegationLetting an application do a limited task with someone else's authority, such as a printing service reading your photos, without giving it your password. OAuth 2.0 is the usual framework for arranging it. or impersonation, according to the policy for this client and target.
- Record the exchange, linking the subject token's identifier to the new token's.
The lifetime rule is the photo service's own. As Following a token exchange showed, the specification treats an exchange as a one-time event that leaves the two tokens unlinked, and it allows, without requiring, the old token's expiry to influence the new one's. The photo service turns that allowance into a rule and never lets an exchanged token outlive its subject token. Otherwise a chain of exchanges could keep Ava's authority alive after the printer's own token had expired.
The same principle covers authentication details. If the printer's token recorded when and how Ava signed in, through claims such as auth_time and acr, the 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. access token profile says tokens derived from it, including by exchange, keep the original values. An exchange must not make a sign-in look more recent or stronger than it was. The specification also says deployments should put only the data the recipient needs into issued tokens, which can mean no more than a pseudonymous identifier for the person.
What the downstream API checks
The storage service receives an ordinary access token and validates it in the ordinary way, following the steps in Token formats and validation: an allowed algorithm, a typ of at+jwt, a signature from the photo service's 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., the exact issuer, its own audience, and expiry. A token that came out of an exchange deserves no more trust than any other. Then storage makes its own decision:
- The scope covers the operation, here
storage.readto read a file. - The object belongs to the subject.
photo-1187must be one ofuser-2048's files, or shared with that account. The storage service takes the subject from the validated token, never from a path or header the photo API supplies. - The actor is one it expects. The storage service accepts delegation tokens only when the current actor is
photo-api. A token about Ava with any other actor is refused, even with the right scope.
On which claims count, the specification is explicit. For access control, a recipient must consider only the token's top-level claims and the current actor, the party named in the outermost act. Earlier actors nested inside are informational: they belong in logs and investigations, not in access decisions.
The storage token is still a bearer token, and anyone who copied it during its minute could use it. Inside a platform, the tokens from Certificate-bound access tokens can tie it to the photo API's certificate, so that a copy is useless anywhere else. That binding is one more choice the authorization server can make at the moment of exchange, beside audience, scope and lifetime.
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
- Decide who may exchange which token, and what storage checks afterwardsMeet each check your tenant makes before an exchange: the client, the grant, the subject token, the lifetime and sign-in details. Then see what storage decides on the token it receives.