Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Password autosave + suggest #131

@AlbertoCe

Description

@AlbertoCe

Hi all,
I'm trying to use webview2 to authenticate against IdentityServer 4 for my WPF app.
I'm using OidcClient (from IdentityModel) with this implementation:

var options = new OidcClientOptions()
{
	Authority = App.ApplicationSettings.IdentityServerUrl,
	ClientId = App.ApplicationSettings.ClientId,
	Scope = App.ApplicationSettings.Scope,
	RedirectUri = App.ApplicationSettings.ClientRedirectUri,
	Browser = new EmbeddedBrowser(),
	LoadProfile = true,
	Policy = new Policy
	{
		RequireIdentityTokenSignature = false
	}
};

Using this as WebView2:

var semaphoreSlim = new SemaphoreSlim(0, 1);
var browserResult = new BrowserResult()
{
	ResultType = BrowserResultType.UserCancel
};

var signinWindow = new Window()
{
	Width = 800,
	Height = 600,
	Title = "Sign In",
	WindowStartupLocation = WindowStartupLocation.CenterScreen
};
signinWindow.Closing += (s, e) =>
{
	semaphoreSlim.Release();
};

var webView = new WebView2();
webView.NavigationStarting += async (s, e) =>
{
	if (IsBrowserNavigatingToRedirectUri(new Uri(e.Uri)))
	{
		e.Cancel = true;
		browserResult = new BrowserResult()
		{
			ResultType = BrowserResultType.Success,
			Response = new Uri(e.Uri).AbsoluteUri
		};

		semaphoreSlim.Release();
		signinWindow.Close();
	}
};

signinWindow.Content = webView;
signinWindow.Show();

webView.CreationProperties = new CoreWebView2CreationProperties(); 
var env = await CoreWebView2Environment.CreateAsync();

await webView.EnsureCoreWebView2Async(env);

webView.CoreWebView2.Settings.IsPasswordAutosaveEnabled = true;
webView.CoreWebView2.Settings.IsGeneralAutofillEnabled = true;

// Delete existing Cookies so previous logins won't remembered
//webView.CoreWebView2.CookieManager.DeleteAllCookies();
// Navigate
webView.CoreWebView2.Navigate(_options.StartUrl);

await semaphoreSlim.WaitAsync();

return browserResult;

Webview suggest me known username (used by this page) but does not ask for password change neither ask to save.

Any suggestion?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions