Skip to main content
服务账号令牌

为 Identity 创建 Service Account Token

使用 Service Account Key 换取绑定指定 Identity 的短期访问令牌。
POST /api/v1/forward/identities/{identity_id}/service_account_tokens 以指定终端用户(Identity)的身份签发 Service Account Token。持有该 Token 的调用方将以此 Identity 的上下文访问 Forward 接口(如创建 Session、查询该 Identity 的配置),适合把 Token 下发给企业自有产品中的单个终端用户会话使用。 如需管理 Templates、Identities 等企业级资源,请使用创建 Service Account Token(管理员主体)。

请求头

Header是否必填说明
AuthorizationBearer <Service Account Key>
Content-Typeapplication/json

路径参数

参数类型是否必填说明
identity_idstringForward Identity ID。

请求体参数

参数类型是否必填说明
ttl_secondsintegerToken 有效期(秒),取值范围 1–43200(最长 12 小时)。省略时使用平台默认有效期。
metadataobject业务元数据,用于标记 Token 用途,便于审计。

示例请求

curl -s -X POST 'https://api.qoder.com/api/v1/forward/identities/idn_019eabc123/service_account_tokens' \
  -H "Authorization: Bearer $QODER_SA_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "ttl_seconds": 3600,
  "metadata": {
    "purpose": "identity runtime"
  }
}'

示例响应

HTTP 201 Created
{
  "type": "service_account_token",
  "access_token": "sat-example-token",
  "token_type": "Bearer",
  "expires_in": 3600,
  "expires_at": "2026-08-06T12:00:00Z",
  "auth_token_id": "8c1d4e7f-2a5b-4c8d-b3e6-9f0a1b2c3d4e",
  "service_account_id": "sa_019f000000",
  "credential_id": "sak_019f000000",
  "subject_type": "identity",
  "identity_id": "idn_019eabc123"
}

响应字段

字段类型说明
typestring固定为 service_account_token
access_tokenstring短期访问令牌。仅在本次响应中返回,请妥善保存。
token_typestring令牌类型,固定为 Bearer
expires_ininteger有效期(秒)。
expires_atstring过期时间,RFC 3339 格式。
auth_token_idstringToken 的唯一标识,吊销 Token 时使用。
service_account_idstring签发该 Token 的 Service Account ID。
credential_idstring签发该 Token 的 Service Account Key ID。
subject_typestringToken 主体类型。本接口返回 identity
identity_idstringToken 绑定的 Identity ID。

错误

HTTPTypeCode触发条件
400invalid_request_error-identity_id 为空、请求体不合法,或 ttl_seconds 超出 1–43200。
401authentication_error-Service Account Key 无效、已过期,或使用了其他类型的凭证。
403permission_error-目标 Identity 已被禁用。
404not_found_error-目标 Identity 不存在。
503api_error-令牌签发服务暂不可用,请稍后重试。

备注

  • Token 与 Identity 绑定:持有方只能以该 Identity 的身份访问接口,不能操作其他 Identity 的数据。
  • Identity 被禁用或删除后,对应 Token 的业务请求会被拒绝。
  • 建议按「一个终端用户会话一个 Token」的粒度签发,并设置贴合会话时长的 ttl_seconds

相关