.net - Google/OAuth 2 - 自动登录

标签 .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?


在第 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/

相关文章:

.net - 掌上电脑/Windows Mobile : How to detect smart minimize

c# - 管理多个环境的设置?

c# - 通过继承判断两个 MethodInfo 实例是否代表同一个(非虚)方法

grails - 将在 Google Apps 中创建的 Google 任务与在我们的 Web 应用程序中创建的任务同步 (Grails/Java)

android - 当我尝试使用 Google Task API 在 Java 中发布任务时,为什么总是收到 'Bad Request'?

c# - 如何计算看起来非常接近 Winforms 控件的控件的禁用文本颜色?

node.js - OAuth 2.0 Flow 它是如何工作的 node-oauth2-server

django - Web 应用程序中基于 Stormpath token 的身份验证

java - Spring-Security-Oauth2:访问此资源需要完全身份验证

android - Firestore 任务 whenallcomplete() - 任务尚未完成