public IWebUI CreateAuthenticationDialog(CoreUIParent coreUIParent, WebViewPreference useEmbeddedWebView, RequestContext requestContext)
        {
            if (useEmbeddedWebView == WebViewPreference.System)
            {
                requestContext.Logger.Info("Using system browser.");
                return(new DefaultOsBrowserWebUi(
                           requestContext.ServiceBundle.PlatformProxy,
                           requestContext.Logger,
                           coreUIParent.SystemWebViewOptions));
            }

            AuthorityType authorityType        = requestContext.ServiceBundle.Config.Authority.AuthorityInfo.AuthorityType;
            bool          isAadOrAdfsAuthority =
                authorityType == AuthorityType.Aad ||
                authorityType == AuthorityType.Adfs;

            if (isAadOrAdfsAuthority)
            {
                requestContext.Logger.Info($"Using WebView1 embedded browser because the authority is {authorityType}. WebView2 does not provide SSO.");
                return(new InteractiveWebUI(coreUIParent, requestContext));
            }

            if (!_isWebView2AvailableFunc())
            {
                requestContext.Logger.Info("Using WebView1 embedded browser because WebView2 is not available.");
                return(new InteractiveWebUI(coreUIParent, requestContext));
            }

            requestContext.Logger.Info("Using WebView2 embedded browser.");
            return(new WebView2WebUi(coreUIParent, requestContext));
        }
Esempio n. 2
0
        public IWebUI CreateAuthenticationDialog(CoreUIParent coreUIParent, WebViewPreference useEmbeddedWebView, RequestContext requestContext)
        {
            if (useEmbeddedWebView == WebViewPreference.System)
            {
                requestContext.Logger.Info("Using system browser");
                return(new DefaultOsBrowserWebUi(
                           requestContext.ServiceBundle.PlatformProxy,
                           requestContext.Logger,
                           coreUIParent.SystemWebViewOptions));
            }

            if (_isWebView2AvailableFunc())
            {
                requestContext.Logger.Info("Using WebView2 embedded browser");
                return(new WebView2WebUi(coreUIParent, requestContext));
            }

#if DESKTOP
            if (_fallbackToLegacyWebBrowser)
            {
                requestContext.Logger.Info("Using legacy embedded browser");
                return
                    (new Microsoft.Identity.Client.Platforms.Features.WinFormsLegacyWebUi.InteractiveWebUI(coreUIParent, requestContext));
            }
#endif
            throw new MsalClientException(
                      MsalError.WebView2NotInstalled,
                      "The embedded browser needs WebView2 runtime to be installed. If you are an end user of the app, please download and install the WebView2 runtime from https://go.microsoft.com/fwlink/p/?LinkId=2124703 and restart the app." +
                      " If you are an app developer, please ensure that your app installs the WebView2 runtime https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution");
        }
 public IWebUI CreateAuthenticationDialog(CoreUIParent coreUIParent, WebViewPreference webViewPreference, RequestContext requestContext)
 {
     throw new PlatformNotSupportedException(
               "Possible Cause: If you are using an XForms app, or generally a netstandard assembly, " +
               "make sure you add a reference to Microsoft.Identity.Client.dll from each platform assembly " +
               "(e.g. UWP, Android, iOS), not just from the common netstandard assembly. " +
               "A browser is not avaiable in the box on .NETStandard 1.3");
 }
        public IWebUI CreateAuthenticationDialog(CoreUIParent coreUIParent, WebViewPreference webViewPreference, RequestContext requestContext)
        {
            if (webViewPreference == WebViewPreference.System)
            {
                throw new MsalClientException(
                          MsalError.WebviewUnavailable,
                          "On UWP, MSAL cannot use the system browser. " +
                          "The preffered auth mechanism is the Web Authentication Manager (WAM) see https://aka.ms/msal-net-uwp-wam");
            }

            return(new WebUI(coreUIParent, requestContext));
        }
