---
title: "Delegated User Authorization (OAuth Token Exchange)"
summary: "Exchanges the user's token and the agent's own identity for a short-lived, single-audience, minimally scoped token immediately before each tool call, so that the agent acts with delegated and attributable authority instead of a shared super-credential"
status: "production"
category: "Security & Safety"
url: "https://agentic-patterns.com/patterns/delegated-user-auth-token-exchange"
source: "https://datatracker.ietf.org/doc/html/rfc8693"
authors: ["Nikola Balic (@nibzard)"]
tags: ["oauth","token-exchange","delegation","least-privilege","on-behalf-of","audit-attribution","multi-tenant","identity"]
signals: ["A multi-tenant agent calls APIs on behalf of the signed-in user","The user's token is valid at more services, or with more scope, than the agent needs for one call","Audit logs must separate actions that the agent took from actions that the user took directly","A shared service account or admin API key is the only alternative"]
anti_signals: ["The tool needs no user-specific authority; the agent's own service identity is sufficient","The authorization server does not support the token exchange grant","One user runs a local agent with their own credentials; use a local credential broker instead"]
updated_at: "2026-11-25"
---

# Delegated User Authorization (OAuth Token Exchange)

> Exchanges the user's token and the agent's own identity for a short-lived, single-audience, minimally scoped token immediately before each tool call, so that the agent acts with delegated and attributable authority instead of a shared super-credential

## Use when

- A multi-tenant agent calls APIs on behalf of the signed-in user
- The user's token is valid at more services, or with more scope, than the agent needs for one call
- Audit logs must separate actions that the agent took from actions that the user took directly
- A shared service account or admin API key is the only alternative

## Avoid when

- The tool needs no user-specific authority; the agent's own service identity is sufficient
- The authorization server does not support the token exchange grant
- One user runs a local agent with their own credentials; use a local credential broker instead

## Problem

An enterprise agent that acts for a signed-in user has two common ways to authenticate a tool call. Both are defective.

- **A shared service account or admin key.** The agent calls APIs with its own broad privilege. The API cannot apply the permissions of the user, because it never learns who asked. A prompt injection then spends the full privilege of the agent. This is the confused-deputy problem: the deputy has more privilege than the user and cannot tell a real request from an injected one.
- **Token passthrough.** The agent forwards the access token of the user to each tool. That token is valid for every audience and scope that it was issued for. A third-party tool server (for example an MCP server) that receives the token can read it, and a broadly valid token can be replayed at other services.

The result is excess privilege in one direction and token leakage in the other. The audit trail is weak also: it records a service, not the pair of human and agent.

## Solution

Put a **token broker** between the agent and its tools. The broker is code that the LLM cannot change, typically the orchestrator or a [Policy-Gated Tool Proxy](policy-gated-tool-proxy.md). Immediately before each tool call, the broker makes an OAuth 2.0 Token Exchange request (RFC 8693), often called an on-behalf-of (OBO) exchange:

- It presents the token of the user as `subject_token` and a token for the agent as `actor_token`.
- It names one target with `resource` or `audience`, and it requests only the scope that this one call needs.
- The authorization server returns a **short-lived token for one audience** with a narrowed scope. The token carries the user as `sub` and the agent as `act`, so the API and its logs can see the delegation.

This is delegation, not impersonation. RFC 8693 describes the actor as "an agent for" the subject, with an identity that stays separate.

```mermaid
sequenceDiagram
    participant U as User
    participant A as Agent orchestrator
    participant B as Token broker
    participant S as Authorization server
    participant R as CRM API
    U->>A: Request plus user token
    A->>B: Call needs contacts.read on the CRM API
    B->>S: Exchange subject_token and actor_token for resource plus scope
    S-->>B: Short-lived CRM token with sub and act
    B->>R: Call with the exchanged token
    R-->>B: Result
    B-->>A: Result
```

```http
POST /token HTTP/1.1
Host: auth.example.com
Content-Type: application/x-www-form-urlencoded
Authorization: Basic <agent-client-credentials>

grant_type=urn:ietf:params:oauth:grant-type:token-exchange
&subject_token=<user-access-token>
&subject_token_type=urn:ietf:params:oauth:token-type:access_token
&actor_token=<agent-own-credential>
&actor_token_type=urn:ietf:params:oauth:token-type:access_token
&resource=https://crm.example.com/api
&scope=contacts.read

# The issued access token, decoded, names both identities:
{
  "aud": "https://crm.example.com/api",
  "iss": "https://auth.example.com",
  "sub": "user-7f3a",
  "scope": "contacts.read",
  "act": { "sub": "agent-billing-assistant" }
}
```

The API that receives the call authorizes on both identities. It uses `sub` for what the user may do and `act` for who is doing it. A second hop adds a nested `act` claim, which gives a chain of delegation.

In a durable or background workflow, the exchange occurs inside each retryable step. The broker never stores a master token in workflow state (see [Durable Execution & Step Checkpointing](durable-execution-step-checkpointing.md)).

## Evidence

