Error "You must be logged in to do this" with status code 401Unauthorized

Description

I am trying to call REST API methods and I am getting this error message “You must be logged in to do this” with status code 401Unauthorized. This would be okay if that user credentials were not alright, BUT they are correct. And I can login and get the user ID plus the authToken but when I try to call any REST API method I get 401 Unauthorized.

Just to clarify further that this has nothing to do with the user credentials I am using, I can log in to the server with that user credentials but only when I try to call the REST API methods it show 401.

Can someone help?

Server Setup Information

  • Version of Rocket.Chat Server: 3.7.1
  • Operating System: linux
  • Deployment Method: docker
  • Number of Running Instances: 1
  • DB Replicaset Oplog: none
  • NodeJS Version: v12.18.4
  • MongoDB Version: 4.0.20
  • Proxy: none
  • Firewalls involved: none

Any additional Information

I did setup the server on October 28, 2020 and it was working fine, until I restarted the server and did a migration on December 18, 2020. Since then I cannot use REST API and all I get is the 401 Unauthorized error. I would like to understand the cause and how to mitigate this.

Thanks in advance

Did you ever clear this up? Seems like I am having the same issue.

Hi!

Usually this can happen while using the user and password to get the token.

When this happens, it will invalidate previous tokens, so you endup with login errors like this one.

While using the REST API, on integrations and what not, create a personal access token. This will generate a long lived token, while also saving one hit into the API (while getting the token with username and password)

For generating the personal access token, you need to access the web interface with the user, click on your “avatar” and go to “My Account” and " Personal Access Tokens". Make sure to check Ignore Two Factor Authentication

Let me know if this helped.

1 Like

Thx a lot - this helped me with problem of one user not able to login.

I still wonder why only one user had this problem and why others not…

1 Like