跳转至

获取或刷新授权 Token 接口

PSOT https://atomgit.com/oauth/token

调用通过此接口,用于获取或刷新访问令牌(access_token)的统一接口

请求参数

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

响应参数

字段 类型 必返 可为空 说明
access_token string 是 否 访问令牌(access_token)
expires_in string 是 否 过期时间
refresh_token string 是 否 刷新令牌(refresh_token)
scope string 是 否 scope权限范围
created_at string 是 否 创建日期

失败响应

接口可能返回以下失败响应:

400 参数错误

{
  "errorCode": "BAD_REQUEST",
  "errorCodeName": "Bad Request",
  "errorMessage": "page must be greater than 0"
}

401 未认证

{
  "errorCode": 401,
  "errorCodeName": "UNAUTHORIZED",
  "errorMessage": "Unauthorized"
}

HTTP 响应状态码

状态码 说明
200 成功(OK)
400 参数错误(Bad Request)
401 未认证(Unauthorized)
403 禁止访问(Forbidden)
404 未找到(Not Found)
429 请求过于频繁(Too Many Requests)
500 系统内部错误(Internal Server Error)

请求示例

cURL

curl -L -X POST 'https://atomgit.com/oauth/token' \
-H 'Content-Type: multipart/form-data' \
-H 'Accept: application/json'

JavaScript

const myHeaders = new Headers();
myHeaders.append("Content-Type", "multipart/form-data");
myHeaders.append("Accept", "application/json");

const requestOptions = {
  method: "POST",
  headers: myHeaders,
  redirect: "follow"
};

fetch("https://atomgit.com/oauth/token", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));

响应示例

状态码: 200

{
  "access_token": "string",
  "expires_in": 0,
  "refresh_token": "string",
  "scope": "string",
  "created_at": "string"
}

错误码

错误码 说明
200 成功(OK)
400 参数错误或请求无法解析(如 page / per_page 取值非法)
401 未认证或凭证无效
403 禁止访问
404 请求路径不存在
405 请求方法不支持
429 请求过于频繁,触发限流
500 系统内部错误

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc