Skip to content
Request
Response

OAuth

OAuth 2.0 接口用于第三方应用授权。

授权端点

GET https://ai-tokenhub.com/oauth/authorize

请求参数

参数类型必填说明
client_idstring客户端 ID
redirect_uristring回调地址
response_typestring授权类型 (code)
scopestring权限范围
statestring状态参数

令牌端点

POST https://ai-tokenhub.com/oauth/token

请求体

参数类型必填说明
grant_typestring授权类型
codestring授权码
client_idstring客户端 ID
client_secretstring客户端密钥
redirect_uristring回调地址

授权码模式流程

1. 请求授权

https://ai-tokenhub.com/oauth/authorize?
  client_id=YOUR_CLIENT_ID&
  redirect_uri=https://yourapp.com/callback&
  response_type=code&
  scope=read:user%20write:api&
  state=random_state_string

2. 用户授权后回调

https://yourapp.com/callback?code=AUTH_CODE&state=random_state_string

3. 获取访问令牌

bash
curl -X POST https://ai-tokenhub.com/oauth/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d '{
    "grant_type": "authorization_code",
    "code": "AUTH_CODE",
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET",
    "redirect_uri": "https://yourapp.com/callback"
  }'

响应示例

json
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "dGhpcyBpcyBhIHJlZnJlc2ggdG9rZW4...",
  "scope": "read:user write:api"
}

刷新令牌

bash
curl -X POST https://ai-tokenhub.com/oauth/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d '{
    "grant_type": "refresh_token",
    "refresh_token": "REFRESH_TOKEN",
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET"
  }'

Scope 权限范围

Scope说明
read:user读取用户信息
write:user修改用户信息
read:api读取 API 使用量
write:api管理 API 密钥
read:billing读取账单信息
write:billing管理充值和订阅