{"id":"TIE-AGT-002","title":"On-behalf-of delegation: the user as subject, the agent as actor","maturity":"reference-build","collection":"Agent identity","category":"Delegation and authorisation","complexity":"Medium","intent":"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.","summary":"Agents that reuse a user's token, or call APIs with their own broad credentials, hide who is really acting. This pattern exchanges the user's token for a delegated token where the user is the subject and the agent is the actor, bound to one audience and the task's scopes.","problems":["Agents using human or shared credentials","Accountability for AI actions","Over-privileged agents","Impersonation instead of delegation","Audit evidence for AI governance"],"standards":["OAuth 2.0 Token Exchange (RFC 8693)","OAuth 2.0 Resource Indicators (RFC 8707)","JWT access tokens (RFC 9068)","OpenID Connect","OWASP Agentic Top 10 ASI03 Identity and Privilege Abuse"],"tags":["on-behalf-of","OBO","delegation","token exchange","act claim","may_act","actor token","subject token","impersonation","confused deputy","audience","down-scoping"],"roles":["IAM architect","Identity engineer","Security leader","Platform engineering","AI engineering"],"industries":["Cross-industry","Financial services","Healthcare","Retail","Public sector"],"builds_on":["TIE-AGT-001"],"related":["TIE-AGT-003","TIE-AGT-005","TIE-AGT-007"],"authors":"Trevonix Innovation","reviewers":"Trevonix IAM architecture","version":"1.0","last_reviewed":"2026-11-24","published":"2026-11-24","og_image":"og-tie-agt-002.png","sections":{"summary":[{"type":"bullets","content":"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.\nThe new token names the **user as the subject** and the **agent as the actor**, so APIs and audit logs see both.\nIt 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":[{"type":"paragraph","content":"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.\n\nBoth 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."},{"type":"note","content":"Regulators and auditors increasingly ask two questions about automated actions: on whose authority was this done, and which software did it? A forwarded token answers only the first; a service credential answers only the second. Delegation answers both.","title":"Why this matters"}],"use_when":[{"type":"bullets","content":"An agent acts in a session started by a signed-in user, such as an assistant, a copilot or a customer-facing agent.\nDownstream APIs already make decisions based on the user, and you want them to keep doing so.\nYou need audit trails that show the person and the agent separately.\nSeveral agents or tools sit between the user and the API, and each hop must narrow access rather than widen it."}],"avoid_when":[{"type":"bullets","content":"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).\nThe 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.\nYou 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":[{"type":"bullets","content":"**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.\n**User context against agent context.** APIs need the user to apply data rules, and security needs the agent to attribute and contain actions.\n**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.\n**Standards against product reality.** RFC 8693 defines the shape, but each platform implements actor claims, consent and audience checks differently."}],"solution":[{"type":"paragraph","content":"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."},{"type":"image","content":"The agent exchanges the user's token for a delegated token per audience. Each API sees the user as subject and the agent as actor.","title":"Solution overview","media":"tie-agt-002-solution.png","alt":"Diagram: a user signs in to an app and gets token T1 for the agent. The agent sends T1 as the subject token and its own credential as the actor to the authorisation server. The server checks that the agent may act for the user, and returns token T2 with sub = the user, act = the agent, aud = the ord"},{"type":"table","content":"Claim or parameter | Holds | Rule\nsub | The user the agent works for | Copied from the subject token; never changed by the agent\nact | 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\naud | The one API this token is for | One audience per token; the API rejects anything else\nscope (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\nexp | When the token stops working | Minutes, not hours; no refresh token for the agent unless the use case truly needs one\nmay_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","title":"What the delegated token carries"},{"type":"numbered","content":"**Sign in.** The user signs in to the client app. The app gets a token whose audience is the agent, not every downstream API.\n**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 as `subject_token`, its own credential as actor, and the target `audience` or `resource`.\n**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.\n**Issue.** It returns a token with `sub` = user, `act` = agent, one audience, reduced scopes and a short expiry.\n**Call.** The agent calls the API with that token only.\n**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.\n**Repeat per hop.** Each further API, tool or agent gets its own exchange, so access narrows at every step.","title":"How it works"},{"type":"code","content":"POST /oauth2/token\nContent-Type: application/x-www-form-urlencoded\n\ngrant_type=urn:ietf:params:oauth:grant-type:token-exchange\n&subject_token=<user access token>\n&subject_token_type=urn:ietf:params:oauth:token-type:access_token\n&actor_token=<agent's own access token or client assertion>\n&actor_token_type=urn:ietf:params:oauth:token-type:access_token\n&audience=https://api.example.com/orders\n&scope=orders.read","title":"Token exchange request (RFC 8693)","language":"http"},{"type":"code","content":"{\n  \"iss\": \"https://idp.example.com\",\n  \"sub\": \"user-4821\",\n  \"aud\": \"https://api.example.com/orders\",\n  \"scope\": \"orders.read\",\n  \"act\": { \"sub\": \"agt-order-assistant-prod\" },\n  \"client_id\": \"agt-order-assistant-prod\",\n  \"iat\": 1764000000,\n  \"exp\": 1764000300\n}","title":"Decoded delegated token","language":"json"},{"type":"tip","content":"If an agent hands work to another agent, the second exchange uses the first delegated token as the subject token, and the result nests the actors: `act: { sub: agent-b, act: { sub: agent-a } }`. Keep the chain short and make APIs check the whole chain, not just the outermost actor.","title":"Agents calling agents"}],"design_rules":[{"type":"numbered","content":"**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.\n**Always delegate, never impersonate, when an agent is involved.** Impersonation drops the actor; delegation keeps it. Turn impersonation off for agent clients.\n**One audience per token.** Request a specific `audience` or `resource` and make APIs reject tokens meant for someone else.\n**Narrow at every hop.** A delegated token's scopes are a subset of the subject token's and of the agent's allowed scopes.\n**Minutes, not hours.** Five to fifteen minutes is a sensible default. Re-exchange rather than refresh.\n**Allow-list agents per API.** APIs accept only actors they know, and record the actor on every write.\n**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.\n**Keep audit in both names.** Logs, events and records carry subject and actor separately so investigations can tell people from agents."}],"anti_patterns":[{"type":"table","content":"Anti-pattern | What goes wrong\nToken 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\nAgent super-credential | The agent calls APIs as itself with rights over all users; one prompt injection or bug acts for anyone\nImpersonation for agents | Tokens show only the user; logs cannot tell what the agent did, and the user is blamed for the agent's mistakes\nSame token for every tool | Scopes are the union of everything the agent might need, so every tool gets more than it should\nLong-lived delegated refresh tokens | The agent can keep acting for the user for weeks after the conversation ended\nActor in a custom header | APIs trust an unauthenticated \"X-Agent\" header that any caller can set"}],"benefits":[{"type":"bullets","content":"Every action is attributable to both the person and the agent.\nAPIs keep applying the user's data rules without change.\nA leaked token is useful for minutes, against one API, for one task.\nThe agent can never exceed what the user could do.\nA clean foundation for policy decisions, approvals and multi-agent chains."}],"costs":[{"type":"bullets","content":"An extra call to the token endpoint per audience. Cache delegated tokens for their short life to keep latency down.\nAPIs must be changed, or fronted by a gateway, to validate audience and actor.\nProduct differences: claim names, consent rules and audience checks vary by platform, so test each one.\nLong-running tasks need a way to resume with fresh user context instead of a long-lived token."}],"tests":[{"type":"table","content":"Test | Expected result\nAgent calls the API with the user's original token | Rejected: wrong audience\nAgent requests a scope the user does not have | Exchange refused, or scope removed from the issued token\nAgent requests a scope it is not allowed to have | Exchange refused\nA different, unregistered client tries to exchange the user's token | Refused: not an allowed actor\nUse an orders token against the payments API | Rejected: wrong audience\nReplay a delegated token after it expires | Rejected\nInspect the audit record for an agent write | Shows the user as subject and the agent as actor\nDisable the agent in the identity platform, then try an exchange | Refused"}],"maturity_notes":[{"type":"paragraph","content":"**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."},{"type":"warning","content":"Agent-specific token flows are new in every product, and some are in preview or early access. Check each recipe's last-verified date and your vendor's current documentation and licensing before you start.","title":"Agent identity products change quickly"}],"faq":[{"type":"faq","content":"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.","title":"What is the difference between delegation and impersonation?"},{"type":"faq","content":"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.","title":"Why not just send the user's token with an agent header?"},{"type":"faq","content":"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.","title":"What about agents that run without a user?"},{"type":"faq","content":"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.","title":"How long should a delegated token live?"},{"type":"faq","content":"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.","title":"Does this work when agents call other agents?"}],"references":[{"type":"bullets","content":"[RFC 8693: OAuth 2.0 Token Exchange](https://www.rfc-editor.org/rfc/rfc8693)\n[RFC 8707: Resource Indicators for OAuth 2.0](https://www.rfc-editor.org/rfc/rfc8707)\n[PingOne Advanced Identity Cloud: Token exchange](https://docs.pingidentity.com/pingoneaic/am-oauth2/token-exchange.html)\n[PingOne Advanced Identity Cloud: Demonstrate delegation](https://docs.pingidentity.com/pingoneaic/am-oauth2/token-exchange-delegation.html)\n[Okta Developer: Set up OAuth 2.0 On-Behalf-Of Token Exchange](https://developer.okta.com/docs/guides/set-up-token-exchange/-/main/)\n[Okta Developer: Set up AI agent token exchange](https://developer.okta.com/docs/guides/ai-agent-token-exchange/main/)\n[Microsoft Learn: Agent OAuth flows, on-behalf-of flow](https://learn.microsoft.com/en-us/entra/agent-id/agent-on-behalf-of-oauth-flow)\n[OWASP Top 10 for Agentic Applications](https://genai.owasp.org/2025/12/09/owasp-top-10-for-agentic-applications-the-benchmark-for-agentic-security-in-the-age-of-autonomous-ai/)"}]},"recipes":{"ping":{"status":"reference-build","product_name":"PingOne Advanced Identity Cloud with PingGateway","summary":"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.","last_verified":"2026-11","blocks":[{"type":"table","content":"Component | Role in this pattern\nSubject client | The user-facing app; issues the user token the agent will exchange\nActor client (the agent) | Confidential OAuth 2.0 client for the agent, allowed to use the token exchange grant\nOAuth2 May Act script | Adds a `may_act` claim to user tokens naming the agent client, so only that agent can exchange them\nToken exchange settings | Allowed audiences and the delegation behaviour on the provider and clients\nPingGateway | Optional enforcement point in front of APIs: validates delegated tokens and actors","title":"Components"},{"type":"bullets","content":"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.\nDecide the agent's client ID and the audiences it may request before you write the May Act script.","title":"Before you start"},{"type":"numbered","content":"In the Advanced Identity Cloud admin console, create a new **OAuth2 May Act** script. Name it, for example, `May act - agents`, and have it set `may_act` with the agent's `client_id` and, for delegation, the agent as `sub`.\nGo 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.\nCreate 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.\nRestrict the audiences the agent may request to the APIs it really calls.\nSign in as a test user through the Web client and get an access token. Introspect it to check that `may_act` names the agent; the claim is not visible in the token response itself.\nAs the agent, call the token endpoint with the user token as `subject_token`, the agent's own token as `actor_token` and the target `audience` and `scope`. Check that the result carries the user as subject, the agent as actor and only the requested scope.","title":"Configure delegation (PingOne Advanced Identity Cloud)"},{"type":"bullets","content":"For delegation, the `may_act` claim 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.\nAdvanced 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.\nClaims 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.","title":"Gotchas"},{"type":"bullets","content":"Introspect a delegated token: `sub` is the user, the actor is the agent, `aud` is the one API and the scopes are reduced.\nTry the exchange with another client: it is refused.","title":"Check it works"}]},"okta":{"status":"documented","product_name":"Okta Workforce Identity with API Access Management","summary":"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.","last_verified":"2026-11","blocks":[{"type":"table","content":"Component | Role in this pattern\nCustom authorization server | Issues the delegated tokens; On-Behalf-Of Token Exchange works within one custom authorization server or between servers in the same org\nCustom scopes | The narrow permissions the agent may request for each API\nAccess policy rule | Allows the Token Exchange grant for the agent's client and limits scopes and token lifetime\nAI agent (Okta for AI Agents) | The agent's registered identity; for agents, Okta also offers its own AI agent token exchange flows","title":"Components"},{"type":"bullets","content":"On-Behalf-Of Token Exchange needs API Access Management (custom authorization servers).\nIf 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.","title":"Before you start"},{"type":"numbered","content":"In the Admin Console, go to **Security > API > Authorization Servers** and open (or create) the custom authorization server for the API.\nOn **Scopes**, add the narrow custom scopes the agent may request, for example `orders.read`.\nRegister the agent's client (or AI agent) with a key-based credential, and allow the **Token Exchange** grant type on it.\nOn **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.\nHave the agent call the authorization server's `/token` endpoint with the user's access token as `subject_token` and request the API's audience and scope.\nValidate the issued token at the API: audience, scope and the client that performed the exchange.","title":"Configure On-Behalf-Of Token Exchange"},{"type":"bullets","content":"When you use the AI agent token exchange flow with an ID-JAG, Okta strips system scopes such as `openid` and `profile` and returns `invalid_scope`; request a custom scope instead.\nCheck how the actor appears in the issued token in your org, and write API checks against what you see rather than what you expect.","title":"Gotchas"}]},"entra":{"status":"documented","product_name":"Microsoft Entra Agent ID","summary":"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.","last_verified":"2026-11","blocks":[{"type":"table","content":"Component | Role in this pattern\nAgent identity blueprint | The agent's parent application; receives the user's token and authenticates with a federated credential, certificate or secret\nAgent identity | The specific agent that acts; the blueprint requests tokens for it during the exchange\nDelegated permissions | The API permissions the agent may use on the user's behalf, consented by the user or an admin\nOn-behalf-of (OBO) flow | jwt-bearer exchange that returns a token for the downstream API with the user's identity","title":"Components"},{"type":"bullets","content":"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.\nBlueprints cannot start interactive sign-in themselves; a client app signs the user in and passes the token to the agent.","title":"Before you start"},{"type":"numbered","content":"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.\nIn the client app, sign the user in and request a token whose audience is the agent identity blueprint.\nIn 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`.\nCall the token endpoint with `grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer`, the user's token as `assertion`, `requested_token_use=on_behalf_of` and the downstream API's scope.\nCall 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.","title":"Configure the agent on-behalf-of flow"},{"type":"bullets","content":"Agents built in Microsoft Foundry can perform this exchange for tool calls automatically; check what Foundry does before writing your own token code.\nUse the Microsoft.Identity.Web library where you can; it handles the agent-specific exchange details.","title":"Gotchas"}]},"saviynt":{"status":"documented","product_name":"Saviynt Identity Security for AI","summary":"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.","last_verified":"2026-11","blocks":[{"type":"table","content":"Capability | Role in this pattern\nAgent inventory and ownership | Confirms every agent that holds a token-exchange client is registered and owned\nAccess governance | Certifies which agents may act for which users or groups, and which scopes they hold\nAgent Access Gateway | Optional runtime enforcement point that evaluates agent requests against policy","title":"Capabilities used"},{"type":"numbered","content":"Bring the agent clients that use token exchange into the agent inventory, with owners.\nModel \"may act for\" relationships and allowed scopes as access that the agent's sponsor certifies on a schedule.\nRevoke the relationship in the authorisation server when a certification removes it.\nWhere you use Agent Access Gateway, add a policy that rejects agent requests that do not carry a delegated user context.","title":"Configure"},{"type":"bullets","content":"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.","title":"Gotchas"}]},"misc":{"status":"not-available","product_name":"","summary":"","last_verified":"","blocks":[]}},"slug":"tie-agt-002-on-behalf-of-delegation-the-user-as-subject-the-agent-as-actor","updated_at":"2026-11-24T16:55:55.909Z","url":"https://exchange.trevonix.com/patterns/tie-agt-002-on-behalf-of-delegation-the-user-as-subject-the-agent-as-actor","markdown_url":"https://exchange.trevonix.com/patterns/tie-agt-002-on-behalf-of-delegation-the-user-as-subject-the-agent-as-actor.md","publisher":"Trevonix","license":{"name":"CC BY 4.0","url":"https://creativecommons.org/licenses/by/4.0/"}}