Create token for websocket connection


#1

I’m using rocket-chat with a custom frontend.

In order to use the realtime API via websocket, I create tokens for the users as follows:

  1. login with admin credentials vie REST API
  2. create a user token (https://rocket.chat/docs/developer-guides/rest-api/users/createtoken/)
  3. pass that token to the client frontend
  4. client uses this token in order to connect to websocket (https://rocket.chat/docs/developer-guides/realtime-api/method-calls/login/#using-an-authentication-token)

The answer that I receive in step 2 returns the user’s id and a token. When I use this token to connect to the websocket, I receive a message through websocket that says that the admin user has been added instead of the user, the token was generated for.
So the token seems to be the admin’s auth token.

Is this expected behavior or am I doing something wrong?

Thanks in advance


#2

It’s now working for me as expected.
The client is logged in as user (not as admin).
I’m not sure what was my mistake, but I’m happy it’s working :slight_smile:


#3

I’d love to see some details of how you achieved this. I have been struggling with oAuth and Wordpress but still have to press the login button after I logged in with Wordpress.


#4

I’m not using oauth.
I use a this rails gem to create the user token: https://github.com/abrom/rocketchat-ruby
And I use this library to connect to the websocket: https://github.com/inf3cti0n95/Rocket.Chat.RealTime.API.RxJS


#5

Ok thanks. If I can’t get oAuth to work I might try this method too.