Skip to content

Instantly share code, notes, and snippets.

@kohendrix
Created February 28, 2019 08:45
Show Gist options
  • Select an option

  • Save kohendrix/90eb4617388fa16cb9e9726ab40afdfd to your computer and use it in GitHub Desktop.

Select an option

Save kohendrix/90eb4617388fa16cb9e9726ab40afdfd to your computer and use it in GitHub Desktop.
Google Sign-in callback functions
<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