API version: 0.3.0

---

# Authentication

Every API request can either include an `Authorization` header or not.

If the header is missing, the request is executed with the permissions of the anonymous user - see the
[configuration reference](/reference/configuration.md) for the `ANONYMOUS_USER_UUID` environment variable that controls
which user that is.

The `Authorization` header carries a bearer token, e.g.:

```txt
Authorization: Bearer secret-token:M3WHIDj4q62EY0XiZFMLnv
```

## How to get a token

Tokens can be created in three ways:

1. Through the [`POST /token`](/api/post-token.md) endpoint.
2. Through the [`token:create`](/command/token-create.md) CLI command.
3. Tokens without an expiration date can be created by removing the `expirationDate` property from a token object
   directly in the Neo4j database or in a backup file.

> **⚠ Discouraged in production**
>
> Creating tokens without an expiration date by editing the database directly is highly discouraged for any
> production system - prefer the endpoint or the CLI command, which both issue tokens with a proper lifetime.

## Example

```bash
curl \
  -H 'Content-Type: application/json' \
  -d '{
        "type": "Token",
        "uniqueUserIdentifier": "test@localhost.dev",
        "password": "1234"
      }' \
  https://api.example.com/token
```

Response:

```json
{
  "type": "_TokenResponse",
  "token": "secret-token:M3WHIDj4q62EY0XiZFMLnv"
}
```

The value of `$.token` is the new bearer token, ready to be sent in the `Authorization` header of subsequent
requests. See [first API requests](/getting-started/first-api-requests.md) for a full walkthrough.

Tokens have a limited lifetime and must be recreated once they expire; see the `token.*` settings in the
configuration reference for the configurable minimum, default and maximum lifetimes. A
user may hold an unlimited number of active tokens at the same time.

## Tokens with capabilities

Most requests only need an ordinary token like the one above. Some instance-wide functionality, e.g. changing
[schemas](/guide/defining-a-schema.md) or assigning roles, is protected by capabilities, which a user gets through their
roles. A token has no capabilities by default, even if the user has them; request the ones you need in `capabilities`
when you create the token:

```bash
curl \
  -H 'Content-Type: application/json' \
  -d '{
        "type": "Token",
        "uniqueUserIdentifier": "test@localhost.dev",
        "password": "1234",
        "capabilities": [
          "schema.manage"
        ]
      }' \
  https://api.example.com/token
```

The response looks like the one above. Capabilities which the user does not have are refused with `403 Forbidden`.
See [roles and capabilities](/reference/roles-and-capabilities.md) for the available capabilities and roles.

---

Home: [Ember Nexus API docs](/index.md)

Full site map: [llms.txt](/llms.txt)

Previous: [First API requests](/getting-started/first-api-requests.md)

Next: [Elements](/guide/elements.md)
