Skip to main content
服务账号令牌

创建 Service Account Token

使用 Service Account Key 换取短期访问令牌(管理员主体)。
POST /api/v1/forward/service_account_tokens Service Account Token 是企业集成场景下调用 Forward API 的短期凭证。使用企业的 Service Account Key 调用本接口换取管理员主体的 Token,之后在业务请求的 Authorization 头中以 Bearer 方式携带该 Token 即可访问 Templates、Identities、Sessions 等管理接口。 如需以某个终端用户(Identity)的身份访问会话类接口,请使用为 Identity 创建 Service Account Token

请求头

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

请求体参数

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

示例请求

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

示例响应

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": "3f8a2b1c-6d4e-4f2a-9b7c-1e5d8a0c4b2f",
  "service_account_id": "sa_019f000000",
  "credential_id": "sak_019f000000",
  "subject_type": "admin"
}

响应字段

字段类型说明
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 主体类型。本接口返回 admin

错误

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

备注

  • Service Account Key 在 Qoder 控制台的 企业凭证 页面创建和管理,仅企业组织可用。
  • Token 到期后自动失效,无法续期;请在到期前重新换取新 Token。
  • 请勿将 Service Account Key 直接用于业务接口,业务接口只接受 PAT 或 Service Account Token。

相关