-
Notifications
You must be signed in to change notification settings - Fork 0
/
login_example.html
65 lines (62 loc) · 2.41 KB
/
login_example.html
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!-- The top of file index.html -->
<!--TAKEN FROM https://developers.google.com/identity/sign-in/web/server-side-flow-->
<html>
<head>
<!-- BEGIN Pre-requisites -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
function start() {
gapi.load('auth2', function () {
auth2 = gapi.auth2.init({
client_id: '11589825117-sa1m73o6t85ti2fvn51a0f7f6kbjt6dd.apps.googleusercontent.com'
// Scopes to request in addition to 'profile' and 'email'
});
});
}
</script>
<script src="https://apis.google.com/js/client:platform.js?onload=start" async defer></script>
<!-- END Pre-requisites --><!-- Continuing the <head> section -->
</head>
<body>
<!-- Add where you want your sign-in button to render -->
<!-- Use an image that follows the branding guidelines in a real app -->
<button id="signinButton">Sign in with Google</button>
<!-- ... -->
</body>
<footer>
<script>
$('#signinButton').click(function () {
// signInCallback defined in step 6.
auth2.grantOfflineAccess({
"redirect_url": "postmessage"
}).then(signInCallback);
});
function signInCallback(authResult) {
if (authResult['code']) {
// TODO REMOVE IN PROD
console.log(authResult['code']);
// Hide the sign-in button now that the user is authorized, for example:
$('#signinButton').attr('style', 'display: none');
// Send the code to the server
$.ajax({
type: 'POST',
url: 'http://localhost:8080/_ah/api/yahtzee/v1/auth/user',
contentType: 'application/json',
success: function (result) {
// TODO REMOVE IN PROD
console.log(result);
// TODO Do something with the JWT returned from the server.
// Probably store it so you can send it with future requests.
},
processData: false,
data: JSON.stringify({
"auth_code": authResult['code']
})
});
} else {
// There was an error.
}
}
</script>
</footer>
</html>