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

Password autosave + suggest #131

Open
AlbertoCe opened this issue Aug 23, 2022 · 2 comments
Open

Password autosave + suggest #131

AlbertoCe opened this issue Aug 23, 2022 · 2 comments

Comments

@AlbertoCe
Copy link

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?

@brockallen
Copy link
Contributor

Not sure -- isn't that a feature of the browser you use?

@AlbertoCe
Copy link
Author

Hi @brockallen,
probably you are right and it could depends on the webview2 control (I opened an issue on the control repository too).
I tried the WpfWebView2 sample in your repository and there are no message to the user asking to save password.
I'll do some more test today and I'll let you know.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants