Create token for websocket connection


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 (
  3. pass that token to the client frontend
  4. client uses this token in order to connect to websocket (

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


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:


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.


I’m not using oauth.
I use a this rails gem to create the user token:
And I use this library to connect to the websocket:


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