react-use-websocket icon indicating copy to clipboard operation
react-use-websocket copied to clipboard

Set cookies to the websocket URL

Open rajeshwarpatlolla opened this issue 2 years ago • 2 comments

How to set / attach cookies to the web socket connection URL? We are connecting to mattermost server for websocket connection. We need to set/attach some cookies for this connection to receive messages. How we set cookies in the headers?

Screenshot 2022-07-04 at 4 39 32 PM

rajeshwarpatlolla avatar Jul 04 '22 11:07 rajeshwarpatlolla

I'm not an expert in this so take this advice with caution. When using the Cloudflare Zero Trust proxy, I have the websocket client first establishes an HTTP/HTTPS connection with the websocket server to setup authentication cookies etc . Then requests from the browser to the websocket will include cookies. Currently I'm doing this with a redirect e.g. user connects to https://site.com and the client javascript checks the URL and redirects to the websocket server's url e.g. https://socket.site.com/authenticate which redirects back to https://site.com/authenticated (in Cloudflare Zero Trust I'm sharing the authentication for both domains and the user will have to login to get access to https://site.com to start with)

markNZed avatar Apr 09 '23 09:04 markNZed

Is there any solution for this issue?

ngoctq avatar Dec 19 '23 21:12 ngoctq