0

経由で Azure AD に接続する UWP アプリIdentityModel.OidcClientは、次のようなエラーを生成します。

Exception Message = "The specified protocol is unknown. (Exception from 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、他の Identity サーバーに接続する場合にのみ発生し、この実装は正常に機能します。どんな助けでも大歓迎です。

4

1 に答える 1

0

答えは簡単です。UseHttpPostinの代わりに、 Azure AD に接続するときにWebAuthenticationOptionsに設定する必要があります。None

var wabOptions = WebAuthenticationOptions.None;
于 2021-12-06T05:03:51.147 に答える