How to remove user cookie using python on application engine?

I am using python facebook api in Google App Engine (webapp). I want the user cookie to expire when the user exits the application. This cookie is set by the Facebook Javascript API.

Here is the facebook api function showing how the facebook api accesses the facebook cookie:

def get_user_from_cookie(cookies, app_id, app_secret): cookie = cookies.get("fbs_" + app_id, "") if not cookie: return None args = dict((k, v[-1]) for k, v in cgi.parse_qs(cookie.strip('"')).items()) payload = "".join(k + "=" + args[k] for k in sorted(args.keys()) if k != "sig") sig = hashlib.md5(payload + app_secret).hexdigest() expires = int(args["expires"]) if sig == args.get("sig") and (expires == 0 or time.time() < expires): return args else: return None 

I can call this function by doing:

 class WelcomePage(webapp.RequestHandler): def getFacebookCookie(self): cookie = facebook.get_user_from_cookie( self.request.cookies, app_id, app_secret) accss_token = cookie["access_token"] logging.debug("The access token is %s"%access_token) 

Now, how can I delete / set the user cookie expiration date?

Any help is greatly appreciated. Thanks in advance.

+7
source share
1 answer

Update: this method will work if you are the one who set the cookie ... but I missed the part in which you clearly said that this is the facebook cookie that you want to delete. In this case, the answer to this question seems to you exactly what you need: Facebook Oauth Logout

If this is the cookie that you set in the first place, you should just set the cookie to expire a very long time in the response header. wikipedia article

 self.response.headers.add_header("Set-Cookie", "access_token=deleted; Expires=Thu, 01-Jan-1970 00:00:00 GMT") 

make sure the domain and path match the original cookie or it probably won't work.

+5
source

All Articles