-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
38 lines (36 loc) · 1.21 KB
/
index.html
File metadata and controls
38 lines (36 loc) · 1.21 KB
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
34
35
36
37
<html>
<head>
<title>Czcx's Oauth</title>
<script src="https://accounts.google.com/gsi/client" async defer></script>
</head>
<body>
<div id="backgroundOverlay"></div>
<div id="content">
<center></center>
<div id="header"></div>
<h1>Your Title Here</h1>
<div id="g_id_onload"
data-client_id="YOUR-CLIENT-ID"
data-callback="handleCredentialResponse">
</div>
<div class="g_id_signin" data-type="standard"></div>
</body>
<script>
function handleCredentialResponse(response) {
const idToken = response.credential;
const decodedToken = parseJwt(idToken);
const email = decodedToken.email;
const name = decodedToken.name;
console.log('User email is ' + email);
console.log('User name is ' + name);
//use email or name to get it for other things
function parseJwt(token) {
const base64Url = token.split('.')[1];
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
const jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
return JSON.parse(jsonPayload);
}
</script>
</html>