As a workspace admin, you can create temporary authentication tokens for users. This is the same type of session authentication token a user gets via login.md and expires the same way.
{% hint style="info" %}
- To use this endpoint, you must add the environment variable
CREATE_TOKENS_FOR_USERS=true
in your compose file. - For SaaS workspaces, contact support to set this variable. {% endhint %}
{% hint style="info" %}
You are required to have the user-generate-access-token
permission.
{% endhint %}
For example, if you use Snaps to deploy, set the environment variable as shown below:
{% code overflow="wrap" %}
echo "CREATE_TOKENS_FOR_USERS=true" > /var/snap/rocketchat-server/common/create-tokens.env
sudo systemctl restart snap.rocketchat-server.rocketchat-server.service
{% endcode %}
HTTP Method | URL | Requires Auth |
---|---|---|
POST | /api/v1/users.createToken | yes |
Key | Example Value | Description |
---|---|---|
userId * or username * | BsNr28znDkG8aeo7W or test | The ID or username of the user. |
With userId
:
curl -H "X-Auth-Token: 9HqLlyZOugoStsXCUfD_0YdwnNnunAJF8V47U3QHXSq" \
-H "X-User-Id: aobEdbYhXfu5hkeqG" \
-H "Content-type:application/json" \
http://localhost:3000/api/v1/users.createToken \
-d '{
"userId": "BsNr28znDkG8aeo7W" }'
With username
:
curl -H "X-Auth-Token: 9HqLlyZOugoStsXCUfD_0YdwnNnunAJF8V47U3QHXSq" \
-H "X-User-Id: aobEdbYhXfu5hkeqG" \
-H "Content-type:application/json" \
http://localhost:3000/api/v1/users.createToken \
-d '{ "username": "test" }'
{
"data": {
"userId": "BsNr28znDkG8aeo7W",
"authToken": "2jdk99wuSjXPO201XlAks9sjDjAhSJmskAKW301mSuj9Sk",
},
"success": true
}
Version | Description |
---|---|
2.1.0 | Added ENV VAR to be able to use this endpoint (process.env.CREATE_TOKENS_FOR_USERS). |
0.56.0 | Added |