Created
February 28, 2019 08:45
-
-
Save kohendrix/90eb4617388fa16cb9e9726ab40afdfd to your computer and use it in GitHub Desktop.
Google Sign-in callback functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| // called by google client | |
| function onSignIn(googleUser) { | |
| var id_token = googleUser.getAuthResponse().id_token; | |
| // never log these out on a real app | |
| console.log('id_token: ', id_token); | |
| var profile = googleUser.getBasicProfile(); | |
| console.log('ID: ' + profile.getId()); | |
| console.log('Name: ' + profile.getName()); | |
| console.log('Image URL: ' + profile.getImageUrl()); | |
| console.log('Email: ' + profile.getEmail()); | |
| // verification | |
| var xhr = new XMLHttpRequest(); | |
| xhr.open('POST', '/tokensignin'); | |
| xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | |
| xhr.onload = function() { | |
| console.log('Server returned: ' + xhr.responseText); | |
| }; | |
| xhr.send('idtoken=' + id_token); | |
| } | |
| // on sign out | |
| function signOut() { | |
| var auth2 = gapi.auth2.getAuthInstance(); | |
| auth2.signOut().then(function() { | |
| console.log('User signed out.'); | |
| }); | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment