用刷新令牌.NET API谷歌测试版1.7认证 [英] .NET Google api 1.7 beta authenticating with refresh token

查看:253
本文介绍了用刷新令牌.NET API谷歌测试版1.7认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在为了通过OAuth认证,并使用谷歌推动蜜蜂一直在看的Oauth净谷歌的API。

I've been looking at the Oauth .Net Google Apis in order to authenticate via OAuth and use the Google drive Apis.

具体来说,我想用一个刷新令牌我已经存储起来,以便用它来实例化一个Google云端硬盘服务。

Specifically, I want to use a refresh token I already have stored in order to use it to instantiate a GoogleDrive service.

我发现样品,如
<一href=\"https://$c$c.google.com/p/google-api-dotnet-client/source/browse/Tasks.SimpleOAuth2/Program.cs?repo=samples\" rel=\"nofollow\">https://$c$c.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.

推荐答案

如果我理解正确,你是问你怎么能创建一个新的谷歌服务,基于现有的刷新令牌。

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.

通过做上述,的 GoogleAuthorization codeFLOW 的会根据您新的访问令牌刷新令牌和客户端秘密。

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 API谷歌测试版1.7认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