Esempio n. 5
0
        public IWebUI CreateAuthenticationDialog(CoreUIParent coreUIParent, WebViewPreference webViewPreference, RequestContext requestContext)
        {
            if (webViewPreference == WebViewPreference.System)
            {
                return(new DefaultOsBrowserWebUi(
                           requestContext.ServiceBundle.PlatformProxy,
                           requestContext.Logger,
                           coreUIParent.SystemWebViewOptions));
            }

            return(new MacEmbeddedWebUI()
            {
                CoreUIParent = coreUIParent,
                RequestContext = requestContext
            });
        }
Esempio n. 6
0
        private static bool GetUseEmbeddedWebview(WebViewPreference userPreference, bool defaultValue)
        {
            switch (userPreference)
            {
            case WebViewPreference.NotSpecified:
                return(defaultValue);

            case WebViewPreference.Embedded:
                return(true);

            case WebViewPreference.System:
                return(false);

            default:
                throw new NotImplementedException("Unknown option");
            }
        }
        public IWebUI CreateAuthenticationDialog(
            CoreUIParent coreUIParent,
            WebViewPreference webViewPreference,
            RequestContext requestContext)
        {
            if (webViewPreference == WebViewPreference.Embedded)
            {
                throw new MsalClientException(MsalError.WebviewUnavailable,
                                              "An embedded webview is not available in the box on .NET Core 3.x " +
                                              "Please reference the package Microsoft.Indentity.Client.Desktop and call WithDesktopFeatures(). See https://aka.ms/msal-net-webview2 " +
                                              "Or use the system webview - see https://aka.ms/msal-net-os-browser");
            }

            return(new DefaultOsBrowserWebUi(
                       requestContext.ServiceBundle.PlatformProxy,
                       requestContext.Logger,
                       coreUIParent.SystemWebViewOptions));
        }
        //#endif

        public IWebUI CreateAuthenticationDialog(
            CoreUIParent coreUIParent,
            WebViewPreference useEmbeddedWebView,
            RequestContext requestContext)
        {
            if (useEmbeddedWebView == WebViewPreference.Embedded)
            {
                return(new EmbeddedWebUI(coreUIParent)
                {
                    RequestContext = requestContext
                });
            }

            return(new SystemWebUI(coreUIParent)
            {
                RequestContext = requestContext
            });
        }
Esempio n. 9
0
        public IWebUI CreateAuthenticationDialog(CoreUIParent coreUIParent, WebViewPreference useEmbeddedWebView, RequestContext requestContext)
        {
            if (useEmbeddedWebView == WebViewPreference.System)
            {
                requestContext.Logger.Info("Using system browser.");
                return(new DefaultOsBrowserWebUi(
                           requestContext.ServiceBundle.PlatformProxy,
                           requestContext.Logger,
                           coreUIParent.SystemWebViewOptions));
            }

            if (_isWebView2AvailableFunc())
            {
                requestContext.Logger.Info("Using WebView2 embedded browser.");
                return(new WebView2WebUi(coreUIParent, requestContext));
            }

            requestContext.Logger.Info("Using legacy embedded browser.");
            return(new InteractiveWebUI(coreUIParent, requestContext));
        }
        public bool IsEmbeddedWebViewAvailable => IsUserInteractive; // WebBrowser control is always available

        public IWebUI CreateAuthenticationDialog(
            CoreUIParent coreUIParent,
            WebViewPreference useEmbeddedWebView,
            RequestContext requestContext)
        {
            if (coreUIParent.UseHiddenBrowser)
            {
                return(new SilentWebUI(coreUIParent, requestContext));
            }

            if (useEmbeddedWebView == WebViewPreference.System)
            {
                return(new DefaultOsBrowserWebUi(
                           requestContext.ServiceBundle.PlatformProxy,
                           requestContext.Logger,
                           coreUIParent.SystemWebViewOptions));
            }

            // Use the old legacy WebUi by default on .NET classic
            return(new InteractiveWebUI(coreUIParent, requestContext));
        }
