'WinForm using webview2 with SSO

I have a client application that hosts a web browser control (WebView2). The client application is configured to use SSO so the current windows user is automatically logged-in to the application. When I navigate to a web application on our intranet I want the current windows user's credentials to be used to automatically login to the web application (which support integrated windows authentication IWA) in the browser control.

How can I do that?



Solution 1:[1]

You might try enabling the CoreWebView2EnvironmentOptions.AllowSingleSignOnUsingOSPrimaryAccount property. This will require creating a custom CoreWebView2Environment via CoreWebView2Environment.CreateAsync and then using WebView2.EnsureCoreWebView2Async initialize your WebView2 using your custom CoreWebView2Environment. Be sure to call EnsureCoreWebView2Async before setting the WebView2.Source property as the Source property will implicitly initialize the WebView2 using a default CoreWebView2Environment.

Solution 2:[2]

Here's my demo project code based on the David his answer

private async void Form1_Load(object sender, EventArgs e)
    {
        var browser = new WebView2();

        var options = new CoreWebView2EnvironmentOptions();
        options.AllowSingleSignOnUsingOSPrimaryAccount = true;

        var environtment = await CoreWebView2Environment.CreateAsync(options: options).ConfigureAwait(false);

        await browser.EnsureCoreWebView2Async(environtment).ConfigureAwait(false);

        Invoke((MethodInvoker)(() =>
        {
            browser.Dock = DockStyle.Fill;
            pnlBrowser.Controls.Add(browser);
            browser.Source = new Uri("https://outlook.office.com/mail/");
        }));
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Risney
Solution 2 J. Cuppens