我正在将 OAuth 2.0 与一些 Google API 结合使用。虽然授权过程很简单,但我在初始授权完成后面临自动授权的问题。
所以:
1. Authorization is done for the first time. (user grants access, I get the token etc etc) 2. User exits the application 3. User starts the application again 4. How to logon automatically here?
在第 4 点,我确实有一个 refresh_token,所以我应该使用该 request_token 请求一个新的 token 。但是我的通话仍然不断收到 401 Unauthorized 结果。
所以我试图做的是我的应用程序可以静默登录,这样用户就不必每次都授予访问权限。
最佳答案
您应该能够使用以下请求刷新 OAuth 2.0 token :
POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded
client_id=21302922996.apps.googleusercontent.com&
client_secret=XTHhXh1SlUNgvyWGwDk1EjXB&
refresh_token=1/6BMfW9j53gdGImsixUH6kU5RsR4zwI9lUVX-tqf8JXQ&
grant_type=refresh_token
正如 Google OAuth 2.0 documentation 中所指出的.
我刚刚使用 curl 进行了尝试,它按预期工作:
curl -d client_id=$CLIENT_ID -d client_secret=$CLIENT_SECRET -d refresh_token=$REFRESH_TOKEN -d grant_type=refresh_token https://accounts.google.com/o/oauth2/token
{"access_token":"$ACCESS_TOKEN","token_type":"Bearer","expires_in":3600}
关于.net - Google/OAuth 2 - 自动登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6252413/