Google/OAuth 2 - 自动登录

Rha*_*ody 5 .net oauth-2.0 google-tasks-api

我正在使用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?
Run Code Online (Sandbox Code Playgroud)

在第4点,我确实有一个refresh_token所以我应该使用request_token请求一个新的令牌.但是我的电话仍然有401个未经授权的结果.

所以我尝试做的是我的应用程序可以静默登录,以便用户不必每次都授予访问权限.

pro*_*ppy 2

您应该能够使用以下请求刷新 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
Run Code Online (Sandbox Code Playgroud)

正如Google OAuth 2.0 文档中指出的那样。

我刚刚使用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}
Run Code Online (Sandbox Code Playgroud)