Skip to content
Darvi Lab. Logo
Engineering

AI Agent Authorization: OAuth,Scopes and Delegation

AI agent authorization with OAuth: why audience validation is mandatory, what token passthrough breaks, and how RFC 8693 delegation records the actor.

Nov 23, 202610 min read
DarviLabs Team
AI Agent Authorization: OAuth, Scopes and Delegation
01

The short answer

If an agent can call your API, the only thing between a bad model output and a deleted row is your authorization layer. Not your system prompt, not a tool description, not a confirmation step the model is free to skip. Agent authorization is ordinary OAuth work done more carefully than most teams do it for human clients, because an agent makes a thousand calls an hour and never reads a warning.

Three things decide whether it holds. The token has to say who is acting on whose behalf, so that a revoked agent does not mean a revoked user. The resource server has to validate that the token was issued for it, and never forward the token it received to anything downstream. And the permission itself has to be enforced by the system that owns the data, not inferred from a scope string the model happened to see.

Everything below is how each of those three fails in production, and what the current specifications actually require. The MCP authorization specification and its security guidance are unusually specific here, and most of what they mandate is cheap to implement if you do it before you have clients in the wild.

02

The agent is not the user, and the token should say so

The shortcut almost everyone takes first is to hand the agent the user's access token. It works immediately, and it destroys two things you will want later. Every downstream audit log now says the user performed the action, so when something goes wrong you cannot tell a human click from an agent loop. And the only way to cut the agent off is to revoke the user's credentials, which also cuts off the user.

OAuth 2.0 Token Exchange, RFC 8693, exists for exactly this and has been a Proposed Standard since January 2020. The grant type value is urn:ietf:params:oauth:grant-type:token-exchange. The two required parameters are subject_token and subject_token_type, carrying what the RFC calls a token representing the identity of the party on behalf of whom the request is being made. The optional actor_token and actor_token_type carry the identity of the acting party, and actor_token_type is required whenever actor_token is present.

That optional parameter is the whole distinction. RFC 8693 separates impersonation from delegation in plain language: under impersonation, principal A is given all the rights that B has within some defined rights context and is, in the RFC's words, indistinguishable from B in that context. Under delegation semantics, principal A still has its own identity separate from B, and any actions taken are being taken by A representing B. An exchange with only a subject token gives you impersonation. If you want delegation, you have to send the actor token.

The result is recorded in the act claim, which the RFC says can provide a representation of a chain of delegation. The outermost act identifies the current actor and nested act claims record prior actors, which is what you want when a user authorizes an orchestrator that calls a sub-agent that calls your API. There is also a may_act claim, titled Authorized Actor in section 4.4, which lets an issuer state in advance that a specific party is permitted to become the actor for a given subject. If you run your own authorization server, may_act is how you allowlist which agents may ever act for a user, rather than deciding it per request in application code.

Use the optional audience, resource and scope parameters on the exchange to narrow as you go: one exchange per downstream target, with only the scopes that target needs. Be aware that when a request names several targets, the RFC describes the requested access rights as the Cartesian product of all the scopes at all the target services, which is the opposite of narrowing. There are also active IETF drafts aimed specifically at on-behalf-of authorization for AI agents, with parameters for naming the agent on the consent screen. Their status moves month to month and none of them is settled, so build on RFC 8693 today and keep the exchange behind one broker you can change later.

03

Audience validation is the one check you cannot skip

In the MCP authorization specification, revision 2026-07-28, a protected MCP server acts as an OAuth 2.1 resource server. It does not issue tokens. An authorization server, co-located or separate, interacts with the user and issues access tokens for use at that server, and the server's job is to validate them. If your MCP server is minting its own bearer tokens, you have built an authorization server by accident and inherited all of its obligations.

The validation requirement is the strongest language in the document. Servers must validate that tokens presented to them were specifically issued for their use, must only accept tokens intended for themselves, and must reject tokens that do not include them in the audience claim or otherwise verify that they are the intended recipient. Invalid or expired tokens must receive an HTTP 401. Clients must not send tokens other than those issued by the server's own authorization server, and the server must not accept or transit any others.

Two RFCs make that mechanically possible. RFC 9728, OAuth 2.0 Protected Resource Metadata, is a must for MCP servers, and clients must use it to discover the authorization server. RFC 8707, Resource Indicators, is a must for clients: the resource parameter goes in both the authorization request and the token request, carries the canonical URI of the MCP server, and must be sent whether or not the authorization server is known to support it. That is the request half of audience binding, and the audience check is the enforcement half. Neither works alone.

Two more requirements are easy to miss. PKCE with the S256 challenge method is mandatory, and clients must refuse to proceed if the authorization server's metadata does not advertise code_challenge_methods_supported. Separately, authorization servers should return the iss parameter and clients must apply the issuer validation from RFC 9207, because PKCE does not prevent mix-up attacks where a malicious authorization server induces a client to send a code to an honest one. Write one validation function that checks issuer, audience, expiry and scope, reject on a missing claim rather than only a mismatched one, and call it on every inbound request including the ones you think are unauthenticated.

04

Token passthrough is the bug that looks like a feature

Passing the inbound token straight to a downstream API feels like the clean, stateless thing to do. The specification forbids it: the MCP server must not pass through the token it received from the client, and must not accept tokens that were not explicitly issued for it. If your server calls an upstream API, it acts as an OAuth client to that API and uses a separate token issued by that API's authorization server.

