Connecting to WebSockets using session cookies

Nelio Lucas 7 years ago

Hi,

I read through some of the documentation and other topics and i really cant figure out (dont understand) how session cookies are used to authorize websocket connections and how to include them in the request header.
What i have done/am doing
i built a custom client application in java and am attempting to establish a websocket connection.

What i would like to know
How to include session cookies in a websocket request (perhaps with some sample code?)

Anton Tananaev 7 years ago

Same way you include it in any other HTTP request.

Nelio Lucas 7 years ago

So in other words something like

setHeader("Cookie","sessionid"+<MY_SESSION_ID>)

?

Anton Tananaev 7 years ago

I would recommend you to check what official web app sends. It should clear any questions you have.

Nelio Lucas 7 years ago

thanks ill have a look

Peter G 4 years ago

Documenting in case it helps someone.
Here are the steps

  1. Do a POST to /api/session with form parameters email and password with the right values.
  2. Take the JSESSIONID cookie from the response once the login is successful and set it as a cookie (with the same) in the web socket connection request.