On-ramp · Lesson 09
OAuth gives a token a purpose: roles, scope, audience
An agent needs to read one customer's record. The CRM must not hand the agent a password, and it must not trust the agent with every customer. OAuth is the vocabulary for that: who asks, who decides, who issues, who serves, and what the token is for.
Four roles
OAuth 2.0 names four roles (RFC 6749, 2012):
| Role | In an agent deployment | Does |
|---|---|---|
| Resource owner | the person (or the organisation) whose data it is | grants or refuses |
| Client | the agent, or the gateway acting for it | asks for a token, presents it |
| Authorization server | the identity provider | authenticates, applies policy, issues tokens |
| Resource server | the CRM, the calendar, an MCP server | verifies the token and serves the request |
flowchart TD C["Client (agent)"] -->|"1. token request: who I am, which scope, which resource"| A["Authorization server"] A -->|"2. access token: sub, scope, aud, exp"| C C -->|"3. Authorization: Bearer token"| R["Resource server (CRM)"] R -->|"4. verify iss, aud, exp, scope; then answer"| C
The resource server never sees a password and never talks to the client's user. It checks a token against the issuer it trusts.
What a token for an agent usually is
Two flows cover this course:
- Authorization code (with PKCE, RFC 7636): a person signs in at the authorization server and consents; the client gets a token that acts for that person. MCP's authorization uses this.
- Client credentials (RFC 6749, section 4.4): no person. The client authenticates as itself and gets a token naming the client. This is an agent with an identity of its own (Module 12, lesson 1).
Three fields, three limits
| Field | Limits | Wrong if |
|---|---|---|
scope |
which operations (crm:read) |
it is *, or carries more than the task needs |
aud |
which server accepts it | missing, or the token is accepted by any server |
sub (and the actor chain) |
whom the action is attributed to | it names a shared service account that fifty agents use |
Resource indicators (RFC 8707, 2020) let the client name the audience in the request, and the authorization server put it in aud. Token exchange (RFC 8693, 2020) lets a service trade one token for another with a narrower scope and a different audience, which is how a gateway can hold a token for itself and hand the CRM one made for the CRM. The exchanged token can carry an act (actor) claim naming the party acting for sub, nested once per hop, so "the gateway, acting for agent-7, acting for Dana" is written in the token rather than inferred from logs. That nesting is the actor chain of the table above.
Expert: scope is a request, not a promise
A client asks for scopes; the authorization server grants what its policy allows, and a token may carry fewer than were asked. A resource server that assumes the requested scope was granted has checked its client's wishes. A second trap: a scope is only as meaningful as the server that interprets it. Two servers that both read read can mean different things. A third: a token exchange that widens. Exchange must only narrow; Module 12 builds and tests the check.
Check yourself
- Map the roles for this setup: a person asks an assistant agent to "summarise my open tickets"; the agent calls a ticketing MCP server through your gateway.
- A token has
aud= the gateway. The gateway needs the ticketing server to accept the call. What are the two correct ways to get a token the ticketing server accepts, and what is the incorrect one? scope: crm:readandaud: crm. Which of the two stops this token being replayed at the calendar, and which stops it deleting a record at the CRM?
Answers
- Resource owner: the person whose tickets they are. Client: the assistant agent, with the gateway acting for it on the outbound call. Authorization server: the identity provider where the person signs in and consents (authorization code with PKCE, since the token acts for that person). Resource server: the ticketing MCP server.
- Correct: the gateway exchanges its token for one with
aud= the ticketing server and a narrower scope (token exchange, RFC 8693, with anactclaim naming the gateway); or the client asks the authorization server for a token for the ticketing server directly, naming it as the resource (RFC 8707). Incorrect: forwarding the gateway's token unchanged and having the ticketing server skip or loosen its audience check. aud: crmstops replay at the calendar, which is not the audience.scope: crm:readstops the delete at the CRM, which is not a read. Each holds only if the server receiving the token checks it.