这是问题的后续跟进Not receiving Google OAuth refresh token
答案是“只有在用户的第一次授权时才提供refresh_token . ”
撤消应用程序的权限并尝试再次授权后,不会返回刷新令牌 . 我得到的是:
{ "access_token" : "XXXX..", "token_type" : "Bearer", "expires_in" : 3600, "id_token" : "XXXX..." }
其他人建议使用 access_type=offline
但是,根据描述,在以下情况下使用离线访问:
“当用户不在浏览器时,应用程序需要访问Google API”
对我来说情况并非如此 .
获取刷新令牌的正确方法是什么?
2 回答
如果设置了access_type = offline,则只获取刷新令牌 . 您有两种选择如何处理:
不要使用
access_type=offline
. 您的访问令牌将持续1小时 . 访问令牌过期后,重新提示用户再次进行身份验证 . 他们需要再次完成整个OAuth舞蹈,以便您可以获得新的访问令牌 .使用
access_type=offline
以便get a new access tokens via the refresh token . 如果您愿意,在用户注销后,您可以revoke the tokens .Every time When you reload you application page , Access Token is Refreshed or you can say the refresh token for this purpose you should use the following 但首先您需要身份验证
i am also doing the same thing by the following Way
您可以使用它来避免您的问题“不返回刷新令牌” .
谢谢!!