> For the complete documentation index, see [llms.txt](https://docs-en.dydu.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-en.dydu.ai/developers/api-reference/authentication.md).

# Authentication

Most APIs of the Dydu solution require authentication: a token to put in the `Authorization` header of your requests (**Authorization** field in the Swagger interface).

Two types of token are accepted:

* **Basic**: built from your login and password;
* **Bearer**: a temporary token provided by the authentication API.

## Basic authentication

To build the token:

1. Concatenate your login, the ":" character and your password (case-sensitive).
2. Encode this string in base64.
3. Add "Basic" followed by a space before the result.

> Example:&#x20;
>
> 1\. "<demo@dydu.ai>:MyPassword"
>
> 2\. "ZGVtb0BkeWR1LmFpOk15UGFzc3dvcmQ="
>
> 3\. "Basic ZGVtb0BkeWR1LmFpOk15UGFzc3dvcmQ="

You can also generate this token from the `https://<server>/servlet/authentication.html` page: enter your login and password, then click **Generate**. The token is computed in your browser.

{% hint style="info" %}
Replace `<server>` with the address of your platform
{% endhint %}

## Bearer authentication

You can get a temporary token with the **POST /authentication/token** API (**Account** category of the Swagger interface). This token is valid for 8 hours.

| Parameter  | Description    | Required |
| ---------- | -------------- | -------- |
| `login`    | Your login.    | Yes      |
| `password` | Your password. | Yes      |

curl request:

```
curl -X POST "https://<server>/servlet/api/authentication/token" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "login=demo@dydu.ai&password=MyPassword"
```

The response is a text that directly contains the value to put in the `Authorization` header:

```
Bearer eyJhbGciOi...
```

If the login or password is wrong, the API returns a **401** "Invalid authentication" error.

## Using the token

Put the whole token, with "Basic" or "Bearer", in the `Authorization` header:

```
curl -X GET "https://<server>/servlet/api/..." -H "Authorization: Basic ZGVtb0BkeWR1LmFpOk15UGFzc3dvcmQ="
```

{% hint style="warning" %}
If an API returns a **401** error, check your login and password, and that you did not forget "Basic" or "Bearer" before the token.
{% endhint %}
