Recently, Authing released a new feature - a small program scan code to log on.
Applet scan code to log refers to the use Authing applet 身份管家
in the web client or other client performs micro letter sign in the current SDK supports only client JavaScript. To use other languages refer to HTTP interface specification .
Click here to immediately experience the applet code to log sweep
Note: Use a small program scan code login, please authing-js-sdk
upgrade to a v0.1.19
version of the above
Access Process
1. configuration applet information
Fill a small program in Authing console appId, secret and callback address, user login is successful scan code will be pulled back to fill in the address.
2. 使用SDK(authing-js-sdk)
In the authing-js-sdk
use of startWXAppScaning
the method ( authing-JS-sdk documentation ):
var Authing = require('authing-js-sdk');
// 对Client ID和Client Secret进行验证,获取Access Token
var auth = new Authing({
clientId: 'your_client_id',
secret: 'your_app_secret'
});
auth.then(function(validAuth) {
validAuth.startWXAppScaning({
mount: 'qrcode-node', //二维码挂载点的HTML元素ID,如不写则默认漂浮在文档中间
});
})
After completion of scan code will automatically jump to a user-configured URL.
Parameter Description
validAuth.startWXAppScaning({
mount: 'qrcode-node', // 二维码挂载点,如不写则默认漂浮在文档中间
redirect: true, // 是否执行跳转(在用户后台配置的URL),默认为true,相关用户信息回传至url上
onSuccess: function(res) {}, // 登录成功后回调函数,redirect为true时不回调此函数
onError: function(error) {}, // 登录失败后回调函数,一般为网络问题
interval: 1500, // 每隔多少秒检查一次,默认1500
tips: '搜索小程序 <strong>身份管家</strong> 扫码登录', // 提示信息,可写HTML
});
HTTP Interface Description
HTTP interface applicable to non-JavaScript platform, JavaScript developers can skip this section.
Log scan code requires the client to do two steps:
- Generate two-dimensional code
- The client status polling query scan code
Another step is the user searching 身份管家
small program scan code login, this Authing already done, developers do not need to worry about.
1. Generate two-dimensional code
Address: https: //oauth.authing.cn/oauth/wxapp/qrcode/: clientId random = RANDOM_STRING?
-
Request method:
GET
-
parameter:
{String} clientId
- Authing Application Id is about to log on
{String} random
- The client generates a random string
-
Return data:
-
{ "data": { "_id": "*********************", "client": "*********************", "oauth": "*********************", "oauthWithApplication": "*********************", "qrcode": "https://usercontents.authing.cn/wxapp/qrcode/SweuVjfoPwSUTVEUv.png", "expiredAt": "2018-07-16T12:56:03.000Z", "__v": 0, "createdAt": "2018-07-16T12:55:03.302Z", "redirect": "", "success": false, "used": false }, "code": 200 }
- Data in the data returned dimensional code address qrcode i.e., directly to the client display.
- If the process is successful, code 200, 200 are non-failure.
-
2. Status polling query scan code
Address: https: //oauth.authing.cn/oauth/wxapp/confirm/qr random = RANDOM_STRING?
-
Request method:
POST
-
parameter:
{String} random
- The first step in generating a two-dimensional code when the client generates a random string
-
Return data:
-
{ "data": { "code": 200, "message": "扫码登录成功", "data": { "_id": "*********************", "email": null, "emailVerified": false, "username": "ivy", "nickname": "ivy", "company": "", "photo": "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLkQc7PfrbBqFMib6lkPUxaA5UsMiadibfWQtKv0CBcKnH2khXicvUB9WB2ibYxN6GRTaTsQfPtlsAafBg/132", "browser": "", "token": "******************************************.*********************.*********************", "tokenExpiredAt": "Wed Aug 01 2018 15:59:42 GMT+0800 (CST)", "loginsCount": 14, "lastLogin": "Tue Jul 17 2018 15:59:42 GMT+0800 (CST)", "lastIP": "*********************", "signedUp": "Tue Jul 17 2018 11:15:03 GMT+0800 (CST)", "blocked": false, "isDeleted": false, "__typename": "ExtendUser" }, "redirect": "http://sample.authing.cn/#/redirect" }, "code": 200 }
redirect
Callback address of the user console Authing disposed in the developer may address this own callback- If the user has scan code, the code is 200, if the non-200, on behalf of the user does not scan the scan code or code failure
-