如果浏览器关闭,GoogleWebAuthorizationBroker.AuthorizeAsync()会挂起 [英] GoogleWebAuthorizationBroker.AuthorizeAsync() hangs if browser closed

查看:400
本文介绍了如果浏览器关闭,GoogleWebAuthorizationBroker.AuthorizeAsync()会挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个可将其输出复制到用户Google Drive的C#桌面应用程序。然而,当我尝试使用GoogleWebAuthorizationBroker.AuthorizeAsync()授权访问Google时,如果用户在浏览器中关闭了身份验证页面,该方法永远不会返回!



即使我使用30秒取消令牌,如果浏览器关闭,它永远不会返回。

  public bool Authorize()
{
_authorised = false;
UserCredential credential = null;
尝试
{
//这里是我们要求用户给我们访问的地方,或者使用先前存储在%AppData%
中的Refresh Token CancellationTokenSource cts = new CancellationTokenSource (新TimeSpan(0,0,30));
凭证= GoogleWebAuthorizationBroker.AuthorizeAsync(新ClientSecrets {ClientId = this.ClientId,ClientSecret = this.ClientSecret},
作用域,
用户名,
cts.Token,// CancellationToken。无,
新的FileDataStore(AppName))。
}
catch(例外)
{
return _authorised; ((凭证!=空)&&(凭证。令牌。访问!=空))
{

}

服务= new DriveService(new BaseClientService.Initializer(){HttpClientInitializer = credential,ApplicationName = AppName,});
_authorised = true;
}

return _authorised;
}

如何阻止用户关闭浏览器窗口并停止我的应用程序挂起?

解决方案

这是Google .net客户端库中的一个已知问题。


  1. GoogleWebAuthorizationBroker.AuthorizeAsync在用户关闭浏览器时挂起

  2. 在GoogleWebAuthorizationBroker.AuthorizeAsync上没有超时?

目前没有我知道的解决方法。我建议在论坛上添加你的名字,以鼓励团队解决这个问题。

更新:它现在在名单上在等待浏览器响应时,GoogleWebAuthorizationBroker未兑现CancellationToken


I'm writing a C# desktop app that can copy its output to a users Google Drive. However when I try an authorise access to Google with GoogleWebAuthorizationBroker.AuthorizeAsync() if the user closes the authentication page in the browser the method never returns!

Even if I use a 30 sec cancellation token it never returns if the browser is closed.

public bool Authorise()
{
    _authorised = false;
    UserCredential credential = null;
    try
    {
        // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
        CancellationTokenSource cts = new CancellationTokenSource(new TimeSpan(0,0,30));
        credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = this.ClientId, ClientSecret = this.ClientSecret },
                                                                 Scopes,
                                                                 UserName,
                                                                 cts.Token,//CancellationToken.None,
                                                                 new FileDataStore(AppName)).Result;
    }
    catch (Exception)
    {
        return _authorised;
    }

    if ((credential != null) && (credential.Token.AccessToken != null))
    {

        Service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = AppName, });
        _authorised = true;
    }

    return _authorised;
}

How can I trap the user closing the browser window and stop my application hanging?

解决方案

This is a known issue in the Google .net Client library.

  1. GoogleWebAuthorizationBroker.AuthorizeAsync Hang when user closes browser
  2. No time out on GoogleWebAuthorizationBroker.AuthorizeAsync?

There is currently no workaround that I know of. I recommend adding your name to the issues on the forum to encourage the team to address the issue.

Update: Its now on the list GoogleWebAuthorizationBroker does not honour CancellationToken when waiting for browser response

这篇关于如果浏览器关闭,GoogleWebAuthorizationBroker.AuthorizeAsync()会挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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