Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 228
pete757 Avatar asked Oct 18 '25 11:10

pete757


2 Answers

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.

like image 67
David Risney Avatar answered Oct 20 '25 04:10

David Risney


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/");
        }));
    }
like image 32
J. Cuppens Avatar answered Oct 20 '25 06:10

J. Cuppens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!