websocket authentication not working within custom cef

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.

websocket authentication not working within custom cef

Postby ssaraf » Wed Jan 25, 2023 4:38 am

Hi, in our custom CEF C++ browser, websocket authentication is not working.

Error: WebSocket authentication failed; HTTP Authentication failed.

It seems like authentication is added within "OnBeforeResourceLoad" and that isn't called for websocket requests. How can we make this work?
ssaraf
Techie
 
Posts: 31
Joined: Mon Nov 09, 2020 2:18 am

Re: websocket authentication not working within custom cef

Postby magreenblatt » Wed Jan 25, 2023 9:23 am

What OS and CEF version? Does the problem reproduce with the CEF sample apps? If so, can you provide a URL that reproduces the issue?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: websocket authentication not working within custom cef

Postby ssaraf » Fri Jan 27, 2023 2:55 am

Windows, CEF 4324

Not replicable in cef, we have our custom application. Is there something we can check to see why authentication is not working?

OnBeforeResourceLoad is used for authentication for normal requests, can we do the same for web sockets auth? Is there an API for it?
ssaraf
Techie
 
Posts: 31
Joined: Mon Nov 09, 2020 2:18 am

Re: websocket authentication not working within custom cef

Postby magreenblatt » Fri Jan 27, 2023 10:19 am

There is no callback specifically for websocket requests. What are you adding in OnBeforeResourceLoad for normal requests? Can you use a cookie instead?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: websocket authentication not working within custom cef

Postby ssaraf » Mon Jan 30, 2023 12:54 am

We are just authenticating using auth token/otp.

---> Can you use a cookie instead?

Yes we can, how can we do that?
ssaraf
Techie
 
Posts: 31
Joined: Mon Nov 09, 2020 2:18 am

Re: websocket authentication not working within custom cef

Postby magreenblatt » Mon Jan 30, 2023 9:17 am

Set a cookie using the CefCookieManager before initiating the websocket request.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: websocket authentication not working within custom cef

Postby ssaraf » Wed Feb 01, 2023 1:36 am

I am setting the cookie but it doesnt work:

const std::string url = request->GetURL();

CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager(NULL);
CefCookie cookie;
CefString(&cookie.name).FromASCII("my_cookie");
CefString(&cookie.value).FromASCII("My Value");
CefString(&cookie.domain).FromASCII(url.c_str());
CefString(&cookie.path).FromASCII("/");
cookie.has_expires = true;
cookie.expires.year = 220;
cookie.expires.month = 4;
cookie.expires.day_of_week = 5;
cookie.expires.day_of_month = 11;

manager->SetCookie(url, cookie, NULL);

-> the websocket has wss scheme.
ssaraf
Techie
 
Posts: 31
Joined: Mon Nov 09, 2020 2:18 am

Re: websocket authentication not working within custom cef

Postby magreenblatt » Wed Feb 01, 2023 11:29 am

Your cookie.domain and cookie.expires.year (and possibly other) values are wrong. For the domain, see https://developer.mozilla.org/en-US/doc ... TP/Cookies "Domain attribute" section.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

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