Page 1 of 2

GetAuthCredentials works only once

PostPosted: Wed Sep 05, 2018 4:39 am
by tniinisto
Have a challenge on using GetAuthCredentials to provide user credentials.

Some background on the solution:
Always on Windows forms application where one web page with login functionality provided with CefSharp.

Problem:
1. GetAuthCredentials() works correctly only on the first time after application is started and user credentials are passed ok
2. With following user logins the GetAuthCredentials() is not called anymore, but the first user's credentials are always passd to web page

Here is a snippet on the GetAuthCredentials implementation:

public bool GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
{
if (isProxy != true)
{
callback.Continue(Program.user.getEmailAddress(), Program.user.getPassword());
return true;
}

return false;
}

CefSharp is initialized like this:

CefSettings settings = new CefSettings();
settings.CefCommandLineArgs.Add("disable-application-cache", "1");
settings.CefCommandLineArgs.Add("disable-session-storage", "1");
Cef.Initialize(settings);

Re: GetAuthCredentials works only once

PostPosted: Wed Sep 05, 2018 4:42 am
by magreenblatt
Correct, credentials are cached.

Re: GetAuthCredentials works only once

PostPosted: Wed Sep 05, 2018 4:46 am
by tniinisto
How can I empty cache, when the program is always running?
Or can I prevent the cache being used?

Tried CefBrowser already like this:
settings.CachePath = "cef_cache";

and when form where browser is closed:
Cef.GetGlobalCookieManager().DeleteCookies("", "");

Re: GetAuthCredentials works only once

PostPosted: Wed Sep 05, 2018 6:32 am
by magreenblatt
There is no way to clear the auth cache currently. I suggest using a different form of authentication where your application can manage login/logout.

Re: GetAuthCredentials works only once

PostPosted: Thu Sep 06, 2018 2:15 am
by tniinisto
Thinked another solution of closing Cef after the web form is closed.
Is this possible since the main form is still up and running?

Re: GetAuthCredentials works only once

PostPosted: Thu Sep 06, 2018 3:21 am
by magreenblatt
You would likely need to restart the application.

Re: GetAuthCredentials works only once

PostPosted: Fri May 07, 2021 9:55 am
by pdooker
Hello,

Is there any plan to address this cache clearing issue?

Thanks,

Paul

Re: GetAuthCredentials works only once

PostPosted: Fri May 07, 2021 12:00 pm
by magreenblatt
Use CefRequestContext::ClearHttpAuthCredentials

Re: GetAuthCredentials works only once

PostPosted: Fri Jul 23, 2021 2:02 pm
by pdooker
Hello Marshall,

Do you have any example on how to use ClearHttpAuthCredentials?

So far, I have tried this (simplified for this context):

Code: Select all
auto requestContext = GetBrowser()->GetHost()->GetRequestContext();
if (requestContext)
{
   requestContext->ClearHttpAuthCredentials(nullptr);
}


This is executed on the main browser thread. Using CEF version: 90.5.10.0

When this executes, I get an exception (attached image).

I know this is a very small snippet of my code, but do you have any insight as to what is happing? Do you have any examples on how this should be called?

Re: GetAuthCredentials works only once

PostPosted: Thu Sep 09, 2021 5:09 pm
by pdooker
Has anyone been able to successfully use ClearHttpAuthCredentials?

I keep getting a crash when I call it.