简体   繁体   English

连接到 Azure AD 时,UWP 中的 OIDCClient“指定协议未知”异常

[英]OIDCClient "The specified protocol is unknown" exception in UWP when connecting to Azure AD

UWP app connecting to Azure AD via IdentityModel.OidcClient generates an error as below. UWP 应用程序通过IdentityModel.OidcClient连接到 Azure AD 会生成如下错误。

Exception Message = "The specified protocol is unknown. (Exception from HRESULT: 0x800C000D)" Noting important in Stack Trace!异常消息 =“指定的协议未知。(来自 HRESULT 的异常:0x800C000D)”在堆栈跟踪中注意重要!

Exception happens inside public class WabBrowser: IBrowser 's InvokeAsyncCore(BrowserOptions options, bool silentMode) function. public class WabBrowser: IBrowserInvokeAsyncCore(BrowserOptions options, bool silentMode) function。

Code:代码:

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

This issue occurs only connecting to Azure AD and when connecting to other Identity servers this implementation works fine.此问题仅在连接到Azure AD时发生,并且在连接到其他身份服务器时,此实现工作正常。 Any help would be appreciated.任何帮助,将不胜感激。

The answer is simple.答案很简单。 Instead of UseHttpPost in WebAuthenticationOptions , you have to set it to None when you're connecting to Azure AD.当您连接到 Azure AD 时,您必须将其设置为None而不是UseHttpPost中的WebAuthenticationOptions

var wabOptions = WebAuthenticationOptions.None;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM