Websocket and Sessions

Brad2 years ago

Hello,
Thanks for the amazing efforts.

To deal with the websocket we have to include sessions token, right ? There's no other way to deal with the websocket, no?

I tried post and get methods for the session api to but did not receive a token in the response message or headers.

Also, I am trying to deal with the websocket between the client app and the web app server and could not find a specific doc for that. I am using socketio to perform the websocket connection between the two but was not able to find details on how to deal with such a thing to emit client data to the server.

Thanks again!

Anton Tananaev2 years ago

A session is the only way to authenticate WebSocket connection.

Please provide full response details from when you did POST/GET to the session API, including headers.

Anton Tananaev2 years ago

And also the request with headers.

Brad2 years ago
  • Request:

Firstly I did a POST request to: <server>/api/session (with Postman)
with headers: Cookie JESSIONID VALUE: node015feh....
Authorization as basic auth (username and password)
and with form-urlencoded body that contains the email and password.
and received a response shown below.

  • Response:

Status: 200 OK

Body:
Note: some values are replaced with <Name>

{
    "id": 3,
    "attributes": {},
    "name": "test",
    "login": null,
    "email": <MY_EMAIL>,
    "phone": null,
    "readonly": false,
    "administrator": true,
    "map": null,
    "latitude": <MY_LAT>,
    "longitude": <MY_LONG>,
    "zoom": 0,
    "twelveHourFormat": false,
    "coordinateFormat": null,
    "disabled": false,
    "expirationTime": null,
    "deviceLimit": -1,
    "userLimit": 0,
    "deviceReadonly": false,
    "limitCommands": false,
    "disableReports": false,
    "fixedEmail": false,
    "poiLayer": null,
    "password": null
}

Cookies:

Name: JESSIONID    Value: node015feh....

Headers:

Date
Content-Type
access-control..
Content-Length
Server
  • Didn't get any token even after doing GET request on /api/session
Anton Tananaev2 years ago

So you already have the session:

NAME: JESSIONID VALUE: node015feh....
Anton Tananaev2 years ago

Please in the future don't use all-caps. Makes it really hard to read and doesn't help anyone.

Brad2 years ago

I have the session but tried it and did not work.
I tried /api/session?token=<Value>

My bad, just edited the message and the all-caps text, sorry I typed the message quickly.

Anton Tananaev2 years ago

That's a session id. Why are you using as an access token?

Brad2 years ago

How can I create an access token ?

Sorry I am confused, how can I deal with the websocket exactly to start authenticating and establishing websocket connection between the client app and the web app server?

Anton Tananaev2 years ago

Are you asking about about access token or the session id (aka session token)?

Brad2 years ago

I am asking about the one needed for starting a websocket connection.

Anton Tananaev2 years ago

That's the session id cookie. That's what you need and you already have it.

Brad2 years ago

Thanks ! I really appreciate your responses and efforts.

Can you provide me with a doc or guide me on how can I start making a websocket connection between the client and the web app server to send data for each client app.

Anton Tananaev2 years ago
  1. Create a session
  2. Connect to the WebSocket endpoint using the same session
Brad2 years ago

Can I know the websocket endpoint?