-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclient.js
31 lines (23 loc) · 890 Bytes
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import React, { Component } from 'react'
module.exports = function (options) {
const handleLogin = () => {
const { authServer, authPath, redirectUri, clientId, authArgs, state = "STATE" } = options;
location.href = `${authServer}${authPath}?response_type=code&client_id=${clientId}&state=${state}&redirect_uri=${encodeURIComponent(redirectUri)}${obj2url(authArgs)}`;
}
const buttonName = () => {
const { buttonName = "OAuth2登录" } = options;
return buttonName
}
const QssoComponent = () => (
<button onClick={handleLogin} className="btn-home btn-home-normal" >{buttonName()}</button>
)
this.bindHook('third_login', QssoComponent);
};
function obj2url(obj) {
if (typeof obj !== 'object') {
return '';
}
return '&' + Object.keys(obj).map(function (k) {
return encodeURIComponent(k) + '=' + encodeURIComponent(obj[k])
}).join('&')
}