获取或刷新授权 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 时必填 |
form-data 参数
| 参数名 | 必填 | 类型 | 说明 |
|---|---|---|---|
| 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=&code=&client_id=&client_secret=&refresh_token=' \
--form 'client_secret=""'
刷新token
POST /oauth/token?grant_type=refresh_token&refresh_token={refresh_token}
Request
Query Parameters
grant_type stringrequired
授权码模式
code string
授权码
client_id string
注册的客户端 ID
refresh_token string
刷新令牌,仅在 grant_type 为 refresh_token 时必传
- multipart/form-data
Body
client_secretstring
刷新令牌。当 grant_type=refresh_token 时必填
Example:
Responses
- 200
成功响应
Response Headers
- application/json
- Schema
- Example (auto)
- Example
Schema
access_tokenstring
expires_ininteger
refresh_tokenstring
scopestring
created_atstring
{
"access_token": "string",
"expires_in": 0,
"refresh_token": "string",
"scope": "string",
"created_at": "string"
}
{
"access_token": "eyPZPVNfsibj9tap_ibj3t3p",
"expires_in": 1296000,
"refresh_token": "b77ced3aee884348852160deab3697a1",
"scope": "all_user all_key all_groups all_projects all_pr all_issue all_note all_hook all_repository",
"created_at": "2024-04-20T09:07:59.889Z"
}