Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

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 flow with a new kind of client, what the consent screen should say about an agent, how authorization details shape the grant, how the token 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 code flow from the OAuth lessons, with a new kind of client and a few new questions.

The assistant is registered at the photo service as a confidential client. Its backend authenticates with a private key, 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 authentication and PKCE verifier, for an access token.

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 token, 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.

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 API 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.

You approve one album for the assistant. The token it receives names you and the assistant, and the photo API checks both on every request.

How long authority lasts

Authority given to an agent should last about as long as the task. Access tokens stay short, fifteen minutes in this example. A refresh token is issued only because the task will run while you are away, and it ends after the 24 hours the consent screen mentioned. When the assistant finishes the book, it revokes its own tokens rather than leaving them to expire, and the grant ends with the task.

Some connections are meant to last. The printer's yearly calendar in the OAuth lessons needs access every December, and a long-lived grant fits it. An errand is different. A standing grant left behind by every errand an agent has ever run is authority lying around, waiting to be found by whoever compromises the agent next. If an agent does need access that outlasts the task, it should ask for that explicitly, and the consent screen should say so.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

Which request limits the assistant most closely to its task of reading the Lisbon trip album? 1 of 3

Choose one answer.

A token has sub set to you and client_id set to assistant. The photo service's policy says agents may not delete albums. Can the photo API enforce that? 2 of 3

Choose one answer.

The photo book errand will take one afternoon while you are away. Which grant fits it best? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity