Created
February 7, 2013 19:33
-
-
Save anonymous/4733505 to your computer and use it in GitHub Desktop.
Logout URL for Google App Engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LogoutPage(webapp2.RequestHandler): | |
def get(self): | |
target_url = self.request.referer or '/' | |
if os.environ.get('SERVER_SOFTWARE', '').startswith('Development/'): | |
self.redirect(users.create_logout_url(target_url)) | |
return | |
# On the production instance, we just remove the session cookie, because | |
# redirecting users.create_logout_url(...) would log out of all Google | |
# (e.g. Gmail, Google Calendar). | |
# | |
# It seems that AppEngine is setting the ACSID cookie for http:// , | |
# and the SACSID cookie for https:// . We just unset both below. | |
cookie = Cookie.SimpleCookie() | |
cookie['ACSID'] = '' | |
cookie['ACSID']['expires'] = -86400 # In the past, a day ago. | |
self.response.headers.add_header(*cookie.output().split(': ', 1)) | |
cookie = Cookie.SimpleCookie() | |
cookie['SACSID'] = '' | |
cookie['SACSID']['expires'] = -86400 | |
self.response.headers.add_header(*cookie.output().split(': ', 1)) | |
self.redirect(target_url) | |
app = webapp2.WSGIApplication( [ | |
(r'/logout', LogoutPage ), | |
], | |
debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment