【问题标题】:OIDCClient "The specified protocol is unknown" exception in UWP when connecting to Azure AD连接到 Azure AD 时,UWP 中的 OIDCClient“指定的协议未知”异常
【发布时间】:2022-01-11 09:38:36
【问题描述】:

通过IdentityModel.OidcClient 连接到 Azure AD 的 UWP 应用会产生如下错误。

Exception Message = "指定的协议未知。(异常 来自 HRESULT: 0x800C000D)" 在堆栈跟踪中注意重要!

异常发生在public class WabBrowser : IBrowserInvokeAsyncCore(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


    【解决方案1】:

    答案很简单。 在连接到 Azure AD 时,您必须将其设置为 None,而不是 WebAuthenticationOptions 中的 UseHttpPost

    var wabOptions = WebAuthenticationOptions.None;
    

    【讨论】:

    猜你喜欢
    • 2015-04-10
    • 1970-01-01
    • 1970-01-01
    • 2013-12-27
    • 2019-10-12
    • 1970-01-01
    • 2023-03-14
    • 2019-12-15
    • 1970-01-01
    相关资源
    最近更新 更多