我正在使用google-api-python-client中内置的revoke方法从django应用程序创建注销函数,但它似乎不起作用。这是我的代码。
def google_logout(request, user_id = None):
storage = Storage(CredentialsModel, 'id', user_id, 'credential')
credential = storage.get()
if credential is not None:
cr_json = credential.to_json()
credential = credential.new_from_json(cr_json)
http = httplib2.Http()
http = credential.authorize(http)
try:
# Don't know yet why this is always raising an exception.
credential.revoke(http)
storage.delete()
except TokenRevokeError:
return HttpResponseBadRequest('Invalid Token.')
else:
return redirect('authentication:google_login')当我使用django 1.4.5时,这是有效的,但后来我需要升级到1.5.1,现在它不起作用了。这是django的问题吗?我敢打赌不会。请帮帮忙。
附注:我知道我可以通过手动将access_token传递给这个url令牌{https://accounts.google.com/o/oauth2/revoke?token=}来撤销令牌,但我想使用接口中提供的方法。
发布于 2014-03-26 09:43:26
即使access_type设置为offline,如果您以前收到过刷新令牌,并且没有另外发送设置为force的查询参数approval_prompt,也可能得不到刷新令牌。
这尤其令人沮丧,并且很可能在调试撤销期间发生。因为您可能经常批准和删除凭据,所以有时Google可能会记住批准并授权,而不经过强制批准过程,在这种情况下,您将不会获得刷新令牌,而客户端API需要刷新令牌才能撤销。
https://stackoverflow.com/questions/17614362
复制相似问题