# Login

## user/login

<mark style="color:green;">`POST`</mark> `https://public-api.timesafe.io/user/login`

Questo servizio permette di ottenere un token JWT da usare per le chiamate successive.

#### Request Body

| Name   | Type   | Description                                                                                                                                                                                                                                  |
| ------ | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ttl    | string | Time To Live specifica in secondi la durata che il token generato deve avere. Può valere un minimo di 5 e un massimo di 86400, oppure "one-time". In questo caso il token non ha scadenza temporale, ma può essere usato una volta soltanto. |
| secret | string | password dell'utente                                                                                                                                                                                                                         |
| email  | string | email o codice identificativo dell'utente.                                                                                                                                                                                                   |

{% tabs %}
{% tab title="200 Autenticazione avvenuta con successo, risponde con token JWT da usare per le successive chiamate e dati dell'utente.
Notare che i campi TTL e issued esistono solo se si è specificato in fase di login un TTL" %}

```
{
    "status": "OK",
    "data": {
        "id": 374862,
        "cf": 11044930961,
        "email": "alan@timesafe.io",
        "sandbox": true,
        "status": "USER_LOGGED",
        "ttl": "one-time",  
        "issued": 1590561214,
        "token": "eyJhbGciOiAiSFMyNTYiLCJ0eXAiOiAiSldUIn0=.eyJpZCI6IjM3NDg2MiIsImNmIjoiMTEwNDQ5MzA5NjEiLCJlbWFpbCI6ImFsYW5AdGltZXNhZmUuaW8iLCJzYW5kYm94Ijp0cnVlLCJzdGF0dXMiOiJVU0VSX0xPR0dFRCIsInR0bCI6Im9uZS10aW1lIiwiaXNzdWVkIjoxNTkwNTYxMjE0fQ==.n3HcNb0jbqIVELGjOmrugUThGWCNdM8b+YHVlaamjlA="
    }
}
```

{% endtab %}

{% tab title="501 In caso di dati errati o mancanti." %}

```
// WRONG PASSWORD
{
    "error": {
        "code": "Wrong password",
        "details": "Wrong password."
    }
}

// WRONG USER
{
    "error": {
        "code": "5_topi_invalidi",
        "details": "This email is not valid."
    }
}

// MISSING ARGUMENT
{
    "error": {
        "code": "3_asini_tristi",
        "details": "Missing argument email."
    }
}
```

{% endtab %}
{% endtabs %}
