§ API REFERENCE

换取 access_token

POST/token换取 token

服务端用 api_secret 换取短期 access_token(client_credentials)。secret 仅此端点验证。

鉴权:x-app-id + Authorization: Bearer <api_secret>(secret 放请求头,禁入 URL)。
§ 1

请求信息

POST https://api.lingxiguangnian.com/api/open/v1/token

请求头

参数类型必填说明
x-app-idstringAPP 公开标识 app_key。
AuthorizationstringBearer <api_secret>。仅 /token 验证;secret 放请求头,禁入 URL / query / 前端 / 日志。

请求体参数

参数类型必填说明
grant_typestring固定 client_credentials。
§ 2

调用示例

curl -X POST "https://api.lingxiguangnian.com/api/open/v1/token" \
  -H "x-app-id: app_xxxxxxxx" \
  -H "Authorization: Bearer sk_xxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{ "grant_type": "client_credentials" }'
§ 3

返回结果

返回字段

参数类型必填说明
access_tokenstring明文 token(oat_ 前缀),作后续业务调用 Bearer;仅此一次返回。
token_typestring固定 Bearer。
expires_innumber有效期秒数(固定 7200 = 2h)。
scopestring授予 scope(空格分隔,= requested ∩ allowed)。
{
  "success": true,
  "data": {
    "access_token": "oat_xxxxxxxxxxxxxxxxxxxxxxxx",
    "token_type": "Bearer",
    "expires_in": 7200,
    "scope": "capabilities:read executions:write reports:read runtime:launch:write"
  }
}
§ 4

端点错误码

通用鉴权、scope 与限流错误见「使用概述」;下表为本端点专属错误。

HTTPerror_code触发条件
401open_api.unauthorizedapp_key / secret 错或 app 非 ACTIVE(统一,不分子原因)。
422open_api.grant_unsupportedgrant_type 非 client_credentials。
422open_api.no_granted_scopesrequested ∩ allowed 为空,无可签发 scope。
429open_api.rate_limited换发过频(防爆破)。
使用说明
  • secret 只展示一次,丢失只能在「密钥申请」轮换重发;轮换后旧 access_token 立即失效。
  • access_token 短期(2h);服务端缓存复用,临近过期再换。

契约真源:apps/m-master/src/app/api/open/v1/token/route.ts