> For the complete documentation index, see [llms.txt](https://docs.enclaive.cloud/enclaive-multi-cloud-platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.enclaive.cloud/enclaive-multi-cloud-platform/developers/api/client-api/auth.md).

# Auth

Our API uses JSON Web Tokens (JWTs) for authentication. JWTs are a secure and efficient way to authenticate users.

To authenticate with our API, users must first create an account. Once they have created an account, they can generate a JWT by providing their username and password.

JWTs are signed with a secret key, which ensures that they are tamper-proof. They also contain an expiration date, which helps to prevent them from being used after they have expired.

To authenticate with our API, users must include their JWT in the Authorization header of their HTTP requests. The format of the Authorization header is as follows:

```
Authorization: Bearer <jwt>
```

where `<jwt>` is the JWT token.

Once the API has verified the JWT, it will grant the user access to the resources that they are authorized to access.

## Login

<mark style="color:green;">`POST`</mark> `{{BASE_URL}}/api/login`

User authentication via email and password fields.

#### Request Body

| Name                                       | Type   | Description |
| ------------------------------------------ | ------ | ----------- |
| email<mark style="color:red;">\*</mark>    | String |             |
| password<mark style="color:red;">\*</mark> | String |             |

{% tabs %}
{% tab title="201: Created " %}

```json
{
    "userToken": "userToken",
    "vaultToken": "teamToken"
}
```

{% endtab %}
{% endtabs %}

## Create User

<mark style="color:green;">`POST`</mark> `{{BASE_URL}}/api/register`

User Registration. After registration you will need to confirm your email.

#### Request Body

| Name                                       | Type   | Description |
| ------------------------------------------ | ------ | ----------- |
| email<mark style="color:red;">\*</mark>    | String |             |
| password<mark style="color:red;">\*</mark> | String |             |
| name<mark style="color:red;">\*</mark>     | String |             |

{% tabs %}
{% tab title="201: Created " %}

```json
{
    "userToken": "userToken",
    "vaultToken": "teamToken"
}
```

{% endtab %}
{% endtabs %}

After registration, a confirmation email will be sent to the user.

## Verify email

<mark style="color:blue;">`GET`</mark> `{{BASE_URL}}/api/verify-email/{token}`

User confirmation via email.

#### Path Parameters

| Name                                    | Type   | Description  |
| --------------------------------------- | ------ | ------------ |
| token<mark style="color:red;">\*</mark> | String | Bearer Token |

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

```json
{
    "userToken": "userToken",
    "vaultToken": "teamToken"
}
```

{% endtab %}
{% endtabs %}

After verification, a default team and a default project will be created for the client.

If the letter has not arrived in the post, you can use the endpoint below to resend it.

## Resend email verification

<mark style="color:blue;">`GET`</mark> `{{BASE_URL}}/api/resend-email-verification`

Request to resend the user's confirmation email to the user's email.

#### Query Parameters

| Name                                     | Type   | Description |
| ---------------------------------------- | ------ | ----------- |
| capcha<mark style="color:red;">\*</mark> | String |             |

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

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

```json
{
    "userToken": "userToken",
    "vaultToken": "teamToken"
}
```

{% endtab %}
{% endtabs %}

## Refresh token

<mark style="color:blue;">`GET`</mark> `{{BASE_URL}}/api/refresh`

Update jwt tokens.

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

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

```json
{
    "userToken": "userToken",
    "vaultToken": "teamToken"
}
```

{% endtab %}
{% endtabs %}

If a customer forgets their password, they can use the endpoint below. An email will then be sent to the user to recover the password.

## Forgot password

<mark style="color:green;">`POST`</mark> `{{BASE_URL}}/api/forgot-passsword`

Password recovery via email.

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

#### Request Body

| Name                                    | Type   | Description |
| --------------------------------------- | ------ | ----------- |
| email<mark style="color:red;">\*</mark> | String |             |

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

```json
{
    "status": "ok"
}
```

{% endtab %}
{% endtabs %}

## Reset password

<mark style="color:green;">`POST`</mark> `{{BASE_URL}}/api/reset-passsword`

Updates the password for the user.

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

#### Request Body

| Name                                          | Type   | Description  |
| --------------------------------------------- | ------ | ------------ |
| token<mark style="color:red;">\*</mark>       | String | Bearer Token |
| newPassword<mark style="color:red;">\*</mark> | String |              |

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

```json
{
    "status": "ok"
}
```

{% endtab %}
{% endtabs %}

Before registering a user, you can check if there is a user with that email address.

## Check if a user with this email address exists

<mark style="color:blue;">`GET`</mark> `{{BASE_URL}}/api/exist-email/{email}`

Check if there is a user with the specified email address.

#### Path Parameters

| Name                                    | Type   | Description |
| --------------------------------------- | ------ | ----------- |
| email<mark style="color:red;">\*</mark> | String |             |

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

```json
true | false
```

{% endtab %}
{% endtabs %}
