Get or Refresh Authorization Token Interface
POST/oauth/token
Basic Information
- Request Path:
/oauth/token - Request Method: POST
- Interface Description: Unified interface for obtaining or refreshing access tokens (access_token)
Request Parameters
Query Parameters
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| grant_type | Yes | string | Grant type. Optional values: - authorization_code: Authorization code mode, used to obtain a new token- refresh_token: Refresh token mode, used to refresh an existing token |
| code | Conditional Required | string | Authorization code. Required when grant_type=authorization_code |
| client_id | Conditional Required | string | Registered client ID. Required when grant_type=authorization_code |
| refresh_token | Conditional Required | string | Refresh token. Required when grant_type=refresh_token |
form-data Parameters
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| client_secret | Conditional Required | string | Registered client secret. Required when grant_type=authorization_code |
Usage Scenarios
- Obtain a New Access Token
- Set grant_type=authorization_code
- Provide code, client_id and client_secret
- Refresh Access Token
- Set grant_type=refresh_token
- Provide refresh_token
Example
Obtain New Token
POST '/oauth/token?grant_type=&code=&client_id=&client_secret=&refresh_token=' \
--form 'client_secret=""'
Refresh Token
POST /oauth/token?grant_type=refresh_token&refresh_token={refresh_token}
Request
Query Parameters
grant_type stringrequired
Authorization Code Mode
code string
Authorization code
client_id string
Registered client ID
refresh_token string
Refresh token, required only when grant_type is refresh_token.
- multipart/form-data
Body
client_secretstring
Refresh Token. Required when grant_type=refresh_token
Example:
Responses
- 200
Successful Response
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"
}