Delegating authority to an agent
The assistant takes the delegate route. This lesson follows the grant you give it for one album: the authorization code flowThe main OAuth flow: the browser visits the authorization server, where the person signs in and approves access, then carries an authorization code back to the client, which exchanges it for tokens directly. When the client runs on a server, the tokens never pass through the browser. with a new kind of client, what the consent screen should say about an agent, how authorization details shape the grant, how the tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. names both you and the assistant, and why the authority should end with the errand.
A familiar flow, a new kind of client
When the assistant needs your album, it shows you a link: "Connect photos.example so I can read your Lisbon trip album." What happens after you select it is the authorization codeA short-lived, single-use value that the authorization server sends back to a client through the browser. The client swaps it for tokens in a direct request to the authorization server; APIs never accept it. flow from the OAuthA framework that lets a person give an application limited access to their resources at another service, using tokens instead of sharing their password. OAuth is about access; OpenID Connect adds sign-in. lessons, with a new kind of client and a few new questions.
The assistant is registered at the photo service as a confidential clientAn OAuth client, typically running on a backend, that can keep a credential such as a client secret or private key protected, and so can authenticate itself to the authorization server.. Its backend authenticates with a private keyThe half of a key pair that its owner keeps to themselves and uses to create signatures or decrypt data. Anyone who obtains it can act as its owner., and the browser part of the flow runs exactly as in the connection traced in Why use the authorization code flow?. You sign in at the photo service, approve the request, and the photo service sends an authorization code back through your browser. The assistant's backend exchanges the code, with its client authenticationChecking evidence that someone, or some application, controls an account, such as a password or a passkey. It establishes which account is being used, not what that account may do. and PKCEProof Key for Code Exchange, pronounced pixie: the client creates a secret for each authorization attempt, sends only a hash of it at the start, and proves it holds the secret when redeeming the code, so a stolen authorization code is useless to anyone else. verifier, for an access tokenA token that a client presents to an API to use access it has been granted, usually limited in what it allows and how long it lasts. It authorizes API calls; it does not tell the client who signed in..
What is new is how the assistant uses that access. It works while you are elsewhere, and the task may take a while. Laying out the pages, waiting for a price and placing the order could stretch over an afternoon. So the assistant may want a refresh tokenA longer-lived credential that a client sends to the authorization server, never to an API, to get new access tokens without asking the person again., as in The refresh token grant. Every refresh extends authority you granted once. A refresh token that lasts ninety days, issued for a task that takes one afternoon, leaves eighty-nine days of access that nobody needs except someone who steals it.
What consent should say
The consent screen comes from the photo service, not from the assistant, so it can describe the assistant using what the photo service knows from the assistant's registration. For an agent, it should say three things clearly:
assistant.example wants to:
Read the photos in your album "Lisbon trip"
for the next 24 hours
assistant.example is an AI assistant. It acts on its own,
without asking you before each step.
[Allow] [Deny]All domains, credentials, and tokens in these examples are fictional. The screen names who is asking, verified from the registration rather than taken from the request. It says that this client acts on its own, which changes how much thought a person should give to the request. And it describes the access precisely: one album, read only, for a day.
Compare that with "assistant.example wants to access your photos and albums." People shown requests like that many times learn to select Allow without reading. Grants, scopes, and consent explains how consent relates to the access a service actually grants. For agents, specific requests are what make consent mean something.
Shaping the grant
Scopes are coarse. A scope like photos.read covers every album you have, and the assistant needs one. Describing access with authorization details ran into the same problem when the printer needed only album 42. A rich authorization request lets a client describe the access it needs in structured detail, using an authorization_details parameter. The assistant's request, with its parameters on separate lines and the details shown decoded, looks like this:
https://auth.photos.example/authorize
?response_type=code
&client_id=assistant
&redirect_uri=https%3A%2F%2Fassistant.example%2Foauth%2Fcallback
&state=demo-attempt-81
&code_challenge=demo-pkce-challenge
&code_challenge_method=S256
&resource=https%3A%2F%2Fapi.photos.example
&authorization_details=[{
"type": "photo_album",
"locations": ["https://api.photos.example"],
"actions": ["read"],
"datatypes": ["images", "captions"],
"identifier": "73"
}]The details name the photo APIAn application programming interface: a defined way for software to interact with a service. A web API offers endpoints where other programs send HTTP requests. in locations, one action, the kinds of data the assistant will read, and one album, the Lisbon trip album with the identifier 73. The resource parameter names the API the token is for, so the token's audience will be the photo API and nothing else. The type photo_album and its fields are defined by the photo service, the same type the printer used for album 42. The standard defines how details are carried, and each service decides what kinds of access it can describe.
The printer will need its own grant when the time comes to order. There, authorization details can describe one order with a spending limit:
[{
"type": "photo_book_order",
"actions": ["create"],
"max_amount": { "currency": "USD", "value": "60.00" }
}]Because the limit is part of the grant, the printer checks it when the order arrives: a book priced at $64 is refused whatever the assistant decided, and an assistant fooled into ordering something else cannot spend more than you allowed. The parameters themselves work as Describing access with authorization details and Selecting the intended resource showed.
Both names in the token
After you approve, the assistant receives an access token. Decoded, it says:
{
"iss": "https://auth.photos.example",
"sub": "user-2048",
"aud": "https://api.photos.example",
"client_id": "assistant",
"authorization_details": [{
"type": "photo_album",
"locations": ["https://api.photos.example"],
"actions": ["read"],
"datatypes": ["images", "captions"],
"identifier": "73"
}],
"iat": 1790863320,
"exp": 1790864220
}The subject is you, and the client is the assistant. In this direct flow, the client ID identifies who is acting. When a token is produced by exchanging another, as in Keeping context across services, the acting party appears in an act claim instead. Either way, the photo API sees both whose authority this is and which software is using it.
That lets the photo API apply its own rules on top of what you approved. The photo service knows from its registration records that assistant is an AI agent. Its policy might say that agents may read and create drafts but never delete or share, whatever a consent screen allowed. The API enforces those rules on every request, because it can see the actor in every token.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Delegate a narrow errand, renew it and then remove its authorityAllow the fixed agent one errand with the authorization code flow, find both names in its token record, renew it with a refresh token, then stop it and see its launch refused.