> For the complete documentation index, see [llms.txt](https://docs.weka.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.weka.io/security/obtain-authentication-tokens.md).

# Obtain authentication tokens

Obtain and manage WEKA access, refresh, and long-lived API tokens.

There are two types of authentication tokens: an access token and a refresh token.

* **Access token:** A short-lived token (valid for five minutes) used to access the NeuralMesh API and enable secure filesystem mounting.
* **Refresh token:** A long-lived token (one month by default, but customizable) used to obtain new access tokens as needed.

**Procedure**

Do one of the following:

* **Using the CLI**: To obtain the refresh token and access token through the **CLI**, log in to the system using the command: `weka user login`. For details, see [Manage users using the CLI](/operation-guide/user-management/user-management-1.md#log-in-to-the-weka-cluster).

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

<div data-with-frame="true"><img src="https://2924606337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDcZwR9zamxPsY03oTOq%2Fuploads%2Fgit-blob-0ba007f33058a9c8be61daeb488ab72b0918527d%2Fwmng_auth_token_example.png?alt=media" alt="Auth-token file content example"></div>

* **Using the REST API**: 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.

<div data-with-frame="true"><img src="https://2924606337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDcZwR9zamxPsY03oTOq%2Fuploads%2Fgit-blob-2ee49ceee806ce9e0d4cbc31af9f2a0f329ca005%2Fwmng_auth_token_api_example.png?alt=media" alt="REST API login response example"></div>

## Manage long-lived tokens for REST API usage

When working with the REST API, local users may use 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-lived access token using the GUI

Generate a long-lived access token for REST API authentication.

#### Before you begin

Sign in as a local user.

1. Open the signed-in user menu. Select **API Token**.
2. In **Manage API Token**, select **Generate token**. Set the expiration time. Select **Generate**.

<div data-with-frame="true"><figure><img src="https://2924606337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDcZwR9zamxPsY03oTOq%2Fuploads%2Fgit-blob-0a2421abe543aec014a3dcb28ff0b796f7f6cdfe%2Fmanage_api_token.png?alt=media" alt="Manage API Token dialog"><figcaption><p>Manage API Token</p></figcaption></figure></div>

{% hint style="info" %}
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.
4. In the three-dot menu, select **REST API**. The cluster REST API opens in your browser.
5. Select **Authorize**.

<div data-with-frame="true"><figure><img src="https://2924606337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDcZwR9zamxPsY03oTOq%2Fuploads%2Fdxazgv3XxWpqZuN4qSpI%2Frest_api_authorize.png?alt=media&amp;token=8c4dba83-8f04-4616-9885-f01ffa18bc7b" alt=""><figcaption><p>REST API</p></figcaption></figure></div>

6. In **Available authorizations**, paste the token. Select **Authorize**.

<div data-with-frame="true"><figure><img src="https://2924606337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDcZwR9zamxPsY03oTOq%2Fuploads%2FtcqPZdfZk29BL5bRvqEs%2FAuthorize_token.png?alt=media&amp;token=4c661793-2809-4fdc-a6a8-732c9e9bafb1" alt="Available authorizations dialog for the REST API" width="485"><figcaption><p>Available authorizations</p></figcaption></figure></div>

6. Use the REST API endpoints.

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

Generates a long-lived access token for REST API use, so automation does not have to log in with a password.

**Command:** `weka user generate-token`

```sh
weka user generate-token [--access-token-timeout <duration>] [--plain]
```

**Parameters**

| Parameter                            | Description                                                            |
| ------------------------------------ | ---------------------------------------------------------------------- |
| `--access-token-timeout` \<duration> | Duration until the access token expires.                               |
| `--plain`                            | Print the token to the console instead of copying it to the clipboard. |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.weka.io/security/obtain-authentication-tokens.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
