# Face Authentication

To perform a face authentication it is required to have already an "Identification" and its verification ID. The process consist in a liveness check of the user and a final check to verify the match with the identification.

## Implementation

* Create a `FaceAuthenticationParams` object with authentication information and the verification id you want to verify
* Start the verification with `FaceAuthenticationActivity.startForResult`
* Handle result in `onActivityResult` method

## Example to Start a Face Authentication

Please update the below code with your Client ID and Client Secret from your [Customer Dashboard](https://customer-dashboard.app.authenteq.com/sign-in).&#x20;

{% hint style="warning" %}
We suggest to use the token authentication in production environment.
{% endhint %}

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

```java
void faceAuthentication(String verificationId) {
    FaceAuthenticationParams faceAuthenticationParams = new FaceAuthenticationParamsWithClientSecret(
        "< client id >",
        "< client secret >",
        verificationId
        R.style.AuthenteqThemeBase // optional
    );
    FaceAuthenticationActivity.startForResult(
        activity, 
        MY_REQUEST_FACEAUTH_CODE,
        faceAuthenticationParams
    );
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    if (requestCode == MY_REQUEST_FACEAUTH_CODE) {
        if (resultCode == RESULT_OK) {
            String code = FaceAuthenticationActivity.getResult(data);
            // Check face authentication result with the CODE provided
        } else {
            Throwable throwable = FaceAuthenticationActivity.getError(data);
            // Handle error
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
fun faceAuthentication(verificationId: String) {
        val faceAuthenticationParams = FaceAuthenticationParamsWithClientSecret(
                "< client id >",
                "< client secret >",
                verificationId
        )
        FaceAuthenticationActivity.startForResult(
                this,
                MY_REQUEST_FACEAUTH_CODE,
                faceAuthenticationParams
        )
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if (requestCode == MY_REQUEST_FACEAUTH_CODE) {
            if (resultCode == Activity.RESULT_OK) {
                FaceAuthenticationActivity.getResult(data)?.let { code ->
                    // Check face authentication result with the CODE provided
                }
            } else {
                FaceAuthenticationActivity.getError(data)?.let { error ->
                    // Handle error
                }
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data)
        }
}
```

{% endtab %}
{% endtabs %}

Authentication Token can be obtained with face authentication [API](/mo/authentication-token.md#obtain-a-mobile-sdk-temporary-authentication-token-for-face-authentication) and then specified with the `FaceAuthenticationParams` as the following code:

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

```java
void faceAuthentication(String verificationId) {
    FaceAuthenticationParams faceAuthenticationParams = new FaceAuthenticationParamsWithToken(
        "< client id >",
        "< token >",
        verificationId
        R.style.AuthenteqThemeBase // optional
    );
    FaceAuthenticationActivity.startForResult(
        activity, 
        MY_REQUEST_FACEAUTH_CODE,
        faceAuthenticationParams
    );
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
fun faceAuthentication(verificationId: String) {
        val faceAuthenticationParams = FaceAuthenticationParamsWithToken(
                "< client id >",
                "< token >",
                verificationId
        )
        FaceAuthenticationActivity.startForResult(
                this,
                MY_REQUEST_FACEAUTH_CODE,
                faceAuthenticationParams
        )
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Authentication token can only be used for a single operation. Always generate a new token before start a new face authentication.
{% endhint %}

### Get Face Authentication Result

With the code obtained from `FaceAuthenticationActivity.getResult` it is possible to get the face authentication result using the following API:

## Obtain the result of a face authentication

<mark style="color:blue;">`GET`</mark> `https://api.app.authenteq.com/mobile-sdk/face-authentication-result`

This endpoint is authorized with Basic Authorization. You should use your `Client ID` and `Client Secret` from the Customer Dashboard as the credentials.

#### Query Parameters

| Name                                   | Type   | Description                                                    |
| -------------------------------------- | ------ | -------------------------------------------------------------- |
| code<mark style="color:red;">\*</mark> | string | The code provided at the conclusion of SDK face authentication |

#### Headers

| Name                                            | Type   | Description                                                                                         |
| ----------------------------------------------- | ------ | --------------------------------------------------------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Your client credentials combined with a colon separator, base64-encoded and prefixed with "Basic ". |

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

```
{
  "accessToken": "81e4cbce-cdad-11eb-8fc3-784f4385af2b"
}
```

{% endtab %}

{% tab title="401  Full authentication is required to perform document recognition." %}

```
{
  "errorCode": "API_KEYS_MISSING",
  "errorMessage": "No API Keys in the Authorization header"
```

{% endtab %}

{% tab title="403 The authenticated customer is disabled and cannot get a token." %}

```
{
  "errorCode": "ACCOUNT_DEACTIVATED",
  "errorMessage": "Account deactivated. Please contact your Authenteq Sales Representative in order to keep using this service"
}huiHjio
```

{% endtab %}
{% endtabs %}

When successful the response will contain a single boolean property named `success`:

```json
{
    "success": true
}
```


---

# 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://docs.authenteq.com/mo/android/face-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.
