Token exchange (RFC 8693): delegation and impersonation done right
A user calls your API gateway with an access token scoped for the gateway. The gateway needs to call a downstream billing service on the user's behalf. What token does it present? If you forward the original token, billing now accepts a token minted for someone else's audience and sees the gateway's full scope. If you mint a fresh token from a shared service account, you have erased the user's identity and billing can no longer enforce per-user authorization. Both are common, and both are wrong.
RFC 8693 defines a grant type for exactly this seam: urn:ietf:params:oauth:grant-type:token-exchange. It lets a service present one token and receive another — usually with a narrower scope, a different audience, and a clear record of who is acting for whom. It is the clean, auditable way to do delegation and impersonation between services.
Delegation versus impersonation
These words get used interchangeably and they are not the same, which matters the moment someone reads an audit log.
Impersonation means the downstream service sees only the user. The acting service disappears; the token looks as though the user requested it directly. This is simple but it destroys information — you cannot later answer "which service performed this action on the user's behalf."
Delegation keeps both identities. The token's sub is still the user, but an act (actor) claim records the service acting for them. RFC 8693 defines this claim explicitly, and it can nest: service A acting for service B acting for the user produces a chain of act claims.
{
"sub": "user-4821",
"aud": "https://billing.example.com",
"scope": "invoices:read",
"act": {
"sub": "svc-gateway",
"act": {
"sub": "svc-edge"
}
}
}Read that bottom-up: the edge service called the gateway, the gateway called billing, and all of it was on behalf of user-4821. Billing can authorize against the user while logging the full actor chain. That is the difference between a forensics investigation that takes an afternoon and one that takes a week.
The request
A token exchange is a POST to the token endpoint. The required parameters are the grant type and the subject_token — the token representing the party on whose behalf the request is made — plus its type.
POST /token HTTP/1.1
Host: auth.example.com
Content-Type: application/x-www-form-urlencoded
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
&subject_token=eyJhbGciOiJSUzI1NiIs...
&subject_token_type=urn:ietf:params:oauth:token-type:access_token
&resource=https://billing.example.com
&scope=invoices:read
&audience=billing-apiThe authorization server validates the subject token, checks that this client is permitted to exchange it for the requested audience and scope, and returns a new token narrowed accordingly.
Narrowing, not widening
The cardinal rule: an exchange should only ever reduce privilege. A token good for ten scopes across five audiences goes in; a token good for one scope at one audience comes out. If your authorization server will issue a broader token than the subject token carried, you have built a privilege escalation primitive, not a delegation mechanism.
scope=* for every audience it can name. The server is the only component that can refuse, because it is the only one that cannot be talked out of the policy by the attacker who owns the caller.The actor token: proving who is asking
For delegation you often supply a second token, the actor_token, identifying the service making the request. The subject token says "this is for user-4821"; the actor token says "and I, svc-gateway, am the one asking." The server verifies both and stamps the act claim from the actor token's subject.
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
&subject_token=<user-token>
&subject_token_type=urn:ietf:params:oauth:token-type:access_token
&actor_token=<service-token>
&actor_token_type=urn:ietf:params:oauth:token-type:access_token
&audience=billing-apiWithout an actor token you get impersonation; with one you get delegation. Choosing between them is a policy decision per downstream service, and it should be explicit in your authorization server configuration rather than an accident of which parameters a caller happened to send.
Where token exchange fits
Three patterns come up repeatedly:
- API gateways and BFFs. A gateway holds a broad session token and exchanges it for a narrow, audience-scoped token per downstream call. A leaked downstream token unlocks one service, not the whole session.
- Service meshes. A workload presents its platform identity (a SPIFFE SVID, a Kubernetes service account token) as the subject token and receives an application-level access token. This bridges infrastructure identity to application authorization without embedding long-lived secrets in pods.
- Cross-domain trust. A token from one trust domain is exchanged for a token in another, with the authorization server enforcing exactly which external issuers it will accept and what it will mint in return.
Token type URNs
RFC 8693 is not limited to access tokens. The subject_token_type can be an access token, a refresh token, an ID token, a SAML assertion, or a JWT. This is what makes it a bridge: you can present a SAML assertion from a legacy IdP and receive a modern OAuth access token, keeping the translation logic in one audited place.
What to audit
When you adopt token exchange, the two questions a reviewer should be able to answer from configuration alone are: which clients may exchange for which audiences, and whether each exchange is delegation or impersonation. If those answers live in code scattered across services, you have the mechanism without the governance. Centralize the exchange policy where the tokens are minted.
Token exchange is one of those specs that looks like plumbing and turns out to be load-bearing for anything with more than two services. Getting the act chain right is what lets you answer "who did this, and on whose behalf" months later — and that clarity is far easier to guarantee when the authorization server minting every token in the chain is one you run yourself, with policy you can read and change. For the request-level mechanics of scoping tokens to a single API, resource indicators (covered separately) are the natural companion.
Run it yourself
Bastionary is free, open-source software. Follow the quick start to have it running on your own server, or browse the releases on Git.