wpf - OIDCClient LogoutAsync 抛出 SemaphoreFullException
问题描述
我正在从 WPF 应用程序连接到 Identity Server 4,并且正在尝试执行注销。但是,在调用 _oidcClient.LogoutAsync() 时,我的 WpfEmbeddedBrowser 中出现了 SemaphoreFullException。最初我认为也许我不应该使用浏览器注销,但我认为这是不可能的。
这是调用登录和注销的部分:
//prompt login
var options = new OidcClientOptions()
{
Authority = Current.Properties["IdentityServerAPIAddress"].ToString(),
ClientId = "wpf",
ClientSecret = "secret",
Scope = "openid offline_access WebAPI",
RedirectUri = "http://localhost/signin-oidc",
Flow = OidcClientOptions.AuthenticationFlow.AuthorizationCode,
Browser = new WpfEmbeddedBrowser()
};
_oidcClient = new OidcClient(options);
try
{
loginResult = await _oidcClient.LoginAsync();
logoutResult = await _oidcClient.LogoutAsync();
}
...
这是 WpfEmbeddedBrowser:
private BrowserOptions _options = null;
public WpfEmbeddedBrowser()
{
}
public async Task<BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default)
{
_options = options;
var window = new Window()
{
Width = 450,
Height = 750,
Title = "SiteMonitor Desktop Application Login"
};
var webBrowser = new WebBrowser();
var signal = new SemaphoreSlim(0, 1);
window.Show();
var result = new BrowserResult()
{
ResultType = BrowserResultType.UserCancel
};
webBrowser.Navigating += (s, e) =>
{
if (BrowserIsNavigatingToRedirectUri(e.Uri))
{
e.Cancel = true;
result = new BrowserResult()
{
ResultType = BrowserResultType.Success,
Response = e.Uri.AbsoluteUri
};
signal.Release();
window.Close();
}
};
window.Closing += (s, e) =>
{
signal.Release();
};
window.Content = webBrowser;
window.Show();
webBrowser.Source = new Uri(_options.StartUrl);
await signal.WaitAsync();
return result;
}
private bool BrowserIsNavigatingToRedirectUri(Uri uri)
{
return uri.AbsoluteUri.StartsWith(_options.EndUrl);
}
解决方案
设置maxCout
为2
in SemaphoreSlim
,这对我来说很合适。
var signal = new SemaphoreSlim(0, 2);
推荐阅读
- android - Oncomplete 任务在 getResult() 之后无法访问方法 getDownloadUrl()
- multiprocessing - astropy 多处理访问 IERS 数据
- javascript - 符号作为 Firefox 中 Javascript 对象的关键标识符
- python - 素数分解一个 3000 位数字,最大素数 <=104743(6 位) - 这可以在几分钟内在“普通”计算机上完成吗?
- java - 如果将文本文件作为主要方法(java)中的命令行参数传递,我如何从其他方法访问我的文本文件
- python - 在使用所有可能的预测变量拟合模型时,它会抛出此错误 TypeError: ufunc 'isfinite' not supported
- python - 为什么这会给我 TypeError: 'int' object is not subscriptable
- python - 部署 Flask - MySQL 到 Heroku
- django - Django - 特定用户类型需要登录
- python - 如何在列表理解中赋值?