Feature
Build a Safer Token Lifecycle for Autonomous AI Agents
Design an OAuth 2.1 and DPoP lifecycle for AI agents using brokered credentials, narrow grants, safe refresh rotation, key recovery and revocation.
Impetuous · · 6 Min Read

An AI agent that publishes, edits, schedules or deletes content should use narrow OAuth grants through a deterministic credential broker, with DPoP binding supported tokens to a broker-held key. The model should never receive an access token, refresh token, authorization code, client secret or DPoP private key. OAuth controls what the client may do and for whom; DPoP reduces the usefulness of a stolen token; the resource API still authorizes every action.
Choose the authority, DPoP support and client type to see the required token path.
Agent Token Path
The default shows a user-delegated public client with provider DPoP support.
Authorization Code With PKCE and DPoP
- Use authorization code with PKCE for the user grant.
- Request a narrow, audience-specific access token and reject a non-DPoP token if sender constraint is required.
- Keep the private key in the broker and generate a fresh proof for every API request.
- The public-client refresh token is bound to the same DPoP key; serialize refreshes and replace rotated tokens atomically.
- If the key is lost, reauthorize or use a provider-documented migration path.
Source basis: OAuth 2.1 draft 16, RFC 9449, RFC 9700 and RFC 8693. Provider support and migration behavior remain deployment-specific.
As of September 25, 2026, OAuth 2.1 remains an Internet-Draft rather than a final RFC. Draft 16 consolidates practices including authorization code with PKCE, exact redirect URI matching, omission of the implicit and password grants, and sender-constrained or one-time-use refresh tokens for public clients. Implement against final standards such as the OAuth Security BCP where possible while tracking the OAuth 2.1 draft’s status and revisions.
Put a Credential Broker Between the Model and APIs
The model should propose operations, not handle credentials. Put OAuth client behavior, token storage and DPoP signing in a deterministic broker or tool gateway:
- The agent asks the broker to perform a named operation, such as
publish_draft. - Policy code maps that operation to an API, resource, account and minimum scope.
- The broker obtains or selects the appropriate access token.
- A protected signing component creates the DPoP proof.
- The broker calls the resource API and returns only the result the agent needs.
Keep credentials out of prompts, traces, tool output and retry messages. This boundary makes authorization reviewable: free-form model output cannot silently broaden a token’s scope or select a different account.
Classify the authority before choosing a grant. A user-authorized publishing assistant normally uses authorization code with PKCE. A scheduled house process acting only for the company may use client credentials if the provider supports that model. Do not turn a user grant into a generic service credential.
Where a downstream service must know both the user and the acting service, OAuth Token Exchange can represent delegation using subject and actor information. The standard distinguishes delegation from impersonation (RFC 8693).
Bind Narrow Tokens to a Broker-Held Key
Generate an asymmetric DPoP key in a non-exportable keystore where the runtime permits it. A practical isolation policy is one key per installation or workload instance, with separate grants for different tenants or users. Sharing one key across unrelated workloads increases the blast radius of a key compromise.
At the token endpoint, the client sends a freshly signed DPoP proof. A supporting authorization server can bind the resulting access token to the proof’s public key and return a token_type of DPoP.
For each protected-resource request, the client sends an Authorization header containing DPoP and the access token, plus a DPoP header containing a fresh signed proof JWT.
Each proof is request-specific. It includes a unique jti, issue time, HTTP method and target URI. When an access token is presented, the proof also includes the token’s SHA-256 hash in ath. A server can require a recent nonce. The resource server must verify the proof, token hash and key binding in addition to the token’s ordinary validity (RFC 9449). Do not cache one proof and attach it to retries or different requests.
Request one audience and the minimum useful scopes. A content token might be valid only for the publishing API with draft:write, rather than being accepted by analytics, billing and administration APIs. Resource Indicators let a client identify the intended protected resource so the authorization server can audience-restrict the token (RFC 8707). The OAuth Security BCP likewise recommends restricting tokens to the resources and actions required (RFC 9700).
Operate Every Token Lifecycle Stage
| Stage | Broker Behavior | Failure Policy |
|---|---|---|
| Grant | Use authorization code with PKCE for user delegation; record subject, client, consented resources and scopes. | Reject an unexpected issuer, redirect URI, resource or scope. |
| Issue | Request an audience-specific, short-lived access token with a DPoP proof. | If sender constraint is required, reject a response whose token_type is not DPoP; never silently downgrade to Bearer. |
| Use | Create a new proof for every request and keep the private key inside the signer. | On a DPoP nonce challenge, retry according to RFC 9449 with a newly generated proof. |
| Refresh | Serialize refreshes per grant and atomically store any replacement refresh token. | On invalid_grant, stop the job and require a new grant; do not loop. |
| Rotate Key | Create a new key and obtain tokens bound to it. | Do not assume an existing bound refresh token can migrate. Reauthorize or use a provider-documented migration mechanism before retiring the old key. |
| Revoke | Revoke the refresh token when an account is disconnected, a workload is retired or compromise is suspected; erase local tokens and key material. | Mark the grant unusable locally immediately, even if server-side propagation is not instantaneous. |
Serialize Refreshes and Replace Tokens Atomically
DPoP-bound refresh tokens need particular care. When a DPoP-supporting authorization server issues a refresh token to a public client that presented a DPoP proof, RFC 9449 requires that refresh token to be bound to the proof’s public key. The client must prove possession of the same key each time it refreshes.
Losing that key therefore means losing the ability to refresh. Treat key loss as a recovery event, not merely a signing error. Reauthorize the grant or follow a migration mechanism explicitly documented by the provider.
The OAuth Security BCP requires authorization servers to use sender constraint or rotation to detect refresh-token replay for public clients, and it recommends inactivity expiry. A deployment can use rotation alongside DPoP, but the broker must serialize concurrent refreshes and atomically replace the old token so its own workers do not present an invalidated token.
Revoke Locally Before Waiting for Propagation
Revocation is part of the operating path, not merely a dashboard control. Implementations of the standard revocation endpoint must support refresh-token revocation, while server policy determines whether related access tokens and the underlying grant are also invalidated. Propagation delays can occur (RFC 7009).
Mark a grant unusable in the broker before making the revocation request. Short access-token lifetimes can limit the residual window, but choose actual lifetimes from the action’s sensitivity and operational tolerance rather than copying a universal number. The available standards do not prescribe one lifetime suitable for every AI agent or publishing operation.
Keep Authorization and Safety Controls Outside DPoP
DPoP narrows one threat: replay of a token by a party that lacks the private key. It is not client authentication, user consent, authorization policy or full HTTP message signing. RFC 9449 binds the HTTP method and target URI, but not the request body, and relies on TLS for message integrity. Code running in a compromised client context may also be able to ask the legitimate signer to authorize malicious requests.
A publishing API must continue to enforce tenant, subject, audience, scope and object-level permissions. High-impact operations such as site deletion, bulk unpublishing, payment changes or credential management should require stronger policy, human approval or a separate grant. DPoP cannot make an over-scoped token safe.
Log lifecycle metadata rather than credentials: grant identifier, pseudonymous subject and actor, client ID, audience, scopes, token expiry, DPoP key thumbprint, refresh-family version, revocation reason and normalized error class. Never log raw tokens, proofs, authorization codes or private keys.
For opaque access tokens, a resource server can use the protected introspection endpoint to determine whether a token is active and inspect its authorization context (RFC 7662). RFC 9449 extends that response with cnf.jkt metadata for the public-key thumbprint of a DPoP-bound token, allowing the resource server to verify the key binding.
The resulting boundary is explicit: the agent proposes an operation, policy selects a narrow grant, the broker manages token state, and the signer proves possession for one HTTP request. A reusable credential never enters the agent context.