【问题标题】:is it possible to retrieve the refresh token with google oauth2是否可以使用 google oauth2 检索刷新令牌
【发布时间】:2015-03-27 00:37:39
【问题描述】:

是否可以从应用程序的谷歌帐户中检索refresh token

我为我的网络应用程序使用 google oauth 登录。首次登录时会生成refresh token。但是当出现问题或程序不接受用户时,已经生成了refresh token 的用户已经登录。用户第二次登录时不会生成refresh token。在生成新的refresh token 之前,用户必须先撤消 Web 应用程序。

有没有办法检索用户的refresh token?或者甚至更好,将用户从 Web 应用程序中踢出?

这就是我获得refresh token的方式:

        code = request.args.get('code')

        credentials = cls.flow.step2_exchange(code)

        print 'refresh_token:{}'.format(credentials.refresh_token)

我正在使用 Flask

【问题讨论】:

  • 疯狂猜测。尝试搜索名为approval_prompt 的东西。如果您没有刷新令牌,您应该能够强制它向用户请求一个新令牌。他们不应该撤销访问权限。这又是一个疯狂的猜测,我不是 Python 程序员

标签: python-2.7 oauth google-oauth


【解决方案1】:

好的,我找到了答案。

当用户接受您的申请时,会生成一个refresh_token。 如果用户稍后回来并且没有撤销您的应用程序,谷歌将不会生成另一个刷新令牌。您可以使用approval_prompt='force' 强制用户通过审批提示。

用户可以通过访问 myaccount.google.com > 已连接的应用和服务,选择您的应用并撤消来撤消您的申请。

要在您的应用程序中撤销用户,您可以调用以下 URL: 'https://accounts.google.com/o/oauth2/revoke?token={token}'

示例:

def revoke(token)
    url = 'https://accounts.google.com/o/oauth2/revoke?token=%s' % token
    h = httplib2.Http()
    return h.request(url, 'GET')[0]

令牌可以是access_tokenrefresh_token

【讨论】:

猜你喜欢
  • 2012-04-22
  • 2015-10-20
  • 2016-08-03
  • 2017-05-12
  • 2021-08-27
  • 2022-06-19
  • 2023-04-02
  • 2013-08-30
  • 2014-08-12
相关资源
最近更新 更多