> 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/identity-api/identity-api-reference/authentication/authenticate-user-v3.md).

# Authenticate User V3

/authenticateUser/v3

#### Description

This service provides biometric template persistence and 1:1 facial authentication against stored templates. It supports two operating modes within a single endpoint, determined by the request body:

* **Enroll mode**: Validates the liveness check and performs facial matching between a provided biometric template and a live capture, then persists the template associated with a `userId`.
* **Authenticate mode**: Retrieves a template previously stored for `userId` and performs 1:1 facial matching and liveness check validation against a new live capture.

#### Functionality

* **Enroll**: The `userId` is sent along with the biometric template (`templateRaw`) and the best tokenized image (`bestImageToken`). The liveness check and facial matching are validated. If both succeed, the template associated with the user is persisted. If the user already exists, the template is updated.
* **Authenticate**: The `userId` is sent along with the `bestImageToken` from the current session. The stored template is retrieved, and 1:1 matching is performed against the live capture. The authentication result is returned with the similarity score.

#### Use cases

1. **Client without previous onboarding with Facephi**: During password recovery, the client completes onboarding that generates a biometric template. This template is enrolled through this endpoint and associated with a `userId`. Future password recoveries authenticate directly against the stored template without repeating onboarding.
2. **Client with previous onboarding with Facephi**: The client already has a stored template. Subsequent authentication uses the 1:1 matching flow against the stored template.

### Integration

Requires implementation of the **Selphi Mobile Widget** or the **Selphi Web Widget** to generate the `bestImageToken` and the biometric template (`templateRaw`).

### Endpoint

```
POST /services/authenticateUser/v3
```

### Headers

| Header       | Type   | Required | Description                         |
| ------------ | ------ | -------- | ----------------------------------- |
| x-api-key    | String | Yes      | Tenant API key                      |
| Content-Type | String | Yes      | `application/json`                  |
| family       | String | No       | Family header required for tracking |

> All calls to Identity Platform endpoints with tracking must include the header `family`.

***

