跳到主要内容

获取或刷新授权 Token 接口

POST 

/oauth/token

基本信息

  • 请求路径: /oauth/token
  • 请求方法: POST
  • 接口说明: 用于获取或刷新访问令牌(access_token)的统一接口

请求参数

Query 参数

参数名必填类型说明
grant_typestring授权类型。可选值:
- authorization_code: 授权码模式,用于获取新token
- refresh_token: 刷新token模式,用于刷新已有token
code条件必填string授权码。当 grant_type=authorization_code 时必填
client_id条件必填string注册的客户端ID。当 grant_type=authorization_code 时必填
refresh_token条件必填string刷新令牌。当 grant_type=refresh_token 时必填

Body 参数

参数名必填类型说明
client_secret条件必填string注册的客户端密钥。当 grant_type=authorization_code 时必填

使用场景

  1. 获取新的访问令牌
    • 设置 grant_type=authorization_code
    • 提供 code、client_id 和 client_secret
  2. 刷新访问令牌
    • 设置 grant_type=refresh_token
    • 提供 refresh_token

示例

获取新token

POST /oauth/token?grant_type=authorization_code&code={code}&client_id={client_id}
Content-Type: application/json

{
"client_secret": "{client_secret}"
}

刷新token

POST /oauth/token?grant_type=refresh_token&refresh_token={refresh_token}

Request

Responses

成功响应

Response Headers