1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+
4+ < head >
5+ < meta charset ="UTF-8 ">
6+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7+ < meta http-equiv ="X-UA-Compatible " content ="ie=edge ">
8+ < title > Google Sign-In Demo</ title >
9+
10+ < script src ="https://apis.google.com/js/platform.js " async defer > </ script >
11+ < meta name ="google-signin-client_id " content ="219758474264-vh1bibcphgvbc32km508lubtqkanikf1.apps.googleusercontent.com ">
12+
13+ </ head >
14+
15+ < body >
16+
17+
18+ < div class ="g-signin2 " data-onsuccess ="onSignIn "> </ div >
19+
20+
21+ < a href ="# " onclick ="signOut(); "> Sign out</ a >
22+ < script >
23+ function signOut ( ) {
24+ var auth2 = gapi . auth2 . getAuthInstance ( ) ;
25+ auth2 . signOut ( ) . then ( function ( ) {
26+ console . log ( 'User signed out.' ) ;
27+ } ) ;
28+ }
29+ </ script >
30+
31+
32+ < script >
33+ function onSignIn ( googleUser ) {
34+ var profile = googleUser . getBasicProfile ( ) ;
35+ console . log ( 'ID: ' + profile . getId ( ) ) ; // Do not send to your backend! Use an ID token instead.
36+ console . log ( 'Name: ' + profile . getName ( ) ) ;
37+ console . log ( 'Image URL: ' + profile . getImageUrl ( ) ) ;
38+ console . log ( 'Email: ' + profile . getEmail ( ) ) ; // This is null if the 'email' scope is not present.
39+
40+
41+ var id_token = googleUser . getAuthResponse ( ) . id_token ;
42+
43+ console . log ( id_token ) ;
44+
45+
46+ var xhr = new XMLHttpRequest ( ) ;
47+ xhr . open ( 'POST' , '/google' ) ;
48+ xhr . setRequestHeader ( 'Content-Type' , 'application/x-www-form-urlencoded' ) ;
49+ xhr . onload = function ( ) {
50+ console . log ( 'Signed in as: ' + xhr . responseText ) ;
51+ } ;
52+ xhr . send ( 'idtoken=' + id_token ) ;
53+
54+ }
55+ </ script >
56+
57+ </ body >
58+
59+ </ html >
0 commit comments