-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.php
68 lines (63 loc) · 2.38 KB
/
test.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>
<title>Google Login Form</title>
</head>
<body>
<script src="https://accounts.google.com/gsi/client" async defer></script>
<div id="g_id_onload"
data-client_id="911384899570-6qiojk3cl3e47jjorfj9att0l1a8gg59.apps.googleusercontent.com"
data-callback="handleCredentialResponse">
</div>
<div class="g_id_signin" data-type="standard"></div>
<script>
function handleCredentialResponse(response) {
if (response.credential) {
const credential = response.credential;
const jwtToken = credential;
// Decode and parse the JWT token to access user details
const userTokenData = JSON.parse(atob(jwtToken.split('.')[1]));
console.log(userTokenData)
// Check if the required user details are available
if (userTokenData.email && userTokenData.name) {
const email = userTokenData.email;
const fullName = userTokenData.name;
const profilePicture = userTokenData.picture;
// Log user details to the console
console.log('Email: ' + email);
console.log('Full Name: ' + fullName);
console.log('Profile Picture: ' + profilePicture);
// Perform further actions with the user details as needed
// Now, let's post the data to the server using fetch
const url = 'api/google.php'; // Replace this with the correct endpoint URL
const data = {
email: email,
fullName: fullName,
profilePicture: profilePicture
};
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
// Handle the response from the server if needed
console.log('Server Response:', data);
})
.catch(error => {
console.error('Error posting data:', error);
});
} else {
console.log('User details not available in the token.');
}
} else {
// Handle the case where no credential is received or the user cancels the sign-in
console.log('No credential received or user canceled the sign-in.');
}
}
</script>
</body>
</html>