使用刷新令牌协调API OAuth2身份验证

时间:2014-11-11 15:57:11

标签: c# asp.net api oauth-2.0 coordinate

我正在寻找一个示例代码,使用OAuth2和现有的刷新令牌对Coordinate API进行身份验证。我在线程Google Coordinate OAuth2 with Service Account中寻找类似的东西。我尝试过该代码片段,但由于dll冲突,我遇到了一些问题。从nuget库看来,Google.Apis.Authentication.OAuth2似乎已被弃用,我们应该使用Google.Apis.Auth代替。

所以,如果有人可以提供一个可以与Google.Apis.Auth合作的示例代码,那就太棒了。

请帮忙。

1 个答案:

答案 0 :(得分:0)

我可以通过尝试不同的组合找到解决方案。添加示例代码,我认为这将有助于寻找类似解决方案的人。

        using Google.Apis.Auth.OAuth2;
        using Google.Apis.Coordinate.v1;
        using Google.Apis.Coordinate.v1.Data;
        using Google.Apis.Services;
        using Google.Apis.Util.Store;


        using (var stream = new FileStream(@"client_secret.json", FileMode.Open, FileAccess.Read))
        {
            credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
            new[] { CoordinateService.Scope.Coordinate },
            "user", CancellationToken.None,new FileDataStore(folder));
        }

        var service = new CoordinateService(new BaseClientService.Initializer()
        {
        HttpClientInitializer = credential,
        ApplicationName = "appname",
        });

        var list = await service.Location.List("teamid", "team@mailid.com", 2000).ExecuteAsync();

希望这会有所帮助。

谢谢, MG

相关问题