IdentityModel.OidcClient.Samples icon indicating copy to clipboard operation
IdentityModel.OidcClient.Samples copied to clipboard

Password autosave + suggest

Open AlbertoCe opened this issue 3 years ago • 2 comments

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?

AlbertoCe avatar Aug 23 '22 09:08 AlbertoCe

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

brockallen avatar Aug 23 '22 11:08 brockallen

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.

AlbertoCe avatar Aug 24 '22 07:08 AlbertoCe