Skip to content

Instantly share code, notes, and snippets.

/gist:4733505
Created Feb 7, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.