基于hivesigner的授权登录流程
当授权时,需要传值在地址栏上并跳转到他们的网站进行登录
//client_id 这是在 HiveSigner 仪表板中注册的应用程序的用户名
//redirect_uri 登录成功的回调地址
//scope 需要授权的权限
window.location.href=https://hivesigner.com/oauth2/authorize?
client_id=CLIENT_ID&redirect_uri=http://192.168.1.11:8080/&response_type=code&scope=vote,comment
当通过跳转成功登录后,然后通过地址栏的回调参数发送请求获取access_token、refresh_token、 expires_in、username。
let no = null,// access_toke
r = null,// refresh_token
i = null,// expires_in
u = null,// username
function n(e) {
var n = new RegExp("(^|&)" + e + "=([^&]*)(&|$)"),
t = window.location.search.substr(1).match(n);
return null != t ? unescape(t[2]) : null
}
code = n('code')
fetch(`https://hivesigner.com/api/oauth2/token`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
},
body: `code=${code}&client_secret=xxxxxxxxxxbfq911e7c99xxxxxxx`
}).then(res => {
res.json().then((json) => {
o = json.access_token;
r = json.refresh_token;
i = json.expires_in;
u = json.username;
}
}