iamops.dev
Argo on X RSS feed
ENEnglish

Knowledge Deep dive · 8 min

OAuth token exchange (RFC 8693) for AI agents: delegation, impersonation and the act claim

How RFC 8693 token exchange works when an AI agent acts for a user: delegation versus impersonation, the act and may_act claims, and what to check first.

Two panels compare what an API sees. On the left, impersonation: the token names only the user and the agent is invisible. On the right, delegation: the token names the user as sub and the agent in the act claim. Below: only the outermost act is the current actor.
TL;DRRFC 8693 swaps one token for another at the token endpoint. Only…
  • RFC 8693 swaps one token for another at the token endpoint. Only subject_token and its type are required; the Keycloak lab shows a full request.
  • With impersonation the API cannot tell the agent from the user. With delegation the token carries both, and the agent sits in the act claim.
  • In a nested act chain only the outermost actor counts for access decisions. The others are history, so log them and do not authorize on them.
  • ID-JAG, transaction tokens and MCP servers all lean on this grant. Entra OBO does the same job with a different grant type.
  • Before trusting a provider, run the checks: who may exchange, which audiences, whether refresh tokens come back, and whether act appears at all.

An AI agent that calls an API for a user should not forward the user’s token. The usual answer is token exchange: the agent, or the MCP server behind it, hands the token to the authorization server and gets back a new one that is narrower and aimed at one API. RFC 8693 defines that grant. It was published in January 2020, long before anyone called a chatbot an agent, and it already had the words this problem needs: delegation, impersonation and actor.

This article is the reference I keep coming back to when I run token exchange labs. It covers the request, the two semantics, the claims that carry them and where the grant now turns up.

What one exchange request carries#

A token exchange is a normal call to the token endpoint with the grant type urn:ietf:params:oauth:grant-type:token-exchange. The parameters:

Parameter Required What it says
subject_token, subject_token_type Yes The party on whose behalf the new token is requested
actor_token, actor_token_type No The party that will act
resource No Absolute URI of where the token will be used, no fragment
audience No Logical name of the target, such as a client ID
scope No The scopes wanted for the new token
requested_token_type No Access token, JWT, ID token, SAML and so on, as a URN

The response names what came back in issued_token_type. How the client authenticates, and whether unauthenticated clients may exchange at all, are left to the deployment. In practice that decision is the whole security model: in my Keycloak lab only one client had the exchange privilege, and a client without it was refused.

resource and audience can both be repeated, so one exchange can ask for a token valid at several targets. For agents I would not do that. One exchange per downstream API keeps each token useless anywhere else.

Delegation or impersonation#

Section 1.1 of the RFC defines the two semantics, and the difference is what an AI agent deployment should decide first.

  • Impersonation. A is given B’s rights within some context and is indistinguishable from B there. The receiving API thinks it is dealing with B. Some parts of the system may know otherwise, but the token does not have to say so.
  • Delegation. A keeps its own identity. The token says that A is acting for B. The RFC puts it plainly: “In a sense, A is an agent for B.”

A delegation token is sometimes called a composite token, because it carries information about two parties. Whether the server issues one is up to its policy and configuration. That matters, because most people asking for “token exchange” in a product get impersonation by default. In my Keycloak 26.8.2 lab the exchanged token kept the user as subject, named the MCP server only as the authorized party (azp) and had no act claim. Keycloak’s delegation support was a preview feature, switched off.

For an agent, impersonation means the API cannot tell whether the user clicked or the agent decided. Both get the same rights and the same log line. Delegation is what you want for audit and for policies such as “agents may read invoices but not pay them”.

Two panels compare what an API sees. On the left, impersonation: the token names only the user and the agent is invisible. On the right, delegation: the token names the user as sub and the agent in the act claim. Below: only the outermost act is the current actor.
Same exchange, two results. With impersonation the API sees the user only. With delegation it sees the user and the acting agent, and can write a policy for each.

Reading the act claim#

Delegation is expressed with the act claim. Its value is an object that identifies the actor, usually with sub and sometimes iss. A chain of delegation nests one act inside another. A trimmed example of what a payments API might receive after two hops:

json
{
  "iss": "https://as.example.com",
  "aud": "https://payments.example.com",
  "sub": "user-4821",
  "scope": "invoices.read",
  "act": {
    "sub": "https://mcp.example.com",
    "act": { "sub": "https://agent.example.com" }
  }
}

The rules from section 4.1 are short and easy to get wrong:

  • The outermost act is the current actor, here the MCP server. The most deeply nested one is the oldest.
  • Prior actors “are informational only and are not to be considered in access control decisions.”
  • act inside an introspection response has the same meaning as in a JWT.

So a policy that says “allow if any actor in the chain is the trusted agent” is wrong by the spec. Authorize on the current actor and the subject. Log the whole chain, because the history is what an incident review will ask for.

may_act decides who may become the actor#

The may_act claim travels in the subject token and says in advance who is allowed to act for the subject. The authorization server can use it to decide whether the client, or the party in actor_token, may perform the requested delegation or impersonation. Claims such as exp and aud inside may_act have no meaning; it only identifies a party.

It is useful because it moves the decision to the issuer of the original token. It is not a guarantee that the server checks it. In my downscoping lab I could not isolate whether Keycloak compared the actor with may_act, so I treat it as a hint the server may honour and test the refusal myself.

Narrowing: audience, scope and lifetime#

The security considerations of RFC 8693 are a single paragraph. It suggests the scope claim and a limited lifetime to contain abuse of delegated rights. Everything else is left to the server, and servers differ:

  • Scope does not follow the subject token by default everywhere. In my A2A lab the exchanged token’s scope followed the acting client’s own scopes, so agent B received a write right that A never granted. One client policy fixed it. Test this in your provider.
  • Refresh tokens should not come back. My Keycloak lab refused a refresh token in a standard exchange. A refresh token in an agent’s hands turns a five-minute grant into a standing one.
  • Short lifetime. The exchanged token in my run lived 300 seconds.
  • Binding. An exchanged token is still a bearer token unless it is bound to a key. DPoP is the usual way to bind it.

Where token exchange shows up now#

  • MCP servers. The 2026-07-28 revision of the MCP specification says servers “MUST only accept tokens that are valid for use with their own resources” and “MUST NOT accept or transit any other tokens”. An MCP server that needs a downstream API therefore exchanges per API. My no-passthrough lab shows the refusal when it does not.
  • ID-JAG and Cross App Access. The client asks its identity provider for an Identity Assertion JWT with a token exchange whose requested_token_type is urn:ietf:params:oauth:token-type:id-jag, then presents it to the other application’s authorization server. Draft -06 is dated 31 October 2026. The ID-JAG explainer walks through the flow without the jargon.
  • Transaction tokens. The OAuth WG draft (-11, 30 July 2026) uses token exchange with the type urn:ietf:params:oauth:token-type:txn_token to turn an external token into a short-lived token that travels inside one trust domain. My IETF 127 notes cover the newer cross-boundary work.
  • Microsoft Entra on-behalf-of. OBO solves the same problem with a different grant: the middle tier calls the token endpoint with the JWT bearer grant and requested_token_use=on_behalf_of. It is not an RFC 8693 request, and the result does not keep the original client, as my OBO lab found.
  • More providers. Amazon Cognito and WorkOS Connect both added RFC 8693 in November 2026, as noted in my Keycloak lab.

What I check before trusting an implementation#

  1. Which clients may exchange at all, and whether that is a per-client switch.
  2. Whether an exchange for an audience the client has no right to is refused.
  3. Whether the new token’s scope is bounded by the subject token, not by the acting client.
  4. Whether a refresh token can come back.
  5. Whether act appears, and whether it can be required. If not, plan to log the join of user, agent and audience yourself.
  6. What the downstream API checks: audience, current actor and scope per operation.

What I did not check#

This article draws on the RFC, the drafts named above and my earlier labs. I did not run a new lab for it, did not test delegation with act in any provider and did not compare Cognito or WorkOS behaviour. A plain-language explainer on token exchange is on the backlog.

Sources#

Discuss this on X or LinkedIn

Follow on X

New posts by email

One email a week with new posts and labs. Unsubscribe anytime.

Your address is stored with Kit, which sends the emails. Details

Related posts and labs