4

I'm attempting to login to my Rocket Chat install using the REST API. The login call comes back successful and I receive the AuthToken and userID. But I can not seem to bypass the login screen. In other words what I want to do is use my app to send over the login request and then because it is successful bypass the Rocket Chat login screen and go straight into the chat.

Thanks!

O2U
  • 409
  • 1
  • 6
  • 19
  • It's not clear what you are trying to do. Are you building a webapp? mobile app? Why would Rocket.Chat login screen show up. My guess is that you are building a webapp and you are using Rocket Chat's client. If you create your own client, there is no reason Rocket.Chat's login screen showing up – Danny Wang Oct 24 '16 at 04:58

2 Answers2

5

Logging in through Rocket.Chat's REST API and expecting the web browser to not require you to login again requires a few more steps.

When you authenticate with the REST API successfully the resulting object looks like (these are from a local development server):

{
    "status": "success",
    "data": {
        "authToken": "t2hjaCXP397DxwnYAgQtEaAULDjo4S5vXkopLr04LZL",
        "userId": "Q4KzBWSGtcCiKTtvC"
    }
}

From this result, you will need to take the authToken and set your in your web browser's LocalStorage Meteor.loginToken with the value of authToken. For example in this case, we would do the following:

var authToken = 'cXvkTF8X4uu-J_2uWelJGt4iuuTxjD5pFHuqhLOQRLJ';
localStorage.setItem('Meteor.loginToken', authToken);

Shortly after doing that, your Rocket.Chat screen should refresh and now you are logged in.

bradleyhilton
  • 366
  • 1
  • 3
  • 7
  • I tried your solution but it did not work. I am using ubuntu 16, having apache2 + php, rocket chat is on http://127.0.0.1:3000 and I called rest API on http://127.0.0.1/rocket.php, successfully got auth token and set in local storage but did not work. I installed rocket chat using "snap install rocketchat-server" command, Will you please give suggestion, where I am wrong? – Jass Aug 05 '17 at 13:30
  • Did you set the item in local storage exactly like suggested above? As it is case sensitive on every part. Also, did you try to refresh the page and look in local storage to see what was exactly set? – bradleyhilton Aug 07 '17 at 19:34
  • yes I tried both but it did not worked. I am still doing RND on it – Jass Aug 08 '17 at 13:29
  • @Jass did you manage to get anything working? As I just tried my code above again and it works still, so I am curious as to why it won't work when you try it.. – bradleyhilton Aug 18 '17 at 09:08
  • From my first comment what do you feel, Am I doing it in correct way? It is not working yet on my side – Jass Aug 18 '17 at 11:06
0

You can insert the token as resumeToken (previously obtained as authToken) in the same HTML:

https://yourown.rocket.chat/home?resumeToken=abcd123456789

(from https://docs.rocket.chat/guides/administrator-guides/authentication)

Jorge Rueda
  • 1
  • 1
  • 2