- **Evidence Grade:** `high` (an IETF Standards Track specification and an IETF Best Current Practice)
- **Most Valuable Findings:**
  - RFC 8693 defines the `urn:ietf:params:oauth:grant-type:token-exchange` grant. It describes a resource server that trades a received token "for a new token that is appropriate to include in a call to a backend service", possibly one "more narrowly scoped for the downstream service". It separates delegation from impersonation and defines the `act` claim for a chain of delegation.
  - RFC 9700 states that access token privileges "SHOULD be restricted to the minimum required" and that tokens "SHOULD be audience-restricted to a specific resource server". The resource server must verify the audience on every request.
  - RFC 9700 names the counterfeit resource server and the compromised resource server as leakage paths. It recommends sender-constrained tokens and audience restriction as countermeasures.
  - The [OAuth.net overview](https://oauth.net/2/token-exchange/) lists "a backend service acting on behalf of the original user when calling downstream services" as a primary use of token exchange.
- **Unverified / Unclear:** RFC 8693 sets no requirements on the trust model or the token syntax, and it leaves composite-token issuance to authorization-server policy. How an MCP deployment binds to token exchange is deployment-specific. No public data counts confused-deputy incidents in agents.

## How to use it

1. **Register the agent as its own OAuth client.** Authenticate it at the token endpoint, and present a token that represents the agent as the `actor_token`. RFC 8693 warns that without client authentication, anyone who holds a compromised token can exchange it for other tokens.
2. **Fix the target of each tool in a server-side registry.** Send as `resource` the URL that the call will actually go to. Do not let the model select the resource or the audience.
3. **Request one audience and the least scope.** RFC 8693 defines the requested rights as the product of all scopes at all target services, so each extra target increases what a leak can reach.
4. **Let authorization-server policy decide.** The server can narrow the scope, refuse a target with `invalid_target`, or decline to add an `act` claim. Configure it to issue the composite tokens that your APIs expect.
5. **Authorize and log on both identities.** The API validates the audience, the scope, and the expiry. It applies the permissions of the user to `sub`, and it records `sub` and `act` with each action.
6. **Exchange inside each step of a durable run.** Treat an expired subject token as a distinct "re-consent required" result, not as an error to retry.
7. **Sender-constrain tokens where possible.** RFC 9700 recommends mutual TLS or DPoP, so that a stolen token alone is not sufficient.

## Trade-offs

**Pros:**

- Each call carries the least privilege that it needs, for one API only.
- No shared super-credential exists to leak or to abuse.
- Each action is attributed to a human subject and to an agent actor.
- A short lifetime and one audience decrease the damage of a leak.

**Cons:**

- One extra round trip to the authorization server for each tool call, unless results are cached briefly per user, tool, and scope.
- It depends on authorization-server support and on downstream APIs that validate the audience and `act`.
- The authorization server becomes a dependency on the request path.
- The policy and scope tables need maintenance as tools change.

### Failure modes

- **Static broad scopes.** The exchanged token can do everything that the user can do. The cause is a broker that requests one fixed set of scopes and audiences for all calls. Keep a scope table for each operation, and alert when a returned `scope` is wider than the requested scope.
- **Raw user token forwarded to a third-party MCP server.** The token of the user appears in the logs of a third party and is replayed at another service. The cause is passthrough to a tool that accepts any bearer token. Always exchange, set the audience to the URL of that server, and let the authorization server refuse unknown resource URLs.
- **Impersonation without `act`.** Audit logs credit the human with actions that the agent did. The cause is a request without an `actor_token`, or a server that omits `act`. Send the actor token, and make the agent-facing API routes reject tokens that have no `act` claim.
- **Stale subject token in an unattended run.** A nightly job fails with an invalid token after the user logged out. The cause is a subject token that expired or was revoked while the job waited: RFC 9700 permits an authorization server to revoke refresh tokens on logout, and RFC 8693 does not link the output token to a renewed input token. Exchange inside each step, report that re-consent is necessary, and agree an explicit offline-access policy for unattended jobs.

## References

- [RFC 8693: OAuth 2.0 Token Exchange](https://datatracker.ietf.org/doc/html/rfc8693): subject token, actor token, downscoping, and audience restriction.
- [RFC 9700: OAuth 2.0 Security Best Current Practice](https://datatracker.ietf.org/doc/html/rfc9700): privilege restriction, audience restriction, and countermeasures for token replay.
- [OAuth.net: Token Exchange](https://oauth.net/2/token-exchange/): overview of RFC 8693 and its uses.
- [Model Context Protocol](https://modelcontextprotocol.io/): an open-source standard for connecting AI applications to external systems; a tool surface where a forwarded token can leak.
- Related: [Local-First Credential Broker](local-first-credential-broker.md) (keeps raw credentials out of the agent process of one user), [Policy-Gated Tool Proxy](policy-gated-tool-proxy.md) (the interception point where the exchange occurs), [Exact-Action Authorization Binding](exact-action-authorization-binding.md) (binds an approval to the action that runs), [Sandboxed Tool Authorization](sandboxed-tool-authorization.md) (limits which tools the agent can call)
