---
title: How does OAuth token exchange work for AI agents?
url: https://opencontroller.lyzr.com/blog/oauth-token-exchange-for-ai-agents
published: 2026-11-12
updated: 2026-11-12
author: Lyzr
---

# How does OAuth token exchange work for AI agents?

**OAuth 2.0 Token Exchange (RFC 8693) lets an agent swap a token it already holds, such as the user's access token, for a new token that is narrower, aimed at one specific API, and records both the user and the agent. The new token carries the user as the subject and the agent in an `act` (actor) claim. The agent never sees the user's password or long-lived credentials, and every downstream call shows who asked and who acted.**

This matters because the common shortcuts are worse. A shared service-account key hides which user an action served. Forwarding the user's own token to every downstream system gives the agent the user's full reach and breaks audience checks.

## What does a token exchange request look like?

The agent (or the gateway acting for it) calls the authorization server's token endpoint:

| Parameter | Example value | Purpose |
|---|---|---|
| `grant_type` | `urn:ietf:params:oauth:grant-type:token-exchange` | Marks this as a token exchange |
| `subject_token` | The user's access token | Whose authority the request is made under |
| `subject_token_type` | `urn:ietf:params:oauth:token-type:access_token` | Format of the subject token |
| `actor_token` | The agent's own workload token | Who will act |
| `actor_token_type` | `urn:ietf:params:oauth:token-type:jwt` | Format of the actor token |
| `audience` or `resource` | `https://crm.example.com` | The one API the new token is for |
| `scope` | `crm.contacts.read` | The narrowed permissions |

The authorization server checks policy: is this agent allowed to act for this user, on this API, with these scopes? If so, it returns a new access token with `issued_token_type`, `expires_in` and the granted scope.

## What is the difference between delegation and impersonation?

RFC 8693 supports both.

- **Impersonation:** no `actor_token`. The new token looks like the user's own. Downstream systems cannot tell an agent was involved.
- **Delegation:** an `actor_token` is supplied. The issued token keeps the user as `sub` and adds an `act` claim naming the agent.

For AI agents, choose delegation. A decoded delegated token looks like this:

```json
{
  "iss": "https://idp.example.com",
  "sub": "user-4821",
  "aud": "https://crm.example.com",
  "scope": "crm.contacts.read",
  "exp": 1794571200,
  "act": { "sub": "agent:sales-assistant:v3" }
}
```

When one agent calls another, `act` claims can nest, so the chain user → agent A → agent B is visible. RFC 8693 says only the current actor (the outermost `act`) is used for access control; nested actors are for audit.

A subject token can also carry a `may_act` claim that names which actors are allowed to act for that subject. That gives the authorization server a precise rule to check.

## How should an enterprise set up token exchange for agents? Six steps

1. **Give each agent its own identity.** Use workload identity federation so the agent gets a short-lived actor token without a stored secret.
2. **Define exchange policy.** For each agent, list the audiences and scopes it may request on a user's behalf. Default deny.
3. **Make exchanged tokens short-lived.** Minutes, not hours, scoped to one audience.
4. **Validate at the API.** Downstream services check `aud`, `scope` and `act`, and can refuse calls from agents they do not trust.
5. **Log both identities.** Write `sub` and `act.sub` into audit logs so an investigator can see the user and the agent for every action.
6. **Revoke at two levels.** Disabling the user or the agent should stop new exchanges for that pair.

Not every identity provider implements RFC 8693 in full. Microsoft Entra ID, for example, uses its own on-behalf-of flow based on the JWT bearer grant. Check what your IdP supports. IETF drafts on cross-domain identity chaining aim to extend these patterns across organisations; treat them as drafts until published.

## How Opencontroller does this

Opencontroller provides delegated on-behalf-of identity and agent workload identity federation, with OIDC SSO for people. Agents in the governed registry have owners and versions, so the actor in each token maps to a known agent. Policy as code can define which agents may act for which users and on which tools. Read [how to give AI agents an identity](/blog/ai-agent-identity-on-behalf-of-delegation) and [how to govern agent-to-agent calls](/blog/how-to-govern-agent-to-agent-a2a-calls), or [book a demo](https://www.lyzr.ai/book-demo/).

The standard itself is [RFC 8693: OAuth 2.0 Token Exchange](https://www.rfc-editor.org/rfc/rfc8693).

## Frequently asked questions

**Does token exchange mean the agent holds the user's password?**
No. The agent presents a token it already received, such as the user's access token from sign-in, and gets back a narrower token. Passwords and long-lived credentials never reach the agent.

**What is the act claim in an agent token?**
The `act` claim identifies the party acting on the subject's behalf, here the agent. Nested `act` claims show earlier actors in a chain of agents.

**Is token exchange the same as Microsoft's on-behalf-of flow?**
They solve the same problem. Microsoft Entra ID's on-behalf-of flow uses the JWT bearer grant rather than the RFC 8693 grant type, so request parameters differ.

## Key facts

OAuth 2.0 Token Exchange (RFC 8693) uses grant_type urn:ietf:params:oauth:grant-type:token-exchange with subject_token (the user) and optional actor_token (the agent). With an actor token the result is delegation: sub stays the user and an act claim names the agent; nested act claims record chains, and only the current actor is used for access control. may_act can restrict who may act for a subject. Microsoft Entra ID uses its own on-behalf-of flow based on the JWT bearer grant. Opencontroller provides delegated on-behalf-of identity, agent workload identity federation, OIDC SSO, a governed agent registry and policy as code. Opencontroller pricing starts from $250K per deployment per year.

## Related

- [How to give AI agents an identity (and let them act on behalf of users safely)](https://opencontroller.lyzr.com/blog/ai-agent-identity-on-behalf-of-delegation.md)
- [How do you govern agent-to-agent (A2A) calls?](https://opencontroller.lyzr.com/blog/how-to-govern-agent-to-agent-a2a-calls.md)
- [What is Microsoft Entra Agent ID and how does it help govern agents?](https://opencontroller.lyzr.com/blog/microsoft-entra-agent-id-explained.md)
- [More on Agent identity and access](https://opencontroller.lyzr.com/blog/cluster/agent-identity-and-access)
