← All guides

Identity & authorization

Design delegated authorization across an agent tool chain

Separate user delegation from application authority, validate token boundaries, and prevent an agent from turning an authorized session into an unauthorized action.

OAuthOBOauthorizationagentsEntra ID
A delegated request crosses API A, an on-behalf-of exchange and API B; application-only authority remains separate.
Validate each token audience and independently authorize the target object and action.View full-size diagram

An agent can choose a tool and propose arguments, but it must not choose the identity or permissions that authorize that call. This guide examines a signed-in user calling an agent API, which then calls a protected downstream API. It uses standard Microsoft Entra OAuth flows; a product-specific agent identity feature may have different preview restrictions. These are architecture and acceptance recommendations, not results from a tenant test.

Threat model and prerequisites

Assume a legitimate user can alter tool arguments, submit another person’s record ID, and cause retrieved content to influence the agent. Also consider a compromised client, a tenant-confusion bug, and a cache returning another user’s result. The protected assets are downstream records and actions, not merely access to the chat interface.

Inventory the client registration, agent API registration, downstream resources, supported token versions, exposed delegated scopes, application permissions, and consent grants. Identify administrators authorized to grant consent and reviewers who understand the downstream product’s licensing and access model. Confirm that the target supports the chosen delegated operation; possession of a Graph token does not establish support for every Graph permission or endpoint.

Define two operations precisely: for example, reading a ticket the user may view and changing its assigned team. Give each a required permission, record-level rule, and expected failure response. Avoid one vaguely named “agent access” entitlement for both.

1. Choose delegation or application authority explicitly

Microsoft’s on-behalf-of flow exchanges a user access token intended for API A for a token intended for API B. It uses delegated permissions and works for user principals, not an incoming app-only principal. The middle tier must also authenticate itself. OBO protocol and limitations.

By contrast, client credentials authorize the application itself without a signed-in user. Application permissions can cover a much wider dataset. A valid app-only token can even lack a roles claim when a resource uses its own application ACL; the resource still must enforce an explicit permission decision. Client-credentials authorization.

Our recommended architecture keeps interactive delegated tools and autonomous application-owned tools behind distinct authorization policies. Never retry a denied delegated request with a more powerful application token. That converts a user boundary into the application’s full authority, even if the UI still displays the user’s name.

Delegation reduces the need to reproduce source-system permissions but introduces consent, session, and user-interaction dependencies. App-only processing supports scheduled work but requires an independently justified authorization model. Choose it for a defined business service, not as a workaround for an OBO error.

2. Validate the token at the API that owns it

Configure supported authentication middleware to validate signature, issuer, lifetime, and audience for the agent API. Select validation metadata for the token version your API accepts. A client treats downstream access tokens as opaque; the receiving resource validates them. An ID token proving sign-in is not the access token for a protected API. Token ownership and validation.

After cryptographic validation, enforce the accepted tenant, subject, operation permission, and actor policy. Use stable identifiers such as the combination of tid and oid for tenant-scoped application records. Email, UPN, and display claims are unsuitable permission keys. Checking only tenant membership and the existence of an object ID can accidentally admit service principals as users. Claims authorization.

Make user-delegated and app-only routes distinguishable by their expected token and permission contract. For a delegated operation, validate the required scp value and the user/resource rule. For an application operation, validate its explicit app permission or approved application ACL. Do not treat “a roles claim exists” as a universal discriminator: user tokens can also carry role information.

3. Exchange for a specific downstream audience

The frontend requests an access token for the agent API. The validated middle tier uses MSAL to request the approved downstream scopes, authenticating with its configured confidential-client credential. It sends the resulting downstream token only to that resource. Do not forward the incoming agent-API token to Graph or another tool endpoint, or expose the downstream token to the model. OBO request chain.

Maintain a server-owned mapping from tool name to API audience, allowed scopes, endpoint, and operation. Model output may supply a ticket identifier, but cannot replace the authority URL, resource audience, or credential. Construct requests through a typed adapter with an allowlisted destination and validate the selected record under the authenticated context.

For guests, MSAL guidance uses the validated token’s tenant-specific authority rather than /common or /organizations. If downstream Conditional Access needs interaction, return the documented claims challenge to a capable client and pause the tool. Do not erase the challenge by falling back to a shared account. MSAL OBO tenant and challenge handling.

4. Bind authorization to the actual action

Evaluate permission at every tool invocation, including retries and handoffs. Derive tenant context from trusted application state; do not accept a tenant, user, or approver named in the conversation as an identity assertion. Microsoft recommends these deterministic boundaries for multitenant agentic systems. Agent authorization boundaries.

Our recommended approval record binds the authenticated approver, target tenant, operation, resource identifiers, important arguments, expiration, and a single-use or idempotency reference. Revalidate after approval: a changed target or amount needs a fresh decision. A read-only delegated scope cannot authorize a write simply because the user typed “yes.”

A downstream service might enforce only coarse API scopes. Your adapter must then enforce application-specific ownership, purpose, or record constraints before invoking it. If the necessary rule cannot be evaluated, return a controlled denial. Do not retrieve unrestricted data and ask the model to decide what the user should see.

5. Keep caches and asynchronous work within the boundary

Use the supported MSAL token cache rather than a global variable holding the last successful token. Token acquisition results include scope, expiry, and account metadata; client code should use those values rather than parse another resource’s token. MSAL caching guidance.

Partition application response caches and conversation state by the actual authorization context, not just prompt text. Include the resource and relevant permission/version state or reauthorize before reuse. A cached answer can disclose a document after retrieval has been correctly denied.

Ordinary OBO and long-running OBO use different MSAL.NET patterns. If a task must continue after the request, explicitly design session-key ownership, protected persisted cache, eviction, cancellation, and reauthentication. Do not store a bearer token in a queue message and assume it creates an indefinitely authorized job. Long-running OBO.

Acceptance tests and evidence

Run against synthetic records using ordinary identities, retaining sanitized request IDs and downstream outcomes:

Case Required result
Intended user, correct scope, owned record Allowed; downstream identity and target match the request
Same user, another tenant’s or excluded record Denied before protected content or side effects reach the model
Token for another API, expired token, or ID token Rejected by API authentication
App-only token on a user-delegated route Rejected under that route’s contract
Delegated call lacks consent or requires step-up Controlled challenge/failure; no app-only fallback
Approved write with mutated arguments Rejected or requires new approval
Two users issue the same question concurrently No token, answer, or conversation-state crossover
Cancelled asynchronous task or revoked test permission No new authorized work after observed enforcement; delay recorded

For troubleshooting, distinguish token validation, token exchange, downstream authorization, and application policy failures. Record tenant/principal identifiers, scope names, tool/version, target, correlation IDs, and policy decision—not tokens. A successful sign-in proves neither a successful API operation nor correct record authorization. Investigate each boundary separately and repeat the matrix when scopes, tool adapters, identities, or cache behavior change.

Go to the source

References & further reading

  1. Microsoft Learn — Microsoft identity platform OAuth on-behalf-of flow
  2. Microsoft Learn — Access tokens in the Microsoft identity platform
  3. Microsoft Learn — Secure applications and APIs by validating claims
  4. Microsoft Learn — OAuth client credentials flow
  5. Microsoft Learn — On-behalf-of flows with MSAL.NET
  6. Microsoft Learn — Acquire and cache tokens with MSAL
  7. Microsoft Learn — Considerations for multitenant agentic systems