.NET Google api 1.7 beta 使用刷新令牌进行身份验证

.NET Google api 1.7 beta authenticating with refresh token(.NET Google api 1.7 beta 使用刷新令牌进行身份验证)
本文介绍了.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 使用刷新令牌进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Custom Error Queue Name when using EasyNetQ for RabbitMQ?(使用 EasyNetQ for RabbitMQ 时自定义错误队列名称?)
How to generate password_hash for RabbitMQ Management HTTP API(如何为 RabbitMQ 管理 HTTP API 生成密码哈希)
Rabbitmq Ack or Nack, leaving messages on the queue(Rabbitmq Ack 或 Nack,将消息留在队列中)
Setup RabbitMQ consumer in ASP.NET Core application(在 ASP.NET Core 应用程序中设置 RabbitMQ 消费者)
Specify Publish timeouts in mass transit(指定公共交通中的发布超时)
RabbitMQ asynchronous support(RabbitMQ 异步支持)