gpt4 book ai didi

c# - 如果浏览器关闭,GoogleWebAuthorizationBroker.AuthorizeAsync() 会挂起

转载 作者:行者123 更新时间:2023-11-30 23:14:21 26 4
gpt4 key购买 nike

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

即使我使用 30 秒的取消 token ,如果浏览器关闭,它也不会返回。

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;
}

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

最佳答案

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

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

据我所知,目前没有解决方法。我建议将您的名字添加到论坛的问题中,以鼓励团队解决问题。

更新:它现在在列表中GoogleWebAuthorizationBroker does not honour CancellationToken when waiting for browser response

关于c# - 如果浏览器关闭,GoogleWebAuthorizationBroker.AuthorizeAsync() 会挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43136455/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com