.NET Google api 1.7 beta authenticating with refresh token(.NET Google api 1.7 beta 使用刷新令牌进行身份验证)
问题描述
我一直在查看 Oauth .Net Google API,以便通过 OAuth 进行身份验证并使用 Google drive API.
I've been looking at the Oauth .Net Google Apis in order to authenticate via OAuth and use the Google drive Apis.
具体来说,我想使用我已经存储的刷新令牌来实例化 GoogleDrive 服务.
Specifically, I want to use a refresh token I already have stored in order to use it to instantiate a GoogleDrive service.
我找到了类似的样本https:///code.google.com/p/google-api-dotnet-client/source/browse/Tasks.SimpleOAuth2/Program.cs?repo=samples
这似乎使用GoogleWebAuthorizationBroker.AuthorizeAsync",但我不确定如何使用刷新令牌而不是您在本示例中提供的客户端机密来使用该方法.
That seem to use "GoogleWebAuthorizationBroker.AuthorizeAsync" but I'm not sure how I can use that method with a refresh token rather than the client secrets you seem to be feeding it in this example.
推荐答案
如果我理解正确,您是在问如何根据现有的刷新令牌创建新的 Google 服务.
If I understand you correctly, you are asking how can you create a new Google service, based on an existing refresh token.
因此,您可以执行以下操作:
So, you can do the following:
var token = new TokenResponse { RefreshToken = "YOUR_REFRESH_TOKEN_HERE" };
var credentials = new UserCredential(new GoogleAuthorizationCodeFlow(
new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = [your_client_secrets_here]
}), "user", token);
然后您可以将您的凭据传递给服务的初始化程序.
Then you can pass your credentials to the service's initializer.
通过执行上述操作,GoogleAuthorizationCodeFlow 将根据您刷新令牌和客户端机密获取新的访问令牌.
By doing the above, GoogleAuthorizationCodeFlow will get a new access token based on you refresh token and client secrets.
请注意,您必须在此处拥有客户端密码,否则您将无法获得访问令牌.
Note that you must have client secrets here, without that, you won't be able to get an access token.
这篇关于.NET Google api 1.7 beta 使用刷新令牌进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.NET Google api 1.7 beta 使用刷新令牌进行身份验证
基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
