-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
34 lines (30 loc) · 933 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
32
33
import React from 'react';
module.exports = function (options) {
const handleLogin = () => {
const { redirectUri, clientId } = options;
const rootUrl = 'https://accounts.google.com/o/oauth2/v2/auth'
const params = {
redirect_uri: redirectUri,
client_id: clientId,
access_type: 'offline',
response_type: 'code',
prompt: 'consent',
scope: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email',
].join(' '),
state: 'test',
};
const qs = new URLSearchParams(params);
location.href = `${rootUrl}?${qs.toString()}`;;
}
const GoogleLoginComponent = () => (
<button
className="btn-home btn-home-normal"
onClick={handleLogin}
>
{options.buttonText ? options.buttonText : 'Sign In with Google'}
</button>
)
this.bindHook('third_login', GoogleLoginComponent);
};