# Authentication

## Authentication with email and password

<mark style="color:green;">`POST`</mark> `https://api.tiledesk.com/v3/auth/signin`

Allows to authenticate an agent using email and password.

#### Headers

| Name         | Type   | Description                  |
| ------------ | ------ | ---------------------------- |
| Content-Type | string | use "application/json" value |

#### Request Body

| Name     | Type   | Description            |
| -------- | ------ | ---------------------- |
| email    | string | the user email address |
| password | string | the user password      |

{% tabs %}
{% tab title="200 " %}

```
{
   "success":true,
   "token":"JWT  XYZ",
   "user":{
      "_id":"5ab11c6b83dc240014d46095",
      "email":"andrea.leo@f21.it"
   }
```

{% endtab %}
{% endtabs %}

## Anonymous authentication for a user

<mark style="color:green;">`POST`</mark> `https://api.tiledesk.com/v3/auth/signinAnonymously`

Allows a user to authenticate anonymously on the system.

#### Headers

| Name         | Type   | Description                  |
| ------------ | ------ | ---------------------------- |
| Content-Type | string | use "application/json" value |

#### Request Body

| Name        | Type   | Description                           |
| ----------- | ------ | ------------------------------------- |
| id\_project | string | the project to which the user belongs |
| firstname   | string | the user firstname                    |
| lastname    | string | the user password                     |
| email       | string | the user email                        |
| attributes  | object | the user custom attributes            |

{% tabs %}
{% tab title="200 " %}

```
{
   "success":true,
   "token":"JWT XYZ",
   "user":{
      "_id":"5e25944ecf6bcc00178e75fa",
      "email":"a0fe493b-a19b-44a0-99ce-414c65fc20b0@tiledesk.com",
      "emailverified":false,
      "createdAt":"2020-01-20T11:51:42.115Z",
      "updatedAt":"2020-01-20T11:51:42.115Z",
      "__v":0
   }
}
```

{% endtab %}
{% endtabs %}

## Custom authentication for a user

<mark style="color:green;">`POST`</mark> `https://api.tiledesk.com/v3/auth/signinWithCustomToken`

Allows to authenticate with a custom JWT token.

#### Headers

| Name          | Type   | Description                     |
| ------------- | ------ | ------------------------------- |
| Authorization | string | Custom JWT Authorization token. |

{% tabs %}
{% tab title="200 " %}

```
{
   "success":true,
   "token":"JWT eyJ0eXYZ",
   "user": {
     "_id":"123456",
     "firstname":"Andrea",
     "lastname":"Leo",
     "email":"andrea.l@test.it",
     "code":"123456",
     "sub":"userexternal",
     "aud":"https://tiledesk.com/projects/5ec688ed13400f0012c2edd1",
     "iat":1598865103,
     "exp":1598865223
  }
}
```

{% endtab %}
{% endtabs %}

Example:

```
curl 'https://api.tiledesk.com/v3/auth/signinWithCustomToken' \
  -X 'POST' \
  -H 'authorization: JWT eyJ0eXAiOiJKVXYZZ....ZZZZZ'
```

You can find here [How to Generate a Custom Authentication Token](https://developer.tiledesk.com/apis/authentication)


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.tiledesk.com/apis/rest-api/authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
