是否可以使用 google oauth2 检索刷新令牌

is it possible to retrieve the refresh token with google oauth2

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

我为我的 Web 应用程序使用 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

好的,我找到了答案。

当用户接受您的申请时,会生成 refresh_token。 如果用户稍后回来并且没有撤销您的申请,google 将不会生成另一个刷新令牌。您可以使用 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