> For the complete documentation index, see [llms.txt](https://docs.facephi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/autenticacion.md).

# Authentication

Middleware API v2 endpoints are authenticated with a **consumer JWT token** sent in the `Authorization: Bearer <token>`. The token is issued based on the two concepts introduced in [Middleware API v2](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2.md): the **client platform** issues tokens for its **consumers**, and each operational call is made on behalf of a consumer.

### Identification headers

| Header             | Description                                                                                           |
| ------------------ | ----------------------------------------------------------------------------------------------------- |
| `platform-id`      | Identifies the client platform. Required only when issuing a consumer token (`POST /consumer/token`). |
| `platform-api-key` | Client platform API key. Required only when issuing a consumer token (`POST /consumer/token`).        |
| `consumer-id`      | Identifies the channel/consumer. Required for all operational endpoints.                              |

### Operational endpoint requirements

All Middleware API v2 operational endpoints require:

* **OAuth2 authentication**: the `Authorization: Bearer <token>`, obtained via `POST /consumer/token` (RS256-signed JWT, see below).
* Header **`consumer-id`**: consumer identifier. Required and must not be empty.
* Header **`operation-id`**: identifier of the [operation](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/operations.md) to which the referenced assets belong, as returned by `POST /operation`. Required for any endpoint whose request references stored assets, and always required for [Document Validation](https://docs.facephi.com/docs.facephi-en/rest-api/midapi-v2/document-services/document-validation.md), which only accepts references.

{% hint style="info" %}
Middleware API v2 does not use `x-api-key`. The scheme is OAuth2 Bearer + `consumer-id` (and `operation-id` for requests that reference stored assets).
{% endhint %}

## Obtaining a consumer token

Before invoking any operational endpoint, the consumer must obtain a JWT token and send it in the header `Authorization: Bearer <token>`. The token is issued by Facephi and includes the `consumer-id` and the scopes corresponding to the services enabled for that consumer.

### Endpoint

```
POST /consumer/token
```

### Headers

| Name                 | Type   | Required | Description                 |
| -------------------- | ------ | -------- | --------------------------- |
| **platform-id**      | string | **Yes**  | Client platform identifier. |
| **platform-api-key** | string | **Yes**  | Client platform API key.    |

### Request body

**Content-Type:** `application/json`

#### Parameters

| Parameter    | Type   | Required | Description                                                                        |
| ------------ | ------ | -------- | ---------------------------------------------------------------------------------- |
| `consumerId` | string | **Yes**  | Identifier of the consumer (channel or vertical) for which the token is requested. |

#### Request example

```json
{
  "consumerId": "<consumerId>"
}
```

### Responses

#### `200` Success

#### Response parameters

| Parameter    | Type   | Description                                                      |
| ------------ | ------ | ---------------------------------------------------------------- |
| `consumerId` | string | Consumer for which the token was issued.                         |
| `token`      | string | JWT token to send in the header `Authorization: Bearer <token>`. |
| `expiresAt`  | string | Token expiration date and time in **ISO 8601**.                  |

#### Example response

```json
{
  "consumerId": "<consumerId>",
  "token": "<jwt>",
  "expiresAt": "2026-06-26T13:00:00.000Z"
}
```

{% hint style="info" %}
The token is **valid for 1 hour** after issuance (the exact expiration time is returned in the `expiresAt`field). Once it expires, simply request a new one using the same endpoint. Each request validates the signature, issuer, `consumer-id`, expiration, and token scopes.
{% endhint %}
