First, I follow this guide https://developers.google.com/identity/sign-in/web/ and this link https://developers.google.com/identity/sign-in/web/reference .
But instead of having the callback declared in window , I used the gapi.signin2.render function to render the button and attach a handler to it in my Angular controller.
Logging in is working fine, the problem is that when I try to log out by calling gapi.auth2.getAuthInstance().signOut() , it just doesn't.
I noticed that sessionStorage for accounts.google.com still exists, and because of this, Google automatically signs me up when I click the button on the login screen again.
I tried to see what happens after signOut() :
gapi.auth2.getAuthInstance().signOut().then(function() { console.log(gapi.auth2.getAuthInstance().isSignedIn.get());
I also tried calling disconnect() instead of signOut() , knowing that it would deny access and it would remove the token from sessionStorage, but the user session still exists. This only happens after a page reload.
Here is my complete code:
$scope.logout = function() { //... gapi.auth2.getAuthInstance().signOut().then(function() { console.log(gapi.auth2.getAuthInstance().isSignedIn); }); }; $scope.processAuth = function(authResult) { console.log("success"); if(authResult.getAuthResponse().id_token) { // backend calls } }; $scope.renderSignInButton = function() { console.log(gapi.auth2); gapi.signin2.render('signInButton', { 'onsuccess': $scope.processAuth, // Function handling the callback. 'onfailure': $scope.signinFailed, // Function handling the callback. 'clientid': 'asdasdasd.apps.googleusercontent.com', 'scope': 'https://www.googleapis.com/auth/userinfo.email', 'cookiepolicy': 'single_host_origin' } ); }; $scope.renderSignInButton();
source share