-
Notifications
You must be signed in to change notification settings - Fork 0
/
googleIdentityService.php
49 lines (43 loc) · 1.3 KB
/
googleIdentityService.php
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
<?php
$clientId = "YOUR_CLIENT_ID";
$redirectUri = 'http://localhost:8888/php-google-oauth2-demo/callback.php';
?>
<!DOCTYPE html>
<html>
<head>
<script src="https://accounts.google.com/gsi/client" onload="initClient()" async defer></script>
</head>
<body>
<script>
function onSuccess(response) {
console.log(`Well Done! Auth code = ${response['code']}`);
}
function onFailure(response) {
console.log(`Error: ${response['message']}`);
}
var client;
function initClient() {
// Use GIS Popup UX
client = google.accounts.oauth2.initCodeClient({
client_id: <?=$clientId?>,
scope: 'email profile',
ux_mode: 'popup',
callback: onSuccess,
// callback: (response) => {
// console.log(`Well Done! Auth code = ${response['code']}`);
// },
error_callback: onFailure
// error_callback: (response) => {
// cconsole.log(`Error: ${response['message']}`);
// },
});
// console.log("Finish initClient()");
}
function getAuthCode() {
// Request authorization code and obtain user consent
client.requestCode();
}
</script>
<button onclick="getAuthCode();">Continue with Google</button>
</body>
</html>