Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google account logout and redirect

I am using openid to log the user in.(google account only). Now I have a sign out link in my page, which on clicking, I want the user to be logged out of google accounts and the page to be redirected to my home page. can this be done ??

Edit-
Changing the accepted answer because now Google allows redirecting [continuing] to any domain you want.

like image 546
Shrinath Avatar asked Nov 17 '10 06:11

Shrinath


2 Answers

I have solved this issue calling this function when the user click on the logout link:

var logout = function(){ document.location.href = "https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=http://www.example.com"; } 

When the user click on the link, the browser redirect the user to the logout page and only when the logout is complete, the user is redirected to the site "http://www.example.com".

I hope this can help.

like image 174
ira Avatar answered Oct 05 '22 16:10

ira


Challenges

Requesting https://www.google.com/accounts/Logout will log the user out. There is a continueUrl parameter that Google adds to that address sometimes, but it will only succeed to redirect the user when the target is some Google site, and not your own. This makes the approach unusable.

Furthermore the OpenID specification does not include global log out at this moment.

There is another way:

Suggestion

Include an IFrame on your page and use the onClick JavaScript event handler on the logout link to load https://www.google.com/accounts/Logout into the IFrame. After that (you might want to check whether the IFrame loaded succesfully), redirect the user to a logout procedure for your own site. After logging out let that page redirect to your home page.

The link might look a bit like this:

<a href="https://www.google.com/accounts/Logout"     onclick="myIFrame.location='https://www.google.com/accounts/Logout';StartPollingForCompletion();return false;">    log out</a> <iframe id="myIFrame"></iframe> 

You need to implement the StartPollingForCompletion() function to periodically check whether the logout page has loaded. use setTimeout() to time the poll, and check for some property on the IFrame (I don't know for sure which ones will work, because you're working cross-site here).

see also these questions:

OpenID. How do you logout

How to add logout feature to an OpenID enabled site?

like image 21
Joseph Tanenbaum Avatar answered Oct 05 '22 15:10

Joseph Tanenbaum