在我使用 .Net HttpPost 的 Google OAuth 请求中,refresh_token 值丢失。
引用:https://developers.google.com/identity/protocols/oauth2/web-server#exchange-authorization-code
我输入的 HTTP post 请求 -
...google oauth post request details..url - (https://accounts.google.com/o/oauth2/token)...
and the postData - (client_id=<client_id>&client_secret=<client_secret_key>&grant_type=authorization_code&redirect_uri=<redirect_url>&code=<authorization_code>&access_type=offline&prompt=consent&approval_prompt=force)
注意:我有一个带有 access_token 的有效响应。但是,refresh_token 对象值为空记录。
请帮忙。
我已经查看了这些链接 - Not receiving Google OAuth refresh token
最佳答案
为访问 token 和刷新 token 交换授权代码的调用如下所示。
HTTP POST https://accounts.google.com/o/oauth2/token
code=4/X9lG6uWd8-MMJPElWggHZRzyFKtp.QubAT_P-GEwePvB8fYmgkJzntDnaiAI&client_id={ClientId}&client_secret={ClientSecret}&redirect_uri={redirectURI}&grant_type=authorization_code
您不使用 access_type 、approval_prompt、prompt
作为授权代码交换的一部分,它们包含在显示同意屏幕的 HTTP GET 请求中。
如果您已经在 google 开发者控制台上创建了网络凭证客户端,您可以在此处添加 access_type。
HTTP GET https://accounts.google.com/o/oauth2/auth?client_id={clientid}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=https://www.googleapis.com/auth/analytics.readonly&response_type=code&access_type=offline
如果您有兴趣了解调用是如何建立的,这可能会有所帮助。 Understanding Google OAuth 2.0 with curl
关于google-api - Google OAuth2 中缺少 refresh_token .Net HttpPost 对 access_token 的请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69747758/