Skip to content

Instantly share code, notes, and snippets.

Created February 7, 2013 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4733505 to your computer and use it in GitHub Desktop.
Save anonymous/4733505 to your computer and use it in GitHub Desktop.
Logout URL for Google App Engine
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