TIE-AGT-002Reference buildAgent identity/Delegation and authorisation
On-behalf-of delegation: the user as subject, the agent as actor
Let an agent act for a signed-in user with a short-lived token that names both of them, so every API sees who asked, which agent acted, and no more access than both are allowed.
In short#
- The agent never forwards the user's token and never uses a standing super-credential. It exchanges the user's token for a new one.
- The new token names the user as the subject and the agent as the actor, so APIs and audit logs see both.
- It is bound to one audience, carries only the scopes the task needs and expires in minutes, so the agent can never do more than the user and the agent are each allowed.
Problem#
When an agent works for a person, for example a banking assistant moving money or an internal assistant updating a ticket, it has to call APIs that were built for people. Teams usually take one of two shortcuts. The agent forwards the user's own access token to every API it calls, or the agent calls the APIs with its own service credential that can act for anyone.
Both shortcuts break accountability. With a forwarded token, every downstream system believes the user did the work and cannot tell an agent from a person; the token is also valid for far more than the task, and any service it passes through can replay it. With a service credential, the agent becomes a confused deputy: it can be talked into acting for a user it should not act for, or into doing something the user could never do themselves.
When to use it#
Use it when
- An agent acts in a session started by a signed-in user, such as an assistant, a copilot or a customer-facing agent.
- Downstream APIs already make decisions based on the user, and you want them to keep doing so.
- You need audit trails that show the person and the agent separately.
- Several agents or tools sit between the user and the API, and each hop must narrow access rather than widen it.
Avoid it, or add more, when
- The agent works on its own schedule with no user behind it. Give it its own identity and its own narrowly scoped access instead (see TIE-AGT-001).
- The downstream API cannot read or validate the delegated token. Put a gateway in front of it that validates the token and forwards a credential the API can trust.
- You expect delegation alone to stop risky actions. It limits who and what; high-impact actions still need a policy decision and, sometimes, a human (see TIE-AGT-003 and TIE-AGT-004).
Forces#
- Least privilege against convenience. One broad token is easy to pass around; one narrow token per audience is safer but needs an exchange per hop.
- User context against agent context. APIs need the user to apply data rules, and security needs the agent to attribute and contain actions.
- Short lifetimes against long tasks. Short tokens limit damage, but an agent task can outlive a token and must not be handed a long-lived refresh token to compensate.
- Standards against product reality. RFC 8693 defines the shape, but each platform implements actor claims, consent and audience checks differently.
Solution#
Put an exchange between the user's session and every API the agent calls. The agent presents the user's token (the subject token) and proves its own identity (the actor token or client authentication). The authorisation server checks that this agent is allowed to act for this user, then issues a new token for one audience with down-scoped permissions and a short lifetime. The API validates the token and applies its rules to the user, while logging and limiting what the agent may do.

What the delegated token carries
| Claim or parameter | Holds | Rule |
|---|---|---|
| sub | The user the agent works for | Copied from the subject token; never changed by the agent |
| act | The agent (its client ID, and its identity in your agent registry) | Present on every delegated token; nested if another agent acts further down the chain |
| aud | The one API this token is for | One audience per token; the API rejects anything else |
| scope (or authorization_details) | What the agent may do for this task | A subset of what the user has and of what the agent is allowed; never wider than the subject token |
| exp | When the token stops working | Minutes, not hours; no refresh token for the agent unless the use case truly needs one |
| may_act (on the subject token) | Which agents may exchange this token | Set by the authorisation server when the user signs in, or checked by policy at exchange time |
How it works
- Sign in. The user signs in to the client app. The app gets a token whose audience is the agent, not every downstream API.
- Exchange. When the agent needs an API, it calls the token endpoint with
grant_type=urn:ietf:params:oauth:grant-type:token-exchange, the user's token assubject_token, its own credential as actor, and the targetaudienceorresource. - Check. The authorisation server confirms the agent is registered, active and allowed to act for this user, and that the requested scopes are within both parties' rights.
- Issue. It returns a token with
sub= user,act= agent, one audience, reduced scopes and a short expiry. - Call. The agent calls the API with that token only.
- Enforce. The API validates signature, issuer, audience, expiry and scope, checks the actor against an allow list, applies the user's data rules and logs both identities.
- Repeat per hop. Each further API, tool or agent gets its own exchange, so access narrows at every step.
POST /oauth2/token
Content-Type: application/x-www-form-urlencoded
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's own access token or client assertion>
&actor_token_type=urn:ietf:params:oauth:token-type:access_token
&audience=https://api.example.com/orders
&scope=orders.read{
"iss": "https://idp.example.com",
"sub": "user-4821",
"aud": "https://api.example.com/orders",
"scope": "orders.read",
"act": { "sub": "agt-order-assistant-prod" },
"client_id": "agt-order-assistant-prod",
"iat": 1764000000,
"exp": 1764000300
}Design rules#
- Never forward the user's token. Exchange it for each audience; the user's original token stays between the user's app and the agent.
- Always delegate, never impersonate, when an agent is involved. Impersonation drops the actor; delegation keeps it. Turn impersonation off for agent clients.
- One audience per token. Request a specific
audienceorresourceand make APIs reject tokens meant for someone else. - Narrow at every hop. A delegated token's scopes are a subset of the subject token's and of the agent's allowed scopes.
- Minutes, not hours. Five to fifteen minutes is a sensible default. Re-exchange rather than refresh.
- Allow-list agents per API. APIs accept only actors they know, and record the actor on every write.
- Check the user is entitled to use this agent. The exchange policy verifies that this user may use this agent, not just that the agent exists.
- Keep audit in both names. Logs, events and records carry subject and actor separately so investigations can tell people from agents.
Anti-patterns#
| Anti-pattern | What goes wrong |
|---|---|
| Token passthrough | The agent sends the user's token to every API; any API or tool on the path can replay it anywhere the user has access |
| Agent super-credential | The agent calls APIs as itself with rights over all users; one prompt injection or bug acts for anyone |
| Impersonation for agents | Tokens show only the user; logs cannot tell what the agent did, and the user is blamed for the agent's mistakes |
| Same token for every tool | Scopes are the union of everything the agent might need, so every tool gets more than it should |
| Long-lived delegated refresh tokens | The agent can keep acting for the user for weeks after the conversation ended |
| Actor in a custom header | APIs trust an unauthenticated "X-Agent" header that any caller can set |
Trade-offs#
Benefits
- Every action is attributable to both the person and the agent.
- APIs keep applying the user's data rules without change.
- A leaked token is useful for minutes, against one API, for one task.
- The agent can never exceed what the user could do.
- A clean foundation for policy decisions, approvals and multi-agent chains.
Costs and risks
- An extra call to the token endpoint per audience. Cache delegated tokens for their short life to keep latency down.
- APIs must be changed, or fronted by a gateway, to validate audience and actor.
- Product differences: claim names, consent rules and audience checks vary by platform, so test each one.
- Long-running tasks need a way to resume with fresh user context instead of a long-lived token.
Recipes#
How to build this pattern on specific products. Each recipe shows its own maturity and when it was last verified.
Ping Identity recipe
Ping Identity
PingOne Advanced Identity Cloud with PingGateway
Advanced Identity Cloud supports RFC 8693 token exchange with both impersonation and delegation. A May Act script on the user's tokens names the agent client that may exchange them, and the agent's service client performs the exchange.
Components
| Component | Role in this pattern |
|---|---|
| Subject client | The user-facing app; issues the user token the agent will exchange |
| Actor client (the agent) | Confidential OAuth 2.0 client for the agent, allowed to use the token exchange grant |
| OAuth2 May Act script | Adds a may_act claim to user tokens naming the agent client, so only that agent can exchange them |
| Token exchange settings | Allowed audiences and the delegation behaviour on the provider and clients |
| PingGateway | Optional enforcement point in front of APIs: validates delegated tokens and actors |
Before you start
- Tokens can be exchanged only at the OAuth 2.0 provider that issued them, so the user's app and the agent must use the same Advanced Identity Cloud realm.
- Decide the agent's client ID and the audiences it may request before you write the May Act script.
Configure delegation (PingOne Advanced Identity Cloud)
- In the Advanced Identity Cloud admin console, create a new OAuth2 May Act script. Name it, for example,
May act - agents, and have it setmay_actwith the agent'sclient_idand, for delegation, the agent assub. - Go to Applications > + Add Application and create (or open) the user-facing Web client. Under its OAuth 2.0 provider overrides, enable the overrides and set OAuth2 Access Token May Act Script to your script.
- Create a Service client for the agent, for example
agt-order-assistant-prod, with a strong credential. Allow the Token Exchange grant type and only the scopes the agent may ever request. - Restrict the audiences the agent may request to the APIs it really calls.
- Sign in as a test user through the Web client and get an access token. Introspect it to check that
may_actnames the agent; the claim is not visible in the token response itself. - As the agent, call the token endpoint with the user token as
subject_token, the agent's own token asactor_tokenand the targetaudienceandscope. Check that the result carries the user as subject, the agent as actor and only the requested scope.
Gotchas
- For delegation, the
may_actclaim must name the agent's client ID and the subject of its actor token. If it names only the client ID, you have configured impersonation, and the agent disappears from the issued token. - Advanced Identity Cloud issues a refresh token on exchange when the client is allowed refresh tokens. Remove the refresh token grant from agent clients unless you have a reason to keep it.
- Claims that must not change, such as subject and issuer, are copied from the subject token. Claims that cannot be inferred are dropped, so test what your APIs need.
Check it works
- Introspect a delegated token:
subis the user, the actor is the agent,audis the one API and the scopes are reduced. - Try the exchange with another client: it is refused.
Okta recipe
Okta
Okta Workforce Identity with API Access Management
Written from vendor documentation and design experience; not yet lab-tested by Trevonix. Validate each step in a non-production tenant first.
Okta supports On-Behalf-Of Token Exchange on custom authorization servers, and Okta for AI Agents adds agent-specific exchange flows. This recipe is written from Okta's documentation and has not been lab-tested by Trevonix for this pattern.
Components
| Component | Role in this pattern |
|---|---|
| Custom authorization server | Issues the delegated tokens; On-Behalf-Of Token Exchange works within one custom authorization server or between servers in the same org |
| Custom scopes | The narrow permissions the agent may request for each API |
| Access policy rule | Allows the Token Exchange grant for the agent's client and limits scopes and token lifetime |
| AI agent (Okta for AI Agents) | The agent's registered identity; for agents, Okta also offers its own AI agent token exchange flows |
Before you start
- On-Behalf-Of Token Exchange needs API Access Management (custom authorization servers).
- If you use Okta for AI Agents, check whether its AI agent token exchange (which uses an Identity Assertion JWT for some resource types) fits your case better than plain on-behalf-of; see TIE-AGT-007.
Configure On-Behalf-Of Token Exchange
- In the Admin Console, go to Security > API > Authorization Servers and open (or create) the custom authorization server for the API.
- On Scopes, add the narrow custom scopes the agent may request, for example
orders.read. - Register the agent's client (or AI agent) with a key-based credential, and allow the Token Exchange grant type on it.
- On Access Policies, add a rule for the agent's client that allows the Token Exchange grant, limits scopes to the ones above, and sets a short access token lifetime.
- Have the agent call the authorization server's
/tokenendpoint with the user's access token assubject_tokenand request the API's audience and scope. - Validate the issued token at the API: audience, scope and the client that performed the exchange.
Gotchas
- When you use the AI agent token exchange flow with an ID-JAG, Okta strips system scopes such as
openidandprofileand returnsinvalid_scope; request a custom scope instead. - Check how the actor appears in the issued token in your org, and write API checks against what you see rather than what you expect.
Microsoft Entra recipe
Microsoft Entra
Microsoft Entra Agent ID
Written from vendor documentation and design experience; not yet lab-tested by Trevonix. Validate each step in a non-production tenant first.
Microsoft Entra Agent ID uses the OAuth 2.0 on-behalf-of flow with agent-specific steps: the agent identity blueprint exchanges the user's token for a token issued to the agent identity. Written from Microsoft documentation; not yet lab-tested by Trevonix for this pattern.
Components
| Component | Role in this pattern |
|---|---|
| Agent identity blueprint | The agent's parent application; receives the user's token and authenticates with a federated credential, certificate or secret |
| Agent identity | The specific agent that acts; the blueprint requests tokens for it during the exchange |
| Delegated permissions | The API permissions the agent may use on the user's behalf, consented by the user or an admin |
| On-behalf-of (OBO) flow | jwt-bearer exchange that returns a token for the downstream API with the user's identity |
Before you start
- The user's token sent to the agent must have the blueprint as its audience. A token meant for another resource, such as Microsoft Graph, is rejected.
- Blueprints cannot start interactive sign-in themselves; a client app signs the user in and passes the token to the agent.
Configure the agent on-behalf-of flow
- Create the agent from a blueprint in Entra ID > Agents (see TIE-AGT-001) and grant the agent identity the delegated permissions it needs for each downstream API, with user or admin consent.
- In the client app, sign the user in and request a token whose audience is the agent identity blueprint.
- In the agent, have the blueprint obtain a token for the specific agent identity using its credential (Microsoft recommends a managed identity as the federated credential), passing the agent identity's client ID as
fmi_path. - Call the token endpoint with
grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer, the user's token asassertion,requested_token_use=on_behalf_ofand the downstream API's scope. - Call the API with the returned token, and confirm in the sign-in logs that the request is attributed to the agent identity acting for the user.
Gotchas
- Agents built in Microsoft Foundry can perform this exchange for tool calls automatically; check what Foundry does before writing your own token code.
- Use the Microsoft.Identity.Web library where you can; it handles the agent-specific exchange details.
Saviynt recipe
Saviynt
Saviynt Identity Security for AI
Written from vendor documentation and design experience; not yet lab-tested by Trevonix. Validate each step in a non-production tenant first.
Saviynt does not issue delegated tokens; it governs which agents may act for whom and can enforce policy at runtime through Agent Access Gateway. Written from Saviynt's published material; not lab-tested by Trevonix.
Capabilities used
| Capability | Role in this pattern |
|---|---|
| Agent inventory and ownership | Confirms every agent that holds a token-exchange client is registered and owned |
| Access governance | Certifies which agents may act for which users or groups, and which scopes they hold |
| Agent Access Gateway | Optional runtime enforcement point that evaluates agent requests against policy |
Configure
- Bring the agent clients that use token exchange into the agent inventory, with owners.
- Model "may act for" relationships and allowed scopes as access that the agent's sponsor certifies on a schedule.
- Revoke the relationship in the authorisation server when a certification removes it.
- Where you use Agent Access Gateway, add a policy that rejects agent requests that do not carry a delegated user context.
Gotchas
- Saviynt governs which delegations should exist; the token exchange itself happens in your authorisation server. Check which of your platforms Saviynt can read delegation settings from.
Other product recipe
Not available
No recipe for another product has been published for this pattern yet. Recipes for further products, for example SailPoint, CyberArk or ForgeRock, are added here as they are written.
Product: to be specified
Verification tests#
| Test | Expected result |
|---|---|
| Agent calls the API with the user's original token | Rejected: wrong audience |
| Agent requests a scope the user does not have | Exchange refused, or scope removed from the issued token |
| Agent requests a scope it is not allowed to have | Exchange refused |
| A different, unregistered client tries to exchange the user's token | Refused: not an allowed actor |
| Use an orders token against the payments API | Rejected: wrong audience |
| Replay a delegated token after it expires | Rejected |
| Inspect the audit record for an agent write | Shows the user as subject and the agent as actor |
| Disable the agent in the identity platform, then try an exchange | Refused |
Maturity and verification#
Reference build. Trevonix has built delegated token exchange end to end on Ping Identity (PingOne Advanced Identity Cloud with PingGateway) in a lab tenant (November 2026). The Okta, Microsoft Entra and Saviynt recipes are written from vendor documentation and have not yet been lab-tested by Trevonix for this pattern.
Frequently asked questions#
What is the difference between delegation and impersonation?
Impersonation issues a token that looks as if the user called the API directly; the agent disappears. Delegation issues a token that keeps the user as subject and adds the agent as actor. For agents, use delegation, so you can see and limit what the agent did.
Why not just send the user's token with an agent header?
It can, but then the API trusts something anyone can forge, and the user's token still travels to every API. A delegated token carries the actor inside a signed token, bound to one audience.
What about agents that run without a user?
Then there is no subject to delegate from. The agent should use its own identity with narrowly scoped access, and high-impact actions should go through a policy decision and, where needed, a human approval.
How long should a delegated token live?
Long enough for one step of the task, usually five to fifteen minutes. If the task takes longer, exchange again when the next step starts, ideally with a fresh user token, rather than giving the agent a refresh token.
Does this work when agents call other agents?
Yes. Each hop exchanges the token it received for a new one aimed at the next audience, and the actor claims nest. Limit the depth, and make APIs check every actor in the chain.
Related patterns and references#
- RFC 8693: OAuth 2.0 Token Exchange
- RFC 8707: Resource Indicators for OAuth 2.0
- PingOne Advanced Identity Cloud: Token exchange
- PingOne Advanced Identity Cloud: Demonstrate delegation
- Okta Developer: Set up OAuth 2.0 On-Behalf-Of Token Exchange
- Okta Developer: Set up AI agent token exchange
- Microsoft Learn: Agent OAuth flows, on-behalf-of flow
- OWASP Top 10 for Agentic Applications
Cite this pattern
Trevonix (2026). On-behalf-of delegation: the user as subject, the agent as actor (TIE-AGT-002, version 1.0). Identi Patterns. https://exchange.trevonix.com/patterns/tie-agt-002-on-behalf-of-delegation-the-user-as-subject-the-agent-as-actor
Licensed under CC BY 4.0. Credit Trevonix and link to this page when you reuse it.
Patterns are guidance, provided as is and without warranty. Test in a non-production environment and check current vendor documentation before you rely on them. Read the full disclaimer.