# Obtain authentication tokens

The authentication tokens include two types: an access token and a refresh token.

* **Access token:** The access token is a short-lived token (five minutes) used for accessing the WEKA system API and to allow the mounting of secure filesystems.
* **Refresh token:** The refresh token is a long-lived token for obtaining an additional access token.

**Procedure**

Do one of the following:

* To obtain the refresh token and access token, **through the CLI**, log in to the system using the command: `weka user login`.

  The system creates an authentication token file and saves it in: `~/.weka/auth-token.json`. The token file contains both the access token and refresh token.

![Auth-token file content example](https://1916840177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTUYL9RLgSDAkF2U90csR%2Fuploads%2FpxGaELWw5ZH4mSqVqqtT%2Fwmng_auth_token_example.png?alt=media\&token=8243d807-ea0b-4a12-91c0-277e768fa2fa)

* To obtain the refresh token and access token, **through the REST API,** use the `POST /login`. The API returns the token in the response body.

![REST API login response example](https://1916840177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTUYL9RLgSDAkF2U90csR%2Fuploads%2FDV7xVf9qo3Rd9H9Deg6x%2Fwmng_auth_token_api_example.png?alt=media\&token=1fe2045e-7b28-4a33-9624-a1f48876919f)

## Manage long-lived tokens for REST API usage

When working with the REST API, local users may require using a long-lived token (a token that doesn't require a refresh every 5 minutes).

As a local user, you can generate a long-lived token using the GUI or the CLI.

### Generate a long-live access token using the GUI

**Procedure**

1. From the signed-in user menu, select **API Token**.
2. In the Manage API Token dialog, select Generate token and set the expiration time. Then, select **Generate**.

<figure><img src="https://1916840177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTUYL9RLgSDAkF2U90csR%2Fuploads%2FsS2iIGMt7fvLidgyqnII%2Fwmng_manage_api_token.png?alt=media&#x26;token=730515c2-f5a9-4728-a139-6cc833a4612d" alt=""><figcaption><p>Manage API Token</p></figcaption></figure>

{% hint style="info" %}
**Note:** If you want to revoke all existing login tokens of the local user and refresh them, select **Revoke Tokens**.
{% endhint %}

3\. Copy the generated token and paste it to the REST API authorization dialog.

<figure><img src="https://1916840177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTUYL9RLgSDAkF2U90csR%2Fuploads%2FREc5EdtChTqklF11SaUQ%2Fwmng_manage_api_token_generated.png?alt=media&#x26;token=1e4a3b9c-ef1c-4442-ad6b-64798bcfa761" alt=""><figcaption><p>Generated token</p></figcaption></figure>

The following demonstrates how to generate the API token and authorize it in the REST API.

<figure><img src="https://1916840177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTUYL9RLgSDAkF2U90csR%2Fuploads%2FNHlT5HS6gbzTe1wI0jAn%2Fwmng_generate_token_example_animated.gif?alt=media&#x26;token=1f8ca149-4f70-4103-90d4-3ffa9ec3c68f" alt=""><figcaption><p>Generate a long-lived token using the GUI example</p></figcaption></figure>

### Generate a long-lived access token using the CLI

**Command:** `weka user generate-token [--access-token-timeout timeout]`

The default timeout is 30 days.

To revoke the access and refresh tokens, use the CLI command: `weka user revoke-tokens`.
