获取三方授权信息
POST/auth/v1/provider/token
接口说明
获取第三方服务的授权信息,通过OAuth登录获取OAuth客户端对应的授权用户信息,生成provider_token
入参要求:
client_id: 应用对应的客户端id(可选,默认为环境id)x-device-id: 设备id(必填,请求头中传入)- 请求体参数(v1GrantProviderTokenRequest):
provider_id: 身份源id(必填,如:github、wechat等)provider_code: 第三方系统获取的登录code(必填,用于换取用户身份)provider_redirect_uri: 身份源回调地址(可选)
前置条件:
- 需要先通过第三方授权流程获取授权码(code)
- 第三方身份源需要在云开发平台配置
出参:
- 返回provider_token和provider_profile信息(v1GrantProviderTokenResponse)
- provider_token用于后续登录接口调用
- provider_profile包含第三方用户的基本信息
获取三方授权信息请求示例
POST /auth/v1/provider/token
x-device-id: device_123456
Content-Type: application/json
{
"provider_id": "github",
"provider_code": "authorization_code_from_github",
"provider_redirect_uri": "https://your-app.com/callback"
}
获取三方授权信息响应示例
{
"provider_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJwcm92aWRlciI6ImdpdGh1YiIsInN1YiI6IjEyMzQ1Njc4OTAiLCJleHAiOjE3MzQ2ODIzNTd9.bVJ0cE1xTnBWc0R5QmhKa0xmR3pYY1ZiTm1Bc1FkRmdIaktsTXBPclN0VXZXeElaQWJDZERlRmZHaEhpSmpLa0xs",
"expires_in": 3600,
"provider_profile": {
"provider_id": "github",
"sub": "1234567890",
"name": "张三",
"picture": "https://avatars.githubusercontent.com/u/1234567890",
"email": "zhangsan@example",
"provider": "github"
}
}
使用流程:
- 用户完成第三方授权后,获取授权码(code)
- 调用此接口使用授权码换取provider_token
- 使用provider_token调用第三方授权信息登录接口完成登录
关键特性:
- provider_token有效期为3600秒(1小时)
- 返回的provider_profile包含第三方用户的完整信息
- 支持自动注册新用户(如果用户不存在)
- 支持绑定到现有用户账号
Request
Query Parameters
client_id string
应用对应的客户端id,默认为环境id,可以不传
Header Parameters
x-device-id stringrequired
设备id
- application/json
Body
provider_id 身份源id, 如wx_open,或小程序appid (string)required
provider_redirect_uri 身份源回调地址 (string)
provider_code 第三方系统获取的登录code, 用来换取用户身份 (string)
Responses
- 200
- 500
A successful response.
Response Headers
- application/json
- Schema
- Example (from schema)
Schema
provider_token 如果不启用自动注册, 则返回 provider_token, 用于进一步处理,例如:通过手机号等。 (string)
expires_in int32
provider_profile object
provider_id 身份源id (string)
sub 主ID, 标识用户唯一标识 (string)
name 姓名 (string)
picture 头像 (string)
email 邮箱 (string)
phone_number 手机号 (string)
gender 性别 (string)
locale 地区 (string)
url 邮箱 (string)
groups string[]
sub_id sub_id 如果客户选需要SLO,可能需要返回sub_id, 可以参考:urn:oasis:names:tc:SAML:attribute:subject-id (string)
token provider 返回的 token,比如:oauth 模式下,该token为 refresh_token (string)
at_hash at hash of provider profile (string)
meta object
object
property name* string
raw 三方信息原文 (string)
provider 身份源类型 (string)
{
"provider_token": "string",
"expires_in": 0,
"provider_profile": {
"provider_id": "string",
"sub": "string",
"name": "string",
"picture": "string",
"email": "string",
"phone_number": "string",
"gender": "string",
"locale": "string",
"url": "string",
"groups": [
"string"
],
"sub_id": "string",
"token": "string",
"at_hash": "string",
"meta": {},
"raw": "string",
"provider": "string"
}
}
An unexpected error response.
Response Headers
- application/json
- Schema
- Example (from schema)
Schema
error 错误信息 (string)
error_code int32
error_description 错误描述 (string)
{
"error": "string",
"error_code": 0,
"error_description": "string"
}
Loading...