# OIDC 短期身份令牌

> 从 Agent 本地 socket 获取签名 JWT，并按 audience、主体和运行范围授权。

- 网址：https://funcoding.ai/agents/cursor/cloud/identity/
- 核实日期：2026-10-18（命令、配置和价格以官方文档为准）
- 官方来源：[Cursor 官方文档：OIDC tokens](https://cursor.com/docs/cloud-agent/identity)

---
OIDC token 让运行中的 Agent 向云平台或内部服务证明身份，无需保存长期 key。它通过执行机器的本地 Unix socket 获取，与外部 Cloud Agents API 的 API Key 认证不同。

## 获取令牌

下面命令由运行环境中的 Agent 或脚本执行：

```bash
curl --unix-socket "${CURSOR_AGENT_SOCKET}" \
  -H 'Content-Type: application/json' \
  -d '{"aud":"sts.amazonaws.com"}' \
  http://cursor-agent/v1/tokens/oidc
```

托管 VM 的 CURSOR_AGENT_SOCKET 为 /run/cursor/api.sock；URL hostname 被忽略。请求必须 POST JSON，body 最多 4 KB，aud 为无空白的可打印 ASCII，最长 512 字符。

响应包含 token 和 Unix 秒 expires_at，有效期 5 分钟，无 refresh endpoint，到期重新 mint。可选 nonce 用于验证方的重放绑定；可选 sub_claim 将支持的 claim 投影为 `<name>:<value>` 主体，目前支持 team_id、organization_id、environment_id，缺值或不支持会失败。

## 验证方配置

| 配置 | 当前地址 |
| --- | --- |
| Issuer | https://api.cursor.com |
| Discovery | https://api.cursor.com/.well-known/openid-configuration |
| JWKS | https://api.cursor.com/keys |

验证 RS256 签名、kid、iss、预期 aud、nbf/exp 和授权主体。Cursor 不限制请求者选择 aud，所以接收端必须拒绝其他 audience；旧 api2.cursor.sh/cloud-agent/identity 仍提供 discovery，但已不是新 token 的 issuer。

默认 sub 为 user:<id> 或 service_account:<id>，不是 email。repo_url 仅为主仓库，需要限制全部仓库时检查完整 repo_urls；该字段缺失不表示单仓。turn 与 branch claim 只有对应值存在时才出现。

## 自托管与信任范围

worker 默认不提供身份 socket（claim token 不需要 socket，见上一节），需要 `agent worker --identity-socket start`，pool 也使用此开关。每个 claim 有独立 socket，token 带 agent_runtime:self_hosted，托管为 managed。

token 代表整个运行，能访问 socket 的代码、Hooks 和 Agent 都可 mint；自托管同一 OS 用户的其他进程也可访问。它不证明某条调用只来自模型本身，授权范围应按整个运行确定。

## Claim tokens

Team Pool controller 在 claim 待处理请求时（还没启动任何 worker）也能拿到 token。它告诉你的系统这次 claim 对应哪个 Agent 和哪个 owner，可以先核对两者再创建机器或发凭据。controller 用服务账号 API key 请求，不经过 socket；内置 controller 用 `--identity-audience` 在每次 claim 时请求。

在 claim 请求体里加 `identityToken`，`audience` 必填，每次 claim 发一个新的 `nonce`：

```bash
curl --request POST \
  --url "https://api.cursor.com/v0/private-workers/claim" \
  -u "$CURSOR_API_KEY:" \
  --header 'Content-Type: application/json' \
  --data '{
    "id": "bc-00000000-0000-0000-0000-000000000002",
    "workerId": "pw_123",
    "identityToken": {
      "audience": "https://provisioner.example.com",
      "nonce": "3f9c1e7a-claim-pw_123"
    }
  }'
```

响应的 `identityToken.token` 是 JWT，有效期 5 分钟，`expiresAt` 与 JWT 的 exp 一致。audience 写进 JWT 的 aud，nonce 原样写进 nonce claim，两者都是可打印 ASCII，最长 512 字符；Cursor 不限制 audience 取值。签发失败时什么都不会被 claim：

| 状态码 | 含义与处理 |
| --- | --- |
| 403 | 这个 Agent 不允许签发 token，不要重试 |
| 429 | 超过每个 Agent 每分钟 30 个 claim token，按 Retry-After 重试 |
| 503 | 签名服务不可用，退避重试 |
| 409 | 不返回 token、不签名：workerId 被其他 Agent 占用，或之前一次 claim 已生效但响应丢失；响应丢失时先 release claim 再重新 claim |

claim token 用独立的 issuer：

| 配置 | 地址 |
| --- | --- |
| Issuer | https://api.cursor.com/self-hosted/claims |
| Discovery | https://api.cursor.com/self-hosted/claims/.well-known/openid-configuration |
| JWKS | https://api.cursor.com/keys（与 socket token 相同） |

只认 `https://api.cursor.com` 的验证方（如官方 AWS IAM 示例）会拒绝 claim token，只给应当接受它的服务加这个 issuer。claim token 的 claim 与 socket token 相同，区别是：iss 为上面的 claim issuer；agent_runtime 为 self_hosted；worker_id 是 claim 的 workerId；sub 和 owner 相关 claim 指 Agent 的 owner，不是发起 claim 的服务账号，sub 总是 user:<id> 或 service_account:<id>。claim discovery 的 x_cursor_sub_claims_supported 为空，因为 claim 请求不接受 sub_claim。

验证时至少检查：RS256 签名和 JWKS 的 kid；iss；aud 是你发送的 audience；nbf/exp（允许少量时钟偏差）；nonce 是本次 claim 发送的值；cloud_agent_id 和 worker_id 与 claim 的 id、workerId 一致；team_id 是你的团队。用 sub 或 owner_user_id 识别用户，不用 owner_email（邮箱会变）。Cursor 不记录 token 是否用过，需要一次性时自己保存 jti（或 nonce），在过期前拒绝重复使用。

持有 pool 服务账号 key 的人，能在 key 的仓库范围内 claim 团队的待处理请求，并拿到写着发起人名字的 token。key 只留在 controller 上，只接受预期 audience 的 claim token。

## 频率与错误

每个 claimed Agent 每分钟最多 30 次，突发最多 10；socket 最多 8 个并发连接，托管环境与 metadata 共用。缓存尚未过期 token，避免每个 API 调用都 mint。

429、503、500、502、504 使用退避重试并遵循 Retry-After；403 视为不可继续的授权失败。换取 AWS/GCP 等服务凭据仍需出站网络，即使 mint 本身走本地 socket。
