完整接口列表

Authing 提供基于 REST 的扫码登录接口,开发者可以直接调用。

生成二维码

GET https://oauth.authing.co/qrcode/gene?userPoolId=xxx&scene=APP_AUTH&customVar1=xxx&customVar2=xxx

返回二维码 ID 和二维码链接。

Query Parameters

Name
Type
Description

customeVar

string

自定义数据字段,可填任意多个。

scene

string

场景值。为常量值,填 APP_AUTH。

userPoolId

string

用户池 ID。

{
    "code": 200, // 200 表示正常
    "message": "生成二维码成功",
    "data": {
        "qrcodeId": "5e061366445c9985e5bf890a", // 二维码 ID
        "qrcodeUrl": "https://usercontents.authing.co/qrcode/5e061366445c9985e5bf890a.png" // 二维码链接
    }
}

请求示例:https://oauth.authing.co/qrcode/gene?userPoolId=59f86b4832eb28071bdd9214&scene=APP_AUTH&customVar1=xxx&customVar2=xxx

生成的二维码:

使用在线二维码解码工具 查看二维码数据如下:其中 customVar1 和 customVar2 保存到了 userDefinedData 对象中。

查询二维码状态

GET https://oauth.authing.co/qrcode/check?qrcodeId=xxxx&scene=APP_AUTH

Query Parameters

Name
Type
Description

scene

string

场景值。为常量值,填 APP_AUTH。

qrcodeId

string

二维码 ID。

请求结果字段说明:

  • scanned: 二维码是否已经被扫描

  • expired:二维码是否已经过期

  • success:用户是否成功授权

  • canceled:用户是否取消授权

  • status

    • 0: 未知状态,即还未扫码,或者已经扫码但用户还没有点击同意授权或者取消授权。

    • 1: 用户同意授权

    • -1: 用户取消授权

  • userInfo:

    • 默认情况下,在用户扫码之后,会包含昵称(nickname)和头像(photo)两个字段

    • 开发者也可以配置返回完整用户信息(包括登录凭证 token)

  • ticket:用于换取完整用户资料。此字段只有在用户同意授权之后才会出现。详情见下文。

使用 ticket 换取用户信息

POST https://oauth.authing.co/oauth/scan-qrcode/exchangeUserInfoWithTicket

Request Body

Name
Type
Description

ticket

string

查询二维码状态接口返回的 ticket

注意:默认情况下,此接口只允许在服务器端调用,即需要使用用户池密钥初始化之后。

ticket 默认有效时间为 300 s。

开发者可在 Authing 控制台 基础配置 -> 基础设置 -> App 扫码登录 Web 自定义配置 处修改。详情见自定义配置项页。

自定义配置项

APP 端标记已扫码

POST https://oauth.authing.co/oauth/scan-qrcode/scanned

Headers

Name
Type
Description

Authorization

string

用户登录凭证。

Request Body

Name
Type
Description

qrcodeId

string

二维码 ID。

APP 端需要满足两个条件:

  1. 用户必须处于登录态

  2. 用户的用户池 ID 和二维码用户池 ID 匹配。

APP 端同意授权

POST https://oauth.authing.co/oauth/scan-qrcode/confirm

Headers

Name
Type
Description

Authorization

string

用户登录凭证。

Request Body

Name
Type
Description

qrcodeId

string

二维码 ID

APP 端需要满足两个条件:

  1. 用户必须处于登录态

  2. 用户的用户池 ID 和二维码用户池 ID 匹配。

APP 端取消授权

POST https://oauth.authing.co/oauth/scan-qrcode/cancel

Headers

Name
Type
Description

Authorization

string

用户登录凭证。

Request Body

Name
Type
Description

qrcodeId

string

二维码 ID

APP 端需要满足两个条件:

  1. 用户必须处于登录态

  2. 用户的用户池 ID 和二维码用户池 ID 匹配。

Last updated

Was this helpful?