# Implementation Guide

### Authentication

A unique access token should be created upon each SDK entry. In order to generate an access token, please refer to Valify's [Authentication](https://valify.gitbook.io/documentation/apis/oauth-token) Documentation.

{% hint style="warning" %}
**Security Warning:** For improved security, consider implementing the access token fetching logic outside the Activity. This helps keep sensitive credentials secure and reduces potential exposure within the Activity/Fragment code.
{% endhint %}

### Importing

Import the module’s function in your file using the following line

```dart
import 'package:vidvliveness_flutter_plugin/vidvliveness_flutter_plugin.dart';

```

### Configurations

The plugin builder is separated into two components.

#### Required Configurations

Initialize the required parameters as follows while adding the required configurations

```dart
  final String baseURL = ' '; //put your acctual base url here
  final String bundleKey = ' '; //put your actual bundle key here
  final String accessToken = ' '; //put your actual access token here


```

#### Optional Configurations

Initialize the required parameters as follows while adding the desired configurations

<pre class="language-dart"><code class="lang-dart">final String language = "&#x3C;insert_language>"; // "en" is set as default
final bool enableSmile = &#x3C;boolean>; // true is set as default
final bool enableLookLeft = &#x3C;boolean>; // true is set as default
final bool enableLookRight = &#x3C;boolean>; // true is set as default
final bool enableCloseEyes = &#x3C;boolean>;// true is set as default
<strong>final String trials = "&#x3C;string>"; // default is "3"
</strong>final String instructions = "&#x3C;string>"; // default is "4"
final String timer = "&#x3C;string>"; // default is "10"
final String primaryColor = ”&#x3C;hex_color_code>”; //
final bool enableVoiceOver= &#x3C;boolean>; // true is set as default

//one of these lines is required to enable face match 
final String ocrTransactionID = "&#x3C;ocr_transaction_id>";//string
final String facematchImage = "&#x3C;base_64_image>";//string

final bool showErrorMessage= &#x3C;boolean>; // true is set as default
final HashMap&#x3C;String, String> headers = HashMap();//default empty

</code></pre>

### Configurations Breakdown

This section shows the breakdown of all optional builder configurations.&#x20;

1. The following line is where the user interface language is set.&#x20;

```dart
final String language = "<insert_language>"; // ["ar" or "en"] 
```

{% hint style="info" %}
The currently supported languages are Arabic and English
{% endhint %}

2. If the following line is set to true, the SDK requires the user to smile during the experience

```dart
final bool enableSmile= <boolean>; // true is set as default
```

3. If the following line is set to true, the SDK requires the user to look to the left during the experience

```dart
final bool enableLookLeft= <boolean>; // true is set as default
```

4. If the following line is set to true, the SDK requires the user to look to the right during the experience

```dart
final bool enableLookRight= <boolean>; // true is set as default
```

5. If the following line is set to true, the SDK requires the user to close their eyes during the experience

```dart
final bool enableCloseEyes= <boolean>; // true is set as default
```

6. The integer set in the following line determines how many failed attempts the user has during a single SDK experience.

```dart
final String trials= <string>;
```

7. The integer set in the following line determines how many instructions the user will need to follow to successfully complete a single SDK experience.

```dart
final String instructions= <string>;
```

8. The integer set in the following line determines how much time (in seconds) the user will be given to complete each task.

```dart
final String timer= <string>;
```

9. The following line is optional and can be used to set your company's branding color to the SDK's user interface.

```dart
final String primaryColor = ”<hex_color_code>”;
```

10. If the following line is set to false, voice-over will be added to the SDK experience dictating the actions expected from the user.

```dart
final bool enableVoiceover= <boolean>; // true is set as default
```

11. If this field has the OCR transaction ID filled, then the face match service is enabled and the referenced transaction ID will be compared with an image captured of the user's face during the SDK experience.

```dart
final String facematch_ocr_transactionId =”<facematch_ocr_transactionId >”;//string
```

12. If the following line is set to true, then an error message will appear in the user interface in the case that the user did not pass the face match or the liveness service.

```dart
final bool showErrorMessage= <boolean>;
```

13. If this field has an base64-encoded image filled, then the face match service is enabled and the image will be compared with an image captured of the user's face during the SDK experience.

```dart
final String facematchImage = "<base_64_image>";//string
```

14. The following line is optional and can be used to set any headers that may be required for purposes specific to your application. Any headers set will be sent along with each API call made by the SDK.&#x20;

```dart
final HashMap<String, String> headers = HashMap();
```

### Parameter Declaration

Declare the SDK parameters with the configuration variables previously created

```dart
    Map<String, dynamic> params = {
      'base_url': baseURL,
      'access_token': accessToken,
      'bundle_key': bundleKey,
      'language': language,
      'liveness_time_per_action': timer,
      'liveness_number_of_instructions': instructions,
      'enable_smile': enableSmile,
      'enable_look_left': enableLookLeft,
      'enable_look_right': enableLookRight,
      'enable_close_eyes': enableCloseEyes,
      'enable_voiceover': enableVoiceover,
      'primary_color': primaryColor,
      'show_error_message': show_error_message,
      
      //in case of face match
      'facematch_ocr_transactionId':facematch_ocr_transactionId ,
      //or
      'facematch_image':facematchImage,
      'headers': headers
    };
```

### Start the SDK

Use the following code snippet to run the plugin

```dart
    try {
      final result = await VidvlivenessFlutterPlugin.startLiveness(params);
        //handle logic to use the liveness response depending on the state
    } catch (e) {
        //catch errors
    }
```

### Sample Integration Example

Check out our [GitHub repository](https://github.com/Valify-Solutions/Flutter_VIDOCR_LIVENESS_Simple_Integration_App) for a simple integration app demonstrating how to use our SDK. The repository includes step-by-step instructions and sample code to help you get started quickly.
