Beta

Create a tenant

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

Following a token exchange

This lesson reads one token exchange message by message: the photo API's request for a storage token 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 token 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.read

The body is form-encoded, and its line breaks are for display. The Basic header represents photo-api:demo-only-not-a-real-secret. HTTP Basic keeps the example short; inside a platform, the photo API would more often authenticate with a workload identity or mutual TLS, 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 server 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 token, 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 authorization 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 OAuth 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 issuer 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.

The photo API exchanges the printer's token for one addressed to the storage service and uses only the new token there. The authorization server and the storage service each make their own checks.

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.read

The 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.

The token each service received
ServiceTokenAudience and scopeCurrent actor
Photo APIAhttps://api.photos.example, photos.readNone; the client is photo-printer
Storage serviceBhttps://storage.photos.example, storage.readphoto-api
Archive serviceChttps://archive.photos.example, archive.readphoto-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.

Two exchanges carry Ava's request from the photo API to the archive. Each service receives a token addressed only to it, and each exchange adds the new actor to the front of the chain.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

An exchange response has issued_token_type urn:ietf:params:oauth:token-type:access_token and token_type Bearer. What does each field tell the photo API? 1 of 3

Choose one answer.

Token C has an act claim naming photo-storage, with photo-api nested inside. Which actor should the archive service use in its access decision? 2 of 3

Choose one answer.

The storage service finds that photo-0311 has moved to the archive. What does it send in its own exchange request to get a token for the archive? 3 of 3

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