获取或刷新授权 Token 接口
POST/oauth/token
基本信息
- 请求路径:
/oauth/token
- 请求方法: POST
- 接口说明: 用于获取或刷新访问令牌(access_token)的统一接口
请求参数
Query 参数
参数名 | 必填 | 类型 | 说明 |
---|---|---|---|
grant_type | 是 | string | 授权类型。可选值: - 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 时必填 |
使用场景
- 获取新的访问令牌
- 设置 grant_type=authorization_code
- 提供 code、client_id 和 client_secret
- 刷新访问令牌
- 设置 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
- 200
成功响应