【发布时间】:2022-01-11 09:38:36
【问题描述】:
通过IdentityModel.OidcClient 连接到 Azure AD 的 UWP 应用会产生如下错误。
Exception Message = "指定的协议未知。(异常 来自 HRESULT: 0x800C000D)" 在堆栈跟踪中注意重要!
异常发生在public class WabBrowser : IBrowser 的InvokeAsyncCore(BrowserOptions options, bool silentMode) 函数内。
代码:
public class WabBrowser : IBrowser
{
private readonly bool _enableWindowsAuthentication;
public WabBrowser(bool enableWindowsAuthentication = false)
{
_enableWindowsAuthentication = enableWindowsAuthentication;
}
private async Task<BrowserResult> InvokeAsyncCore(BrowserOptions options, bool silentMode)
{
var wabOptions = WebAuthenticationOptions.UseHttpPost;
if (_enableWindowsAuthentication)
{
wabOptions |= WebAuthenticationOptions.UseCorporateNetwork;
}
if (silentMode)
{
wabOptions |= WebAuthenticationOptions.SilentMode;
}
WebAuthenticationResult wabResult;
try
{
if (string.Equals(options.EndUrl, WebAuthenticationBroker.GetCurrentApplicationCallbackUri().AbsoluteUri, StringComparison.Ordinal))
{
wabResult = await WebAuthenticationBroker.AuthenticateAsync(
wabOptions, new Uri(options.StartUrl));
}
else
{
if (string.IsNullOrWhiteSpace(options.EndUrl))
{
wabResult = await WebAuthenticationBroker.AuthenticateAsync(
wabOptions, new Uri(options.StartUrl), WebAuthenticationBroker.GetCurrentApplicationCallbackUri());
}
else
{
wabResult = await WebAuthenticationBroker.AuthenticateAsync(
wabOptions, new Uri(options.StartUrl), new Uri(options.EndUrl));
}
}
}
catch (Exception ex)
{
Utility.WriteErrorsToLogViaMessenger("WabBrowser-InvokeAsyncCore", ex);
return new BrowserResult
{
ResultType = BrowserResultType.UnknownError,
Error = ex.ToString()
};
}
}
此问题仅在连接到 Azure AD 时发生,并且在连接到其他身份服务器时,此实现工作正常。
任何帮助将不胜感激。
【问题讨论】:
标签: uwp win-universal-app openid-connect windows-10-universal oidc-client