0

I'm building a php webaplication with a google based logon based on the tutorial on : https://www.youtube.com/watch?v=oxa581kKBNg everything works fin with one exception : logging out.

the log-out is based on unsetting the session variable. after this the aplication will request a new login.

but when i want to login again google assumes my last account used for login and i am not requested again for permissions.

also this makes is difficult to switch between different google accounts.

how can i force my log-out to forget the last used (google)account ?

  • 2
    Check out this answer: http://stackoverflow.com/a/12909563/357403 – Koshinae Jul 10 '15 at 10:21
  • Thanks ! it explains a lot. my fault was that i had only one google account active in the browser i was using for debugging. after adding an other google account i was prompted for the account i was going to use on the website i was logging in to. – Kasper Jan Mooijman Jul 10 '15 at 11:09
  • Possible duplicate of [How to Logout of an Application Where I Used OAuth2 To Login With Google?](http://stackoverflow.com/questions/12909332/how-to-logout-of-an-application-where-i-used-oauth2-to-login-with-google) – Prafulla Kumar Sahu Dec 17 '15 at 14:40

1 Answers1

0

I also ran into this problem, and came to the conclusion that there is no API support for logging out, amazingly enough.

We've solved it by inserting an iframe into our document that is hidden, and loads the 'logout' page that a user would normally visit. This is a pretty horrible solution but the only way I found that worked.

Create an iframe element from this HTML:

<iframe id="logoutframe" src="https://accounts.google.com/logout" style="display: none"></iframe>

(exactly how you do this will depend on your code infrastructure, whether you're using a javascript toolkit like jQuery or Dojo etc)

Add the iframe dom node to your document somewhere, and it'll process the logout for you.

I also discovered that there's no sensible way to detect if the user has logged out yet, because the iframe contents operate asynchronously. If you destroy it when the onLoad event fires, the job hasn't yet been done and the user will stay logged in. To avoid polling the gapi authentication system to see if the user is still logged in, I simply wait two seconds and then assume the logout is complete, and destroy the iframe.

Source: https://groups.google.com/forum/#!topic/google-api-javascript-client/PCs8xXV4wxk

shihab mm
  • 505
  • 5
  • 15