第三方授权token登录
POST/auth/v1/signin/with/provider
接口说明
通过第三方授权信息生成的provider_token进行登录,支持自动注册新用户或绑定到现有用户
入参要求:
client_id: 应用对应的客户端id(可选,默认为环境id)x-device-id: 设备id(必填,请求头中传入)- 请求体参数(v1SignInWithProviderRequest):
provider_token: provider_token(必填,通过获取三方授权信息接口获取)force_disable_sign_up: 强制关闭自动注册(可选,默认false)sync_profile: 是否强制从第三方同步昵称等信息(可选,默认false)
前置条件:
- 需要先调用获取三方授权信息接口获取有效的provider_token
- provider_token必须在有效期内(默认1小时)
- 第三方身份源需要在云开发平台配置并启用
出参:
- 返回标准的token响应(access_token、refresh_token等)
- 如果用户不存在且自动注册开启,会自动创建新用户
- 如果用户已存在,会绑定第三方身份源到现有用户
第三方授权token登录请求示例
POST /auth/v1/signin/with/provider
x-device-id: device_123456
Content-Type: application/json
{
"provider_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJwcm92aWRlciI6ImdpdGh1YiIsInN1YiI6IjEyMzQ1Njc4OTAiLCJleHAiOjE3MzQ2ODIzNTd9.bVJ0cE1xTnBWc0R5QmhKa0xmR3pYY1ZiTm1Bc1FkRmdIaktsTXBPclN0VXZXeElaQWJDZERlRmZHaEhpSmpLa0xs",
"force_disable_sign_up": false,
"sync_profile": true
}
第三方授权token登录响应示例
{
"token_type": "Bearer",
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2FwaS5leGFtcGxlLmNvbSIsInN1YiI6Ijk4NzY1NDMyMTAxMjM0NTY3ODkiLCJhdWQiOiJkZW1vLWFwcC0yZjhhOWMzZTFiNGQiLCJleHAiOjE3MzQ2NzU4ODksImlhdCI6MTczNDY2ODY4OSwic2NvcGUiOiJ1c2VyIn0.dGhpc19pc19hX2Zha2Vfc2lnbmF0dXJlX2Zvcl9leGFtcGxlX3B1cnBvc2VzX29ubHlfZG9fbm90X3VzZV9pbl9wcm9kdWN0aW9uX2Vudmlyb25tZW50X3RoaXNfaXNfbm90X3JlYWxfdG9rZW5fZGF0YQ",
"refresh_token": "m.aB3cD4eF5gH6iJ7kL8mN9oP0qR1sT2uV3wX4yZ5aB6cD7eF8gH9iJ0kL1mN2oP3qR4sT5uV6wX7yZ8",
"expires_in": 7200,
"scope": "user sso",
"sub": "9876543210123456789"
}
使用流程:
- 用户完成第三方授权,获取授权码(code)
- 调用获取三方授权信息接口换取provider_token
- 调用此接口使用provider_token进行登录
- 返回标准的access_token和refresh_token
关键特性:
- 支持自动注册新用户(如果force_disable_sign_up为false)
- 支持绑定到现有用户账号
- 可以强制同步第三方用户信息到本地账号
- 支持多种第三方身份源(GitHub、微信、Google等)
注意事项:
- provider_token有效期较短,建议及时使用
- 如果用户已存在,会自动绑定第三方身份源
- 自动注册功能可以在云开发平台配置是否开启
- 同步用户信息功能可以更新本地用户的昵称、头像等信息
Request
Query Parameters
client_id string
应用对应的客户端id,默认为环境id,可以不传
Header Parameters
x-device-id stringrequired
设备id
- application/json
Body
provider_id 身份源id (string)required
provider_token 通过/auth/v1/provider/token获取的三方的providerToken (string)required
force_disable_sign_up 强制关闭自动注册。默认情况下,这里以服务器配置为准,如果客户端为了平滑升级可以配置为true。 (boolean)
sync_profile 是否强制从第三方同步昵称等信息 (boolean)
Responses
- 200
- 500
A successful response.
Response Headers
- application/json
- Schema
- Example (from schema)
Schema
token_type 访问令牌类型 (string)
统一返回 Bearer
access_token 用户的访问令牌 (string)
用于访问云开发HTTP API的令牌,长度4096位以内
refresh_token 用户的刷新令牌 (string)
access_token过期可通过refresh_token刷新获取新的access_token,过期时间默认为31天。长度128位以内
expires_in int32
access_token的过期时间,单位为秒
scope 授权范围 (string)
sub 用户的唯一id (string)
groups string[]
{
"token_type": "string",
"access_token": "string",
"refresh_token": "string",
"expires_in": 0,
"scope": "string",
"sub": "string",
"groups": [
"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...