Skip to content

刷新令牌

接口说明

使用刷新令牌获取新的访问令牌。

请求信息

  • Method: POST
  • Path: /v1/auth/refresh
  • 认证: 不需要

请求参数

json
{
  "refresh_token": "string"
}

响应示例

json
{
  "code": 0,
  "message": "success",
  "data": {
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "token_type": "Bearer",
    "expires_in": 86400
  }
}

错误情况

  • 401: 刷新令牌无效或过期
  • 400: 参数验证失败

示例代码

bash
curl -X POST http://localhost:8081/v1/auth/refresh \
  -H "Content-Type: application/json" \
  -d '{
    "refresh_token": "YOUR_REFRESH_TOKEN"
  }'
javascript
const response = await fetch('http://localhost:8081/v1/auth/refresh', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    refresh_token: refreshToken
  })
});

const data = await response.json();
const newAccessToken = data.data.access_token;
python
import requests

response = requests.post(
    'http://localhost:8081/v1/auth/refresh',
    json={
        'refresh_token': refresh_token
    }
)

data = response.json()
new_access_token = data['data']['access_token']

Released under the MIT License.