Log out using API

18,451 views
Skip to first unread message

payal patel

unread,
Oct 26, 2012, 12:48:20 PM10/26/12
to google-api-jav...@googlegroups.com
Hi,

I am using Google API Javascript Client to fetch google Analytics data to my site.
Once user logged in I want to show him Logout option so that user can logout from my site.

I have also looked at several Google API but I haven't has any success.

Does anyone have any suggestions ??

Thanks,
Payal.

Nick Fenwick

unread,
Oct 30, 2012, 2:18:20 AM10/30/12
to google-api-jav...@googlegroups.com
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.

Does that help?  Any better solutions would be welcome.

Brendan

unread,
Oct 30, 2012, 11:40:34 AM10/30/12
to google-api-jav...@googlegroups.com
Hi,

Since users use Google Accounts to authorize your apps, logging out of your app is equivalent to logging out of the Google Account. Typically developers will include a logout link to https://accounts.google.com/logout. If you'd like to do it programmatically Nick's suggestion will work, but I suggest only logging a user out in response to explicit user interaction.

Regards,
Brendan
Reply all
Reply to author
Forward
0 new messages