GetAuthCredentials works only once

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

GetAuthCredentials works only once

Postby tniinisto » Wed Sep 05, 2018 4:39 am

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);
tniinisto
Newbie
 
Posts: 5
Joined: Thu Aug 16, 2018 12:05 am

Re: GetAuthCredentials works only once

Postby magreenblatt » Wed Sep 05, 2018 4:42 am

Correct, credentials are cached.
magreenblatt
Site Admin
 
Posts: 11090
Joined: Fri May 29, 2009 6:57 pm

Re: GetAuthCredentials works only once

Postby tniinisto » Wed Sep 05, 2018 4:46 am

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("", "");
tniinisto
Newbie
 
Posts: 5
Joined: Thu Aug 16, 2018 12:05 am

Re: GetAuthCredentials works only once

Postby magreenblatt » Wed Sep 05, 2018 6:32 am

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.
magreenblatt
Site Admin
 
Posts: 11090
Joined: Fri May 29, 2009 6:57 pm

Re: GetAuthCredentials works only once

Postby tniinisto » Thu Sep 06, 2018 2:15 am

Thinked another solution of closing Cef after the web form is closed.
Is this possible since the main form is still up and running?
tniinisto
Newbie
 
Posts: 5
Joined: Thu Aug 16, 2018 12:05 am

Re: GetAuthCredentials works only once

Postby magreenblatt » Thu Sep 06, 2018 3:21 am

You would likely need to restart the application.
magreenblatt
Site Admin
 
Posts: 11090
Joined: Fri May 29, 2009 6:57 pm

Re: GetAuthCredentials works only once

Postby pdooker » Fri May 07, 2021 9:55 am

Hello,

Is there any plan to address this cache clearing issue?

Thanks,

Paul
pdooker
Techie
 
Posts: 18
Joined: Fri Apr 21, 2017 12:16 pm

Re: GetAuthCredentials works only once

Postby magreenblatt » Fri May 07, 2021 12:00 pm

Use CefRequestContext::ClearHttpAuthCredentials
magreenblatt
Site Admin
 
Posts: 11090
Joined: Fri May 29, 2009 6:57 pm

Re: GetAuthCredentials works only once

Postby pdooker » Fri Jul 23, 2021 2:02 pm

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?
Attachments
Exception.PNG
Exception
Exception.PNG (30.36 KiB) Viewed 459 times
pdooker
Techie
 
Posts: 18
Joined: Fri Apr 21, 2017 12:16 pm

Re: GetAuthCredentials works only once

Postby pdooker » Thu Sep 09, 2021 5:09 pm

Has anyone been able to successfully use ClearHttpAuthCredentials?

I keep getting a crash when I call it.
pdooker
Techie
 
Posts: 18
Joined: Fri Apr 21, 2017 12:16 pm

Next

Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 20 guests