Sign out of Google+ with JS

I am trying to add a Google+ login button on my site. The button works fine. I have an exit button. I hide the login button when the user logs in. My code is here:

<span id="signinButton"> <span class="g-signin" data-callback="signinCallback" data-clientid="******************" data-cookiepolicy="single_host_origin" data-requestvisibleactions="http://schema.org/AddAction" data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email"> </span> </span> &nbsp;&nbsp;&nbsp;&nbsp; <button id="revokeButton" onclick="gapi.auth.signOut()">Sign Out</button> <script> function signinCallback(authResult) { if (authResult['status']['signed_in']) { document.getElementById('signinButton').setAttribute('style', 'display: none'); console.log("User successfully logged in!!"); } else { console.log('Sign-in state: ' + authResult['error']); } } </script> <script> function disconnectUser(access_token) { var revokeUrl = 'https://accounts.google.com/o/oauth2/revoke?token=' + access_token; // Perform an asynchronous GET request. $.ajax({ type: 'GET', url: revokeUrl, async: false, contentType: "application/json", dataType: 'jsonp', success: function(nullResponse) { document.getElementById('signinButton').setAttribute('style', 'display: display'); // The response is always undefined. console.log("Success in logging out!"); }, error: function(e) { // Handle the error console.log(e); // You could point users to manually disconnect if unsuccessful // https://plus.google.com/apps } }); } </script> 

The problem is that I use gapi.auth.signOut () to log out ... it logs me out of the system, but registers the same user on Google+ again when updating. How to allow other users to enter my site. How to completely exit Google. I'm new to Javascript ... an example will help.

+5
source share
2 answers

The answer, as I understand it, is simple. When a user logs in for the first time, he is not registered on my site. Therefore, obviously, the user must log in. The next time the page refreshes ... Google+ checks if the user is registered in any of the Google services, such as gmail, etc., And forces the user to log in if the answer is correct. To check if this works ... sign out of any Google service (gmail, etc.) and try signing in to Google+. He will ask for credentials. Therefore, as soon as a user signs in to Google+, he / she does not have to constantly subscribe.

+2
source

This answer is more of a joke, but why don’t you try the hacker method of logging out a user from your google account by adding a hidden iframe to the body using src of https://accounts.google.com/Logout ?

It will refuse to display due to the X-Frame settings set to DENY, but will actually exit the system.

Single line with jquery:

 $('<iframe style="display: none" src="https://accounts.google.com/Logout"></iframe>').appendTo(document.body); 
0
source

All Articles