{% hint style="warning" %}
**Maximum request size: 6 MB.** The template, tokenized image, and Base64 tracking token (`templateRaw`, `bestImageToken` and `extraData`) count toward this limit together, with \~33% overhead over the original files (maximum total size of original files: \~4.5 MB). Compressed JPEG images of 1–2 MB each at most are recommended. If the limit is exceeded, the gateway responds `413` without processing the request. See [Request size limit](https://docs.facephi.com/pages/bc7bee9358079d52bafa44ad281828eb424e96fe#l%C3%ADmite-de-tama%C3%B1o-de-la-solicitud).
{% endhint %}

### Enroll mode

Enrolls or updates a biometric template for a user. Liveness check and facial matching must succeed before the template is persisted.

The presence of the `templateRaw` field in the request body activates this mode.

#### Request body

Content-Type: application/json

#### Parameters

| Parameter      | Type (Content)  | Required | Description                                                                                                                                                                               |
| -------------- | --------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| userId         | String          | Yes      | Unique user identifier. Must be at least 2 characters long.                                                                                                                               |
| templateRaw    | String (Base64) | Yes      | Facial biometric template generated from the best image during the onboarding process. Its presence activates **enroll mode**.                                                            |
| bestImageToken | String (Base64) | Yes      | Best tokenized facial image generated by the Selphi Widget. Used for liveness check and facial matching against the `templateRaw` to verify that they correspond to the same live person. |
| tracking       | JSON Object     | No       | Object containing tracking information.                                                                                                                                                   |
| extraData      | String (Base64) | No       | Token generated by the SDK Mobile/Web that contains tokenized tracking information.                                                                                                       |
| operationId    | String          | No       | Operation identifier generated by the SDK Mobile/Web.                                                                                                                                     |

#### Enroll request example

```json
{
    "userId": "user-001",
    "templateRaw": "BAEBAQIxLiHIhMPQWaUo…",
    "bestImageToken": "BgEBAQJksxGtVd++lRjN…",
    "tracking": {
        "extraData": "BQABAQG2gBNjuHN...",
        "operationId": "123e4567-e89b-12d3-a456-426614174000"
    }
}
```

#### Enroll behavior

1. **Liveness check**: Validates that the `bestImageToken` belongs to a live person.
2. **Facial Matching**: Performs 1:1 Matching between `templateRaw` and `bestImageToken` to verify that they belong to the same person.
3. **Persistence**: If both checks pass, looks up the `userId`:
   * If the user **does not exist**: creates the user and stores the template.
   * If the user **already exists**: updates the stored template with the new one.
4. **TTL** (if configured): The stored template expires after the period specified by `templateTTLSeconds`, starting from the time of enrollment. An expired template can no longer be used for authentication (`-105`). A new enrollment for the same `userId` replaces it and resets the expiration period.

***

### Authenticate mode

Authenticates a user by comparing a live capture against their previously stored biometric template. This mode is activated when `templateRaw` **is not** included in the request body.

> **Important**: The user must have been enrolled previously (through enroll mode or the v1/v2 self-registration flow) before they can be authenticated. Attempting to authenticate a user who has not been enrolled returns a `User not found`.

#### Parameters

| Parameter      | Type (Content)  | Required | Description                                                                                                                                           |
| -------------- | --------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| userId         | String          | Yes      | Unique identifier of the user to authenticate. Must be at least 2 characters long.                                                                    |
| bestImageToken | String (Base64) | Yes      | Best tokenized facial image from the current authentication session. Used for liveness check validation and 1:1 Matching against the stored template. |
| tracking       | JSON Object     | No       | Object containing tracking information.                                                                                                               |
| extraData      | String (Base64) | No       | Token generated by the SDK Mobile/Web that contains tokenized tracking information.                                                                   |
| operationId    | String          | No       | Operation identifier generated by the SDK Mobile/Web.                                                                                                 |

#### Request example: Authenticate

```json
{
    "userId": "user-001",
    "bestImageToken": "BgEBAQJksxGtVd++lRjN…",
    "tracking": {
        "extraData": "BQABAQG2gBNjuHN...",
        "operationId": "123e4567-e89b-12d3-a456-426614174000"
    }
}
```

#### Authentication behavior

1. **User lookup**: Retrieves the stored template associated with the `userId`.
2. **TTL check**: If the template has a configured expiration and it has passed, returns `serviceResultCode` `-105` with `serviceResultLog` `Template expired`.
3. **Liveness check**: Validates that the `bestImageToken` belongs to a live person.
4. **Facial Matching**: Performs 1:1 Matching between the stored template and the `bestImageToken`.
5. **Result**: Returns the matching result, including similarity score, authentication status, and liveness check diagnostics.

***

### Responses

#### 200 Success

#### Response parameters

| Identifier                        | Type    | Description                                                                                                                                            |
| --------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| serviceResultCode                 | Integer | Code indicating the overall result of the service execution. See the Service Result Code table below.                                                  |
| serviceResultLog                  | String  | Descriptive field for the execution result. Empty on success.                                                                                          |
| serviceFacialSimilarityResult     | Float   | Value indicating the facial similarity between the template and the bestImageToken. 1.0 = 100%. Present only when biometric matching is performed.     |
| serviceFacialAuthenticationLog    | String  | Descriptive field for the facial authentication result (e.g., "Positive", "Negative", "Uncertain"). Present only when biometric matching is performed. |
| serviceFacialAuthenticationResult | Integer | Code indicating the facial authentication result. See Table 2 - Service Facial Authentication Result.                                                  |
| serviceLivenessLog                | String  | Descriptive field for the passive liveness check result (e.g., "Live", "Spoof"). Present only when the liveness check is evaluated.                    |
| serviceLivenessResult             | Integer | Code indicating the result of the passive liveness check evaluation. See Table 3 - Service Liveness Result.                                            |
| timestamp                         | String  | Response timestamp (UTC) in the format: YYYY-MM-DDThh:mm:ssZ                                                                                           |
| transactionId                     | String  | Transaction identifier associated with the request processed by the API.                                                                               |

#### Service Result Code

The  `serviceResultCode`  indicates the overall result of the service execution:

| serviceResultCode | Description                                                          | HTTP code |
| ----------------- | -------------------------------------------------------------------- | --------- |
| 0                 | Successful operation (enrollment completed or user authenticated).   | 200       |
| -101              | The bestImageToken does not correspond to a live person.             | 200       |
| -102              | User authentication failed: negative facial match.                   | 200       |
| -103              | User not found (authenticate mode only).                             | 404       |
| -104              | Template not found: the user exists but has no stored template.      | 404       |
| -105              | Template expired: TTL exceeded; the template is no longer available. | 200       |

#### Service Liveness Result

The  `serviceLivenessResult`  indicates the result of the passive liveness check evaluation:

<details>

<summary>Service Liveness Result</summary>

<table><thead><tr><th width="101.947998046875">Code</th><th>Result</th><th width="251.6302490234375">Description</th></tr></thead><tbody><tr><td>0</td><td>None</td><td>The liveness check could not be evaluated.</td></tr><tr><td>1</td><td>Spoof</td><td>DEPRECATED. Use 'NoLive' instead.</td></tr><tr><td>2</td><td>Uncertain</td><td>DEPRECATED</td></tr><tr><td>3</td><td>Live</td><td>The subject is assumed to be alive.</td></tr><tr><td>4</td><td>NoneBecauseBadQuality</td><td>The liveness check could not be evaluated due to poor image quality.</td></tr><tr><td>5</td><td>NoneBecauseFaceTooClose</td><td>The liveness check could not be evaluated because the detected faces are too close to the edges.</td></tr><tr><td>6</td><td>NoneBecauseFaceNotFound</td><td>The liveness check could not be evaluated because no faces were detected.</td></tr><tr><td>7</td><td>NoneBecauseFaceTooSmall</td><td>The liveness check could not be evaluated because the detected faces are too small.</td></tr><tr><td>8</td><td>NoneBecauseAngleTooLarge</td><td>The liveness check could not be evaluated because the angle between faces exceeds the permitted limit.</td></tr><tr><td>9</td><td>NoneBecauseImageDataError</td><td>The liveness check could not be evaluated due to errors in the image format.</td></tr><tr><td>10</td><td>NoneBecauseInternalError</td><td>The liveness check could not be evaluated due to an internal error.</td></tr><tr><td>11</td><td>NoneBecauseImagePreprocessError</td><td>The liveness check could not be evaluated due to an image preprocessing error.</td></tr><tr><td>12</td><td>NoneBecauseTooManyFaces</td><td>The liveness check could not be evaluated because too many faces were detected in the image.</td></tr><tr><td>13</td><td>NoneBecauseFaceTooCloseToBorder</td><td>The liveness check could not be evaluated because the face is too close to the edge.</td></tr><tr><td>14</td><td>NoneBecauseFaceCropped</td><td>The liveness check could not be evaluated because the face is cropped.</td></tr><tr><td>15</td><td>NoneBecauseLicenseError</td><td>The liveness check could not be evaluated due to a license error.</td></tr><tr><td>16</td><td>NoneBecauseFaceOccluded</td><td>The liveness check could not be evaluated because the face is occluded.</td></tr><tr><td>17</td><td>NoLive</td><td>No signs of life were detected.</td></tr><tr><td>18</td><td>NoneBecauseEyesClosed</td><td>The liveness check could not be evaluated because the person's eyes are closed.</td></tr></tbody></table>

</details>

#### Facial Authentication Service Result

The  `serviceFacialAuthenticationResult` indicates the result of facial matching operations:

<details>

<summary>Facial Authentication Service Result</summary>

| Code | Result                           | Description                                                                                                                                                                                  |
| ---- | -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 0    | NONE                             | Facial verification could not be performed.                                                                                                                                                  |
| 1    | NEGATIVE                         | The process completed successfully. The comparison of the facial patterns does not match.                                                                                                    |
| 3    | POSITIVE                         | The process completed successfully. The comparison of the facial patterns is positive. The value of  `serviceFacialSimilarityResult` indicates the % similarity between the compared images. |
| 4    | NONE BECAUSE POSE EXCEED         | Facial verification could not be performed due to the face pose.                                                                                                                             |
| 5    | NONE BECAUSE INVALID EXTRACTIONS | Facial verification could not be performed due to problems extracting the facial pattern.                                                                                                    |

</details>

#### Example response: Successful enrollment

```json
{
    "serviceResultCode": 0,
    "serviceResultLog": "",
    "serviceFacialSimilarityResult": 0.9812,
    "serviceFacialAuthenticationLog": "Positive",
    "serviceFacialAuthenticationResult": 3,
    "serviceLivenessLog": "Live",
    "serviceLivenessResult": 3,
    "timestamp": "2026-04-20T15:12:07Z",
    "transactionId": "cd13a168-6eb0-4afd-bc88-408ca6a73437"
}
```

#### Response example: Successful authentication (positive match)

```json
{
    "serviceResultCode": 0,
    "serviceResultLog": "",
    "serviceFacialSimilarityResult": 0.9812,
    "serviceFacialAuthenticationLog": "Positive",
    "serviceFacialAuthenticationResult": 3,
    "serviceLivenessLog": "Live",
    "serviceLivenessResult": 3,
    "timestamp": "2026-04-20T15:12:28Z",
    "transactionId": "1ada7f96-44f2-48f1-87a5-0359621ae7a1"
}
```

#### Response example: Negative match

```json
{
    "serviceResultCode": -102,
    "serviceResultLog": "User authentication failed",
    "serviceFacialSimilarityResult": 0.0192,
    "serviceFacialAuthenticationLog": "Negative",
    "serviceFacialAuthenticationResult": 1,
    "serviceLivenessLog": "Live",
    "serviceLivenessResult": 3,
    "timestamp": "2026-04-20T15:34:47Z",
    "transactionId": "d6e29c6c-0da2-4620-9ca7-f483c6950d72"
}
```

#### Response example: User not found

```json
{
    "serviceResultCode": -103,
    "serviceResultLog": "User not found",
    "timestamp": "2026-04-20T15:12:29Z",
    "transactionId": "ca61856d-0eb8-49ca-8178-66346e0c75ab"
}
```

#### 400 Bad Request

```json
{
    "status": 400,
    "title": "Bad Request",
    "detail": "Invalid request.",
    "type": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400",
    "errors": [
        "userId is required"
    ]
}
```

#### 401 Unauthorized

```json
{
    "message": "Unauthorized"
}
```

#### 403 Forbidden

```json
{
    "Message": "User is not authorized to access this resource with an explicit deny"
}
```

#### 404 Not Found

```json
{
    "serviceResultCode": -103,
    "serviceResultLog": "User not found",
    "timestamp": "2026-04-20T15:12:29Z",
    "transactionId": "ca61856d-0eb8-49ca-8178-66346e0c75ab"
}
```

#### 413 Payload Too Large

The request exceeds the maximum allowed size. The gateway rejects it **without processing it**: the response does not include `serviceResultCode` nor `serviceTransactionId`. See [Request size limit](https://docs.facephi.com/pages/bc7bee9358079d52bafa44ad281828eb424e96fe#l%C3%ADmite-de-tama%C3%B1o-de-la-solicitud).

Request over 6 MB and up to 10 MB (`Content-Type: application/json`):

```json
{
    "message": "Request Too Long"
}
```

Request over 10 MB (10,485,760 bytes) (`Content-Type: text; charset=utf-8`, plain text, not JSON):

```
HTTP content length exceeded 10485760 bytes.
```

#### 502 Bad Gateway

```json
{
    "status": 502,
    "title": "Bad Gateway",
    "detail": "Server got an invalid response.",
    "type": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502"
}
```

#### 504 Gateway Timeout

```json
{
    "message": "Endpoint request timed out"
}
```

***

### Differences from v1/v2

| Aspect                                   | v1/v2                                                                                                                   | v3                                                                              |
| ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| Template field in request                | `registeredTemplateRaw`                                                                                                 | `templateRaw`                                                                   |
| `merchantReferenceId`                    | Required                                                                                                                | Not used                                                                        |
| `image` / `template` as input            | Supported                                                                                                               | Not supported, only `templateRaw` + `bestImageToken`                            |
| Auto-enrollment on first authentication  | Yes                                                                                                                     | No, explicit enrollment required                                                |
| Template in response                     | Yes (`registeredTemplateRaw`)                                                                                           | No (not returned for security reasons; avoids unnecessary transfer of PII)      |
| Liveness check + match during enrollment | N/A                                                                                                                     | Required before persistence                                                     |
| Template age at registration             | Only when registering a new user, if the client configuration sets a maximum age for the `registeredTemplateRaw` (`-2`) | Not supported                                                                   |
| Expiration of stored template            | Not supported                                                                                                           | From enrollment, if the client configuration sets `templateTTLSeconds` (`-105`) |
| New error codes                          | N/A                                                                                                                     | `-104` (Template not found), `-105` (Template expired)                          |

***
