NATSoauth.token.issue换发访问令牌

apps/openapi 的 token 端点回源:以授权码(或刷新令牌)换发访问令牌;形态由应用注册的 tokenType 决定。

Request Payload

消息格式:JSON

NameData TypeRequiredDescription
grantTypestringYesauthorization_code / refresh_token
codestringNo授权码(authorization_code 时必填)
refreshTokenstringNo刷新令牌(refresh_token 时必填)
clientIdstringYes客户端标识
clientSecretstringYes客户端密钥
redirectUristringNo回调地址(authorization_code 时校验一致)
type RequestBody = {
  /** authorization_code / refresh_token */
  grantType: string
  /** 授权码(authorization_code 时必填) */
  code?: string
  /** 刷新令牌(refresh_token 时必填) */
  refreshToken?: string
  /** 客户端标识 */
  clientId: string
  /** 客户端密钥 */
  clientSecret: string
  /** 回调地址(authorization_code 时校验一致) */
  redirectUri?: string
}
{
  "grantType": "authorization_code",
  "code": "ac_5Fd83jK02mQ9wL7x",
  "clientId": "cli_9f2ka81mdx",
  "clientSecret": "cs_8Wn3tXcV6mB1qL5rY9uH2eK4",
  "redirectUri": "https://analytics.xeegam.com/oauth/callback"
}

Response Payload

回复使用统一信封 {id, code, messages, result},其 result:

NameData TypeRequiredDescription
tokenTypestringYes应用声明的形态:jwt / opaque
accessTokenstringYes访问令牌(jwt 为 JWT 串,opaque 为随机串)
expiresInnumberYes访问令牌有效期(秒)
refreshTokenstringYes刷新令牌
scopesarrayYes令牌的 scope
type ResponseBody = {
  /** 应用声明的形态:jwt / opaque */
  tokenType: string
  /** 访问令牌(jwt 为 JWT 串,opaque 为随机串) */
  accessToken: string
  /** 访问令牌有效期(秒) */
  expiresIn: number
  /** 刷新令牌 */
  refreshToken: string
  /** 令牌的 scope */
  scopes: string[]
}
{
  "tokenType": "jwt",
  "accessToken": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "expiresIn": 7200,
  "refreshToken": "rt_oauth_c19f4e0a2b58d736",
  "scopes": [
    "user:profile:read",
    "orgs:list"
  ]
}

Response Code

回复使用统一信封 {id, code, messages, result},其 code 字段:

code Meaning Notes
0 成功 换发访问令牌
2703 clientSecret 不正确
2003 刷新令牌无效 refresh_token 场景

Examples

{
  "grantType": "authorization_code",
  "code": "ac_5Fd83jK02mQ9wL7x",
  "clientId": "cli_9f2ka81mdx",
  "clientSecret": "cs_8Wn3tXcV6mB1qL5rY9uH2eK4",
  "redirectUri": "https://analytics.xeegam.com/oauth/callback"
}
{
  "id": "01JD8SWTHS7U4VR",
  "code": 0,
  "messages": [],
  "result": {
    "tokenType": "jwt",
    "accessToken": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
    "expiresIn": 7200,
    "refreshToken": "rt_oauth_c19f4e0a2b58d736",
    "scopes": ["user:profile:read", "orgs:list"]
  }
}

Remarks

JWT 签名密钥经 JWKS 端点发布。授权码无效 / 已使用 / redirectUri 不一致时返回共享状态冲突码。