OAuth2.0授权
标准的OAuth2.0授权流程接口。
请求方式
POST /api/v1/grant/oauth
请求参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| grant_type | string | 是 | 授权类型(authorization_code,refresh_token) |
| client_id | string | 是 | 客户端ID |
| client_secret | string | 是 | 客户端密钥 |
| code | string | 否 | 授权码(grant_type=authorization_code时必填) |
| refresh_token | string | 否 | 刷新令牌(grant_type=refresh_token时必填) |
| redirect_uri | string | 否 | 回调地址(与注册时一致) |
响应参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| access_token | string | 访问令牌 |
| token_type | string | 令牌类型(Bearer) |
| expires_in | int | 过期时间(秒) |
| refresh_token | string | 刷新令牌 |
| scope | string | 权限范围 |
请求示例
json
{
"grant_type": "authorization_code",
"client_id": "client123",
"client_secret": "secret123",
"code": "authcode123",
"redirect_uri": "https://example.com/callback"
}响应示例
json
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "refresh123456",
"scope": "read write"
}错误码
| 错误码 | 说明 |
|---|---|
| 400 | 参数错误 |
| 401 | 认证失败 |
| 403 | 客户端被禁用 |
| 500 | 服务器内部错误 |