我正在尝试结合一些 Google API 来使用 OAuth 2.0。虽然授权过程非常简单,但在初始授权完成后,我遇到了自动授权的问题。
So:
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请求一个新令牌。但我的通话中仍然不断收到 401 未经授权的结果。
所以我尝试做的是我的应用程序可以静默登录,以便用户不必每次都授予访问权限。
您应该能够使用以下请求刷新 OAuth 2.0 令牌:
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
正如指出的谷歌 OAuth 2.0 文档 http://code.google.com/apis/accounts/docs/OAuth2.html#SSMoreToken.
我刚刚使用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}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)