未收到 Google OAuth 刷新令牌 [英] Not receiving Google OAuth refresh token

查看:30
本文介绍了未收到 Google OAuth 刷新令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 Google 获取访问令牌.Google API 说要获取访问令牌、发送代码和其他参数到令牌生成页面,响应将是一个 JSON 对象,如:

I want to get the access token from Google. The Google API says that to get the access token, send the code and other parameters to token generating page, and the response will be a JSON Object like :

{
"access_token" : "ya29.AHES6ZTtm7SuokEB-RGtbBty9IIlNiP9-eNMMQKtXdMP3sfjL1Fc",
"token_type" : "Bearer",
"expires_in" : 3600,
"refresh_token" : "1/HKSmLFXzqP0leUihZp2xUt3-5wkU7Gmu2Os_eBnzw74"
}

但是,我没有收到刷新令牌.在我的情况下的回应是:

However, I'm not receiving the refresh token. The response in my case is:

{
 "access_token" : "ya29.sddsdsdsdsds_h9v_nF0IR7XcwDK8XFB2EbvtxmgvB-4oZ8oU",
"token_type" : "Bearer",
"expires_in" : 3600
}

推荐答案

refresh_token 仅在用户第一次授权时提供.后续授权,例如您在测试 OAuth2 集成时所做的授权,将不会再次返回 refresh_token.:)

The refresh_token is only provided on the first authorization from the user. Subsequent authorizations, such as the kind you make while testing an OAuth2 integration, will not return the refresh_token again. :)

  1. 转到显示可以访问您帐户的应用的页面:https://myaccount.google.com/u/0/permissions.
  2. 在第三方应用菜单下,选择您的应用.
  3. 点击删除访问",然后点击确定"进行确认
  4. 您发出的下一个 OAuth2 请求将返回一个 refresh_token(前提是它还包含access_type=offline"查询参数.
  1. Go to the page showing Apps with access to your account: https://myaccount.google.com/u/0/permissions.
  2. Under the Third-party apps menu, choose your app.
  3. Click Remove access and then click Ok to confirm
  4. The next OAuth2 request you make will return a refresh_token (providing that it also includes the 'access_type=offline' query parameter.

或者,您可以将查询参数 prompt=consent&access_type=offline 添加到 OAuth 重定向(请参阅 Google 的 适用于 Web 服务器应用程序的 OAuth 2.0 页面).

Alternatively, you can add the query parameters prompt=consent&access_type=offline to the OAuth redirect (see Google's OAuth 2.0 for Web Server Applications page).

这将提示用户再次授权应用程序,并始终返回一个refresh_token.

This will prompt the user to authorize the application again and will always return a refresh_token.

这篇关于未收到 Google OAuth 刷新令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