The reason is not purity. A downstream service receiving a forwarded token may trust it as though your server vouched for it, or assume someone upstream already validated its claims. You lose the trust boundary, you lose any ability to apply your own policy at the edge, and your audit trail records the original client rather than the service that actually made the call. A stolen token then turns your server into a general-purpose exfiltration proxy, because it will forward anything it is handed.

The sharpest version of this is the confused deputy problem, and it needs four conditions that are easy to meet by accident. Your server proxies to a third-party authorization server using one static client ID for all traffic. It lets MCP clients register dynamically, so each gets its own client_id. The third party sets a consent cookie after the first successful authorization. And your proxy does not ask for consent per client before forwarding. Once a legitimate user has consented once, an attacker registers a client with their own redirect_uri, sends a crafted link, the third party skips consent because the cookie matches the static client ID, and the authorization code lands on the attacker's endpoint.

The mitigation is a per-user registry of approved client_id values, checked before any third-party flow starts, and a consent screen that names the requesting client, the specific third-party scopes and the registered redirect URI. The guidance is specific about the mechanics, and the details are where implementations go wrong: consent cookies using the __Host name prefix, with Secure, HttpOnly and SameSite=Lax, either signed or backed by server-side sessions, bound to a specific client_id rather than recording that the user has consented in general. Redirect URIs matched by exact string, never a pattern or wildcard. A fresh random state per request, single-use, short-lived, and critically, the cookie or session holding it is not set until after the user has actually approved the consent screen.

05

Scopes: stop publishing the whole catalogue

Most MCP servers advertise every scope they have in scopes_supported, and most clients request all of them on first authorization. The result is a long-lived token with files, database and admin rights sitting in a client's token store, which is precisely the token worth stealing. The security guidance lists this as a mistake by name, along with wildcard scopes named all or full-access, and changing the meaning of a scope without versioning it.

The alternative is a deliberately thin baseline, something like a basic tools scope, plus escalation when a specific tool is actually called. The mechanism is already there: the server returns a 401 with a WWW-Authenticate header carrying the scope it needs, as defined in RFC 6750 section 3, and the client re-authorizes for that scope. Log those elevation events with a correlation ID, because the sequence of scopes an agent asks for over a session is one of the better signals you will get about what it is actually doing.

Be honest about the tension in this design. With no scope challenge to go on, a client's reasonable fallback is to request everything in scopes_supported. Step-up only reduces blast radius if your server really does issue narrow challenges and really does reject calls above the granted scope. Half an implementation is worse than none, because you have published the full catalogue and gained nothing.

Two client-side details matter if you write both ends. On re-authorization, request the union of what was already granted and what was newly challenged, or you will silently drop capability the user already approved. And cache denials, because an agent that re-requests a scope the user just refused will loop until something times out. On the server side, remember that an authorization server may issue a subset of what was requested, so your code must act on the scopes in the token it received rather than the ones it asked for.

06

Enforce in the resource, and never trust a handle

OWASP's Excessive Agency entry, LLM06 in the 2025 list, puts the conclusion better than most engineering blogs: implement authorization in downstream systems rather than relying on an LLM to decide if an action is allowed or not. It names three root causes, and they are worth checking your own design against. Excessive functionality, where a tool exposes operations the use case never needed. Excessive permissions, where the credential behind a tool is broader than the tool. Excessive autonomy, where the application fails to independently verify high-impact actions.

The permissions one is the cheapest to fix and the most commonly skipped. OWASP's own example is a read-only use case connecting to a database with an identity that also holds UPDATE, INSERT and DELETE. If a tool reads, give it a role that can only read. Tenant isolation belongs in row-level security or an equivalent at the data layer, not in a prompt instruction about which tenant the agent is serving. OWASP is also clear that logging, monitoring and rate limiting do not prevent excessive agency, though they limit the damage, so do not let a dashboard stand in for a permission boundary.

There is a related trap specific to agent plumbing. MCP at the 2026-07-28 revision is stateless with no protocol-level sessions, so servers that need continuity mint a handle, a cart ID or a workflow ID, and receive it back as a tool argument. The guidance is blunt: servers must not treat possession of a state handle as authentication, and must verify every inbound request. Generate handles from a secure random source, bind them server-side to the authenticated user by keying stored state as user ID plus handle where the user ID comes from the verified token and never from the client, and reject a handle presented by any other principal.

Finally, watch the client registration story, because it moved. Dynamic Client Registration is now marked deprecated and retained for backwards compatibility, and OAuth Client ID Metadata Documents are the path servers and clients should support. That changes what a client_id means to you. A metadata document proves control of a domain; it cannot prove which local process is listening on a loopback port, which is why the guidance tells authorization servers to warn on localhost-only redirect URIs and to display the redirect hostname during authorization. Treat a client identifier as a label for consent decisions, not as an authenticated identity you can authorize against.

07

Working with Darvi Labs

This is the unglamorous half of agentic engineering, and it is usually the half that decides whether a working prototype can go in front of real customer data. We build agent systems and the APIs behind them at Darvi Labs, which means token exchange brokers, MCP servers that validate their own audience, scope models that survive a security review, and the enforcement work in the database rather than the prompt.

If you are putting an agent in front of production systems and want a second pair of eyes on the authorization design before it ships, get in touch through the Contact page. Our other engineering write-ups, including pieces on multi-tenant isolation in PostgreSQL and on building MCP servers for the stateless specification, are on the blogs page, and recent work is on the portfolio page.

Next step

Thinking through a similar decision?

Send us the constraint, the workflow, or the decision that keeps resurfacing. We can help clarify what should change first.

Start a conversation→