Following a token exchange
This lesson reads one 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. message by message: 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.'s request for a storage 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. while it serves Ava's album, the response, the new token and its use, then a second exchange the storage service makes for itself, with the nested act claim and shrinking lifetime a chain produces.
Sending the request
It is 09:02 UTC on 1 October. The printer asks the photo API for the photos in Ava's album 42, presenting the 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. it received at 09:00. The photo API validates the token, confirms the album is Ava's, and needs the first file from the storage service. It is registered as client photo-api, and the photo service's policy lets that client exchange tokens issued for the photo API for tokens to use at the storage service, the arrangement Delegation, impersonation, and actor tokens described. All domains, credentials, and tokens in these examples are fictional.
POST /token HTTP/1.1
Host: auth.photos.example
Authorization: Basic cGhvdG8tYXBpOmRlbW8tb25seS1ub3QtYS1yZWFsLXNlY3JldA==
Content-Type: application/x-www-form-urlencoded
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange
&subject_token=eyJhbGciOiJFUzI1NiIsImtpZCI6InBob3Rvcy0yMDI2LTA5IiwidHlwIjoiYXQrand0In0.eyJpc3Mi...
&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Aaccess_token
&requested_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Aaccess_token
&resource=https%3A%2F%2Fstorage.photos.example
&scope=storage.readThe body is form-encoded, and its line breaks are for display. The Basic header represents photo-api:demo-only-not-a-real-secret. HTTPThe Hypertext Transfer Protocol, the rules browsers, apps, and servers use to send requests and responses on the web. Basic keeps the example short; inside a platform, the photo API would more often authenticate with a workload identityAn identity that belongs to software that runs and acts without a person directing each request, such as a service, a scheduled job or a pipeline step. It names the logical workload, not one running copy, and each copy holds its own credential. or mutual TLSTransport Layer Security, the protection behind HTTPS. It encrypts traffic between two connected systems, detects changes on the way, and uses certificates so the client can confirm which server it reached., as Service-to-service access suggested.
grant_type selects token exchange. subject_token is the printer's token, shortened here, and subject_token_type says it is an access token from this server. requested_token_type asks for an access token in return; it is optional, and included to make the request explicit.
resource names where the new token will be used, as in Selecting the intended resource. scope names the access needed there, in the storage service's own terms. The storage service defines scopes such as storage.read for reading stored files, so the request does not ask for photos.read, which means something only at the photo API.
The 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. authenticates the photo API, validates the printer's token, and applies its exchange policy. Trust and validation sets out those checks in order.
Reading the response
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache
{
"access_token": "eyJhbGciOiJFUzI1NiIsImtpZCI6InBob3Rvcy0yMDI2LTA5IiwidHlwIjoiYXQrand0In0.eyJpc3Mi...",
"issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
"token_type": "Bearer",
"expires_in": 60
}The new token arrives in access_token, shortened here. The field keeps its familiar name so that token exchange fits the ordinary token response, but the token inside it does not have to be an access token.
Two fields describe the token, and they answer different questions. issued_token_type is required and says what was issued, using the same identifiers as the request: here, an access token. token_type is also required and says how to use the token at an API, in the same sense as in every other token response. Bearer means present it as it is.
expires_in is recommended rather than required, and gives one minute. scope is missing because the server issued exactly what was asked for; it may leave scope out only in that case, so its absence here means storage.read. There is no refresh tokenA longer-lived credential that a client sends to the authorization server, never to an API, to get new access tokens without asking the person again., which is usual when one short-lived credential is exchanged for another.
Some exchanges issue something that is not used at an API at all. Suppose the photo API asked for requested_token_type=urn:ietf:params:oauth:token-type:jwt, to present as an assertion at another 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, the way Lantern's portal presented one in JWT and SAML assertion grants. The response would then read:
{
"access_token": "eyJhbGciOiJFUzI1NiIs...",
"issued_token_type": "urn:ietf:params:oauth:token-type:jwt",
"token_type": "N_A",
"expires_in": 300
}N_A says that no 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. token type applies, because this token is not meant to be sent to an API.
Inside the new token
Decoded, the storage token reads:
Header:
{
"alg": "ES256",
"kid": "photos-2026-09",
"typ": "at+jwt"
}
Claims:
{
"iss": "https://auth.photos.example",
"sub": "user-2048",
"aud": "https://storage.photos.example",
"client_id": "photo-api",
"scope": "storage.read",
"iat": 1790845320,
"exp": 1790845380,
"jti": "demo-token-id-storage-1",
"act": {
"sub": "photo-api"
}
}Compare it with the printer's token. The 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. and subject are unchanged: the photo service issued it, and it concerns Ava, user-2048. The audience is now https://storage.photos.example, matching the resource the photo API named. client_id is photo-api, because that is the client that requested this token, and act records the photo API as the party acting for Ava. The scope is the storage service's, and the token lives from 09:02:00 to 09:03:00 UTC.
The same key, photos-2026-09, signed it, and its typ is still at+jwt. To the storage service it is an ordinary access token from the photo service, validated in the ordinary way.
Using the new token
GET /objects/photo-1187 HTTP/1.1
Host: storage.photos.example
Authorization: Bearer eyJhbGciOiJFUzI1NiIsImtpZCI6InBob3Rvcy0yMDI2LTA5IiwidHlwIjoiYXQrand0In0.eyJpc3Mi...The storage service validates the token, checks that storage.read covers the request, confirms that photo-1187 belongs to user-2048, and sees that the actor is the photo API, a caller it expects. It returns the file.
As Service-to-service access noted, the photo API can keep the storage token for its short life and reuse it for the album's other files. The cache needs one rule above all: an exchanged token is about one person, so it must be keyed by subject as well as audience, and never used for a request on behalf of someone else.
The exchange also leaves the printer's token as it was. Exchanging a token does not use it up, unless its type is defined to be single-use, so the printer's token stays valid at the photo API until 09:10. Nor are the two tokens linked afterwards by the specification. If the printer's token were revoked at 09:02:30, the storage token would not stop working on its own unless the deployment deliberately carries revocation across. Its one-minute lifetime keeps that gap short.
The second exchange
Most of album 42 sits in the storage service. One photo, photo-0311, was taken in 2019 and Ava has not opened it in years, so its original has moved to the archive service at https://archive.photos.example. When the photo API asks for it with the storage token, the storage service validates the token, confirms that the photo belongs to user-2048 and that the actor is the photo API, and finds only a note saying the original is in the archive.
To keep the tokens apart, call the printer's token A and the storage token B. Now the storage service stands where the photo API stood. It holds a token issued for it, token B, and needs a token for another service. It is registered as client photo-storage, and the photo service's policy lets that client exchange a token carrying storage.read for archive.read at the archive. At 09:02:01 it sends:
POST /token HTTP/1.1
Host: auth.photos.example
Authorization: Basic cGhvdG8tc3RvcmFnZTpkZW1vLW9ubHktbm90LWEtcmVhbC1zZWNyZXQ=
Content-Type: application/x-www-form-urlencoded
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange
&subject_token=eyJhbGciOiJFUzI1NiIsImtpZCI6InBob3Rvcy0yMDI2LTA5IiwidHlwIjoiYXQrand0In0.eyJpc3Mi...
&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Aaccess_token
&resource=https%3A%2F%2Farchive.photos.example
&scope=archive.readThe subject token is token B, shortened, and the Basic header represents photo-storage:demo-only-not-a-real-secret. The authorization server checks that photo-storage may exchange tokens, that token B was issued for the storage service and is still valid, that archive.read follows from storage.read, and that the archive is a target this client may reach. It returns token C, with the same header as token B and an expires_in of 59. Its claims read:
{
"iss": "https://auth.photos.example",
"sub": "user-2048",
"aud": "https://archive.photos.example",
"client_id": "photo-storage",
"scope": "archive.read",
"iat": 1790845321,
"exp": 1790845380,
"jti": "demo-token-id-archive-1",
"act": {
"sub": "photo-storage",
"act": {
"sub": "photo-api"
}
}
}The act claim now has two levels. The outer one names photo-storage, the current actor. Inside it, photo-api appears as the earlier actor. Read from the outside in, it is a history: the storage service is acting for Ava now, and before it, the photo API was.
The expiry repays a closer look. A full minute from 09:02:01 would end at 09:03:01, but token B expires at 09:03:00, and the photo service never lets a token outlive its subject token, a rule Trust and validation explains. So token C ends at 09:03:00 as well, and expires_in is 59 seconds. No token in the chain can outlast the one before it, though each may end sooner.
A server can also limit how long a chain may grow. Each hop adds a level to act, and a deployment that expects at most two hops can refuse a third exchange, so that a loop between services, or a compromised service relaying tokens onward, stops at a known depth instead of producing ever longer tokens.
What each service decided
The archive validates token C like any access token, then decides, considering only the top-level claims and the current actor. archive.read covers the request, photo-0311 belongs to user-2048, and the current actor is photo-storage, the only caller the archive expects. photo-api, nested inside, goes into the archive's log and plays no part in the decision. The archive returns the original, the storage service passes it to the photo API, and the photo API includes it in the album for the printer.
| Service | Token | Audience and scope | Current actor |
|---|---|---|---|
| Photo API | A | https://api.photos.example, photos.read | None; the client is photo-printer |
| Storage service | B | https://storage.photos.example, storage.read | photo-api |
| Archive service | C | https://archive.photos.example, archive.read | photo-storage |
The subject never changed: every service made its decision about user-2048. Everything else shifted at each hop. The audience moved to the next service, the scope moved into that service's vocabulary, the lifetime shrank to a minute or less, and the actor became whoever was holding the token.
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
- Send a token exchange field by field, then follow Ava's request through a second hopSend the lesson's exchange request, read the response and the new token, reuse and revoke the subject token, and carry Ava's request on to an archive with a second exchange and a nested act chain.