Page 1 of 1
websocket authentication not working within custom cef
Posted:
Wed Jan 25, 2023 4:38 am
by ssaraf
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?
Re: websocket authentication not working within custom cef
Posted:
Wed Jan 25, 2023 9:23 am
by magreenblatt
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?
Re: websocket authentication not working within custom cef
Posted:
Fri Jan 27, 2023 2:55 am
by ssaraf
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?
Re: websocket authentication not working within custom cef
Posted:
Fri Jan 27, 2023 10:19 am
by magreenblatt
There is no callback specifically for websocket requests. What are you adding in OnBeforeResourceLoad for normal requests? Can you use a cookie instead?
Re: websocket authentication not working within custom cef
Posted:
Mon Jan 30, 2023 12:54 am
by ssaraf
We are just authenticating using auth token/otp.
---> Can you use a cookie instead?
Yes we can, how can we do that?
Re: websocket authentication not working within custom cef
Posted:
Mon Jan 30, 2023 9:17 am
by magreenblatt
Set a cookie using the CefCookieManager before initiating the websocket request.
Re: websocket authentication not working within custom cef
Posted:
Wed Feb 01, 2023 1:36 am
by ssaraf
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.
Re: websocket authentication not working within custom cef
Posted:
Wed Feb 01, 2023 11:29 am
by magreenblatt
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.