Skip to content
Workforce IdentityMarkdown

Let an agent act for a user

Let an agent use a user's access on their behalf, with tokens that name both the user and the agent, within limits you and the user set.

APIRFC 8693, RFC 9449

An email assistant, a scheduling agent or a coding agent working in someone’s repositories needs the user’s access, not its own. The user signs in to an app as usual; the agent swaps the user’s token for one that says this user, through this agent. Every API sees both, and can decide differently for an agent acting for someone than for the user themselves. The agent can never do more than the user could, or more than you allowed.

Before you start:

  • Who can do it: a realm administrator (a group holding RealmOwner).
  • Where: today this is done through the API, with your session in $CVYUH_SESSION (Call the API).
  • What you need: invoice-agent and its client invoice-agent-client are registered (see Register an agent). Here the agent acts for maya.
  1. Read the realm’s grant types:

    Terminal window
    curl https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
  2. Offer token exchange in the realm: send the grantTypes you just read, plus token exchange.

    Terminal window
    curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "grantTypes": ["…existing grant types", "urn:ietf:params:oauth:grant-type:token-exchange"] }'
  3. Let the agent’s client use it: read the client, and send its grantTypes plus the same value:

    Terminal window
    curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client/invoice-agent-client \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "grantTypes": ["client_credentials", "urn:ietf:params:oauth:grant-type:token-exchange"] }'
  4. Let the agent act for the user, limited in time and scope:

    Terminal window
    curl -X POST https://foobar.cvyuh.com/api/v0/am/objects/v1/agent/invoice-agent/relationships/actsFor \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{
    "targetId": "maya",
    "targetType": "user",
    "properties": {
    "validFrom": "<RFC 3339 time>",
    "validTo": "<RFC 3339 time>",
    "scopes": ["invoices:read"]
    }
    }'
  5. Allow delegation by policy. The realm’s delegation set starts empty, so without a policy every exchange is refused. This one allows any agent to use a delegation it holds:

    Terminal window
    curl -X POST "https://foobar.cvyuh.com/api/v0/am/objects/v1/policy?id=agents-may-delegate" \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{
    "active": true,
    "resources": ["delegation://*/*"],
    "actionValues": { "delegate": true },
    "subject": { "type": "JwtClaim", "claimName": "principal_type", "claimValue": "agent" }
    }'
  6. Link the policy to the delegation set and the delegation type:

    Terminal window
    curl -X POST https://foobar.cvyuh.com/api/v0/am/objects/v1/policy/agents-may-delegate/relationships/policySet \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "targetId": "delegation" }'
    curl -X POST https://foobar.cvyuh.com/api/v0/am/objects/v1/policy/agents-may-delegate/relationships/resourceType \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "targetId": "delegation" }'
  7. Optionally, limit how many agents may stack in one token. The default is 4, and an exchange that would nest deeper is refused:

    Terminal window
    curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/agentSettings/agentSettings \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H "Content-Type: application/json" \
    -d '{ "maxActDepth": 2 }'

The agent swaps maya’s access token at the token endpoint, proving itself with its key and, since an agent’s client is held to FAPI 2.0 by default (unless it attests), a DPoP proof:

Terminal window
curl https://foobar.cvyuh.com/oauth2/token \
-H "DPoP: <proof>" \
-d grant_type=urn:ietf:params:oauth:grant-type:token-exchange \
-d subject_token=<maya's access token> \
-d subject_token_type=urn:ietf:params:oauth:token-type:access_token \
-d scope=invoices:read \
-d client_id=invoice-agent-client \
-d client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer \
-d client_assertion=eyJ…

It gets an access token only, bound to the agent’s DPoP key and ending no later than the user’s. Its claims name both:

{
"sub": "<maya's id>",
"act": { "sub": "<invoice-agent's id>", "principal_type": "agent", "risk_class": "high", "...": "..." },
"mode": "delegated",
"scope": "invoices:read"
}

A second agent working for the first appears outside it: act names the newest agent, and its own act names the one before.

  • Naming the API. The agent may name it with resource, or with audience, which must be one of its client’s allowedResources (else invalid_target). Both may be sent only when they name the same one; otherwise the request is invalid_request.
  • No silent cut. Asking for more than allowed is invalid_scope.
  • Token types. The realm’s access tokens are JWTs, so a token type of …:token-type:jwt is taken wherever …:access_token is, for the token sent and for the one asked for.

The user sees nothing at the exchange. On their AI agents page they see every agent allowed to act for them, and their own audit trail lists every exchange made in their name.

Delete the agent’s actsFor link to the user. The user can do the same themselves: see Let users remove agents.