NATSoauth.token.issue换发访问令牌
Try it 面板需要启用 JavaScript。
apps/openapi 的 token 端点回源:以授权码(或刷新令牌)换发访问令牌;形态由应用注册的 tokenType 决定。
Request Payload
消息格式:JSON
| Name | Data Type | Required | Description |
|---|---|---|---|
| grantType | string | Yes | authorization_code / refresh_token |
| code | string | No | 授权码(authorization_code 时必填) |
| refreshToken | string | No | 刷新令牌(refresh_token 时必填) |
| clientId | string | Yes | 客户端标识 |
| clientSecret | string | Yes | 客户端密钥 |
| redirectUri | string | No | 回调地址(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:
| Name | Data Type | Required | Description |
|---|---|---|---|
| tokenType | string | Yes | 应用声明的形态:jwt / opaque |
| accessToken | string | Yes | 访问令牌(jwt 为 JWT 串,opaque 为随机串) |
| expiresIn | number | Yes | 访问令牌有效期(秒) |
| refreshToken | string | Yes | 刷新令牌 |
| scopes | array | Yes | 令牌的 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 不一致时返回共享状态冲突码。