使用 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 | 是否必填 | 说明 |
|---|---|---|
| Authorization | 是 | Bearer <Service Account Key> |
| Content-Type | 是 | application/json |
请求体参数
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
| ttl_seconds | integer | 否 | Token 有效期(秒),取值范围 1–43200(最长 12 小时)。省略时使用平台默认有效期。 |
| metadata | object | 否 | 业务元数据,用于标记 Token 用途,便于审计。 |
示例请求
示例响应
HTTP 201 Created
响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
| type | string | 固定为 service_account_token。 |
| access_token | string | 短期访问令牌。仅在本次响应中返回,请妥善保存。 |
| token_type | string | 令牌类型,固定为 Bearer。 |
| expires_in | integer | 有效期(秒)。 |
| expires_at | string | 过期时间,RFC 3339 格式。 |
| auth_token_id | string | Token 的唯一标识,吊销 Token 时使用。 |
| service_account_id | string | 签发该 Token 的 Service Account ID。 |
| credential_id | string | 签发该 Token 的 Service Account Key ID。 |
| subject_type | string | Token 主体类型。本接口返回 admin。 |
错误
| HTTP | Type | Code | 触发条件 |
|---|---|---|---|
| 400 | invalid_request_error | - | 请求体不合法,或 ttl_seconds 超出 1–43200。 |
| 401 | authentication_error | - | Service Account Key 无效、已过期,或使用了其他类型的凭证。 |
| 503 | api_error | - | 令牌签发服务暂不可用,请稍后重试。 |
备注
- Service Account Key 在 Qoder 控制台的 企业凭证 页面创建和管理,仅企业组织可用。
- Token 到期后自动失效,无法续期;请在到期前重新换取新 Token。
- 请勿将 Service Account Key 直接用于业务接口,业务接口只接受 PAT 或 Service Account Token。