Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Token Exchange 与 Agent 身份(RFC 8693)

Agent 代表用户调用工具时的身份委托:持用户 token + Agent 服务身份,换取带委托链的短命 token。

Agent 一等身份

在后台「OAuth 客户端」编辑页给 M2M client 填写 Agent 身份(agent_id) 后,该 client 的 client_credentials token 携带 agent_id claim:

{
  "sub": "agent_manager",
  "aud": "agent_manager",
  "agent_id": "agent_007",
  "token_type": "client",
  "permissions": ["platform:run:create"]
}

client 停用(下线)后:签发立即停止,introspect 返回 active: false,已发 token 最长 15 分钟自然过期。

换取委托 token(OBO)

POST /oauth/token
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
&client_id=agent_manager
&client_secret=***
&subject_token=<用户的 access_token>
&resource=https://mcp.erp/api        # 可选,RFC 8707 指示器 → 新 token 的 aud
&scope=platform:run:create           # 可选,与用户权限取交集

响应:

{
  "access_token": "eyJ...",
  "issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
  "token_type": "Bearer",
  "expires_in": 900
}

委托 token 的 claims:

{
  "sub": "42",
  "preferred_username": "alice",
  "client_id": "agent_manager",
  "aud": "https://mcp.erp/api",
  "token_type": "delegation",
  "act": { "iss": "https://auth.ai-as.cc", "sub": "agent_manager", "agent_id": "agent_007" },
  "agent_id": "agent_007"
}
语义说明
sub原用户不变(OBO):资源服务器按“被代表的人“隔离与归因
actRFC 8693 §4.1 委托链,最外层 = 当前 actor;只含身份 claims
agent_id扁平便捷 claim,工具/网关直读
audresource 指示器,未传时继承原 token 的 aud
permissionsscope 参数与用户权限的交集;未传 scope 时继承用户权限
TTL默认 900 秒(DELEGATION_TOKEN_TTL_SECS 可配),不发 refresh

前置条件

client 须为机密 client 且 grant_typesurn:ietf:params:oauth:grant-type:token-exchange(后台 grant_types 标签中勾选 token-exchange)。

链式委托(Agent 的 Agent)

拿委托 token 再换一次,act 自动按规范嵌套(最外层 = 最新 actor,最内层 = 最初 actor):

{
  "act": {
    "sub": "agent_worker_b",
    "act": { "iss": "...", "sub": "agent_manager", "agent_id": "agent_007" }
  }
}

消费方做访问控制只看顶层 claims 与最外层 actor,嵌套链仅作审计线索(RFC 8693 §4.1)。

introspect

委托 token 与服务身份 token 均可在 introspect 响应中拿到 act / agent_id

POST /oauth/introspect
token=<委托 token>
{
  "active": true,
  "sub": "42",
  "username": "alice",
  "client_id": "agent_manager",
  "act": { "iss": "...", "sub": "agent_manager", "agent_id": "agent_007" },
  "agent_id": "agent_007"
}

审计

每次 exchange 落审计事件 TOKEN_EXCHANGED(subject + agent client + agent_id + resource),后台「审计日志」可查。工具级归因配合决策审计(见 Agent 资源授权)构成 人 → Agent → 工具 全链。