Esempio n. 11
0
        public void ValidateInteractiveParameters(
            WebViewPreference expectedEmbeddedWebView,
            IAccount expectedAccount = null,
            IEnumerable <string> expectedExtraScopesToConsent = null,
            string expectedLoginHint            = null,
            string expectedPromptValue          = null,
            ICustomWebUi expectedCustomWebUi    = null,
            SystemWebViewOptions browserOptions = null)
        {
            Assert.IsNotNull(InteractiveParametersReceived);

            Assert.AreEqual(expectedAccount, InteractiveParametersReceived.Account);
            CoreAssert.AreScopesEqual(
                (expectedExtraScopesToConsent ?? new List <string>()).AsSingleString(),
                InteractiveParametersReceived.ExtraScopesToConsent.AsSingleString());
            Assert.AreEqual(expectedLoginHint, InteractiveParametersReceived.LoginHint);
            Assert.AreEqual(expectedPromptValue ?? Prompt.NotSpecified.PromptValue, InteractiveParametersReceived.Prompt.PromptValue);
            Assert.IsNotNull(InteractiveParametersReceived.UiParent);
            Assert.AreEqual(expectedEmbeddedWebView, InteractiveParametersReceived.UseEmbeddedWebView);
            Assert.AreEqual(expectedCustomWebUi, InteractiveParametersReceived.CustomWebUi);
            Assert.AreEqual(browserOptions, InteractiveParametersReceived.UiParent.SystemWebViewOptions);
        }
        public IWebUI CreateAuthenticationDialog(
            CoreUIParent coreUIParent,
            WebViewPreference webViewPreference,
            RequestContext requestContext)
        {
            if (webViewPreference == WebViewPreference.Embedded)
            {
                throw new MsalClientException(MsalError.WebviewUnavailable,
                                              "If you have a Windows application which targets net5 or net5-windows, please change the target to net5-windows10.0.17763.0, " +
                                              "which provides support from Win7 to Win10. For details, see https://github.com/dotnet/designs/blob/main/accepted/2020/platform-checks/platform-checks.md" +
                                              "If you have a cross-platform (Windows, Mac, Linux) application which targets net5, please dual target net5 and net5-windows10.0.17763.0." +
                                              "Your installer should deploy the net5 version on Mac and Linux and the net5-window10.0.17763.0 on Win7 - Win10." +
                                              "For details, see https://github.com/dotnet/designs/blob/main/accepted/2020/platform-checks/platform-checks.md" +
                                              "If you have a .NET Core 3.1 app, please reference the NuGet package Microsoft.Identity.Client.Desktop and call the extension method .WithDesktopFeatures() first." + "For details, see https://aka.ms/msal-net-webview2 or use the system WebView - see https://aka.ms/msal-net-os-browser");
            }

            requestContext.Logger.Info("Using system browser.");
            return(new DefaultOsBrowserWebUi(
                       requestContext.ServiceBundle.PlatformProxy,
                       requestContext.Logger,
                       coreUIParent.SystemWebViewOptions));
        }
        public IWebUI CreateAuthenticationDialog(CoreUIParent coreUIParent, WebViewPreference useEmbeddedWebView, RequestContext requestContext)
        {
            if (useEmbeddedWebView == WebViewPreference.System)
            {
                requestContext.Logger.Info("Using system browser");
                return(new DefaultOsBrowserWebUi(
                           requestContext.ServiceBundle.PlatformProxy,
                           requestContext.Logger,
                           coreUIParent.SystemWebViewOptions));
            }


            if (_isWebView2AvailableFunc(coreUIParent?.EmbeddedWebviewOptions?.WebView2BrowserExecutableFolder))
            {
                requestContext.Logger.Info("Using WebView2 embedded browser");
                return(new WebView2WebUi(coreUIParent, requestContext));
            }

            throw new MsalClientException(
                      MsalError.WebView2NotInstalled,
                      "The embedded browser needs WebView2 runtime to be installed. If you are an end user of the app, please download and install the WebView2 runtime from https://go.microsoft.com/fwlink/p/?LinkId=2124703 and restart the app." +
                      " If you are an app developer, please ensure that your app installs the WebView2 runtime or that you provide a fixed version. See https://aka.ms/msal-net-webview2 for details");
        }