This is a quick implementation guide for the CafFaces2dSdk.
Create a demo environment for the CafFaces2dSdk by cloning this repository.
To obtain a token, follow the instructions here: https://docs.caf.io/caf-sdk/sdk_integration_documentation
β οΈ Important: To useCafFaces2dSdk, a prior configuration is required by the CAF team. Please contact support to ensure the token is properly configured and enabled for use with this SDK.
<script src="./caf-faces2d-sdk.js"></script>Creates an instance of the 2D liveness SDK.
| Name | Type | Required | Description |
|---|---|---|---|
options |
CameraSdkOptions |
β | Configuration object for the SDK instance |
const { CafFaces2dSdk } = window['@caf/web-sdk-liveness-2d'];
const sdk = new CafFaces2dSdk({
token: "my-token",
personId: "my-person-id",
environment: "prod",
useFaceAuthenticator: true,
language: "en_US",
disableDesktopExecution: false,
disableVisibilityChangeSecurity: true,
analytics: {
enabled: true,
trackingId: undefined,
trackingInfo: undefined,
enableDebugMode: true,
},
appearance: {
captureButtonIcon: "",
captureIconSize: "",
captureButtonColor: "",
fontFamily: "",
hideCameraSwitchButton: false,
},
textSettings: {
title: "",
messages: {
processMessage: "",
captureFailedMessage: "",
},
},
});SDK initialization parameters.
| Property | Type | Required | Description |
|---|---|---|---|
token |
string |
β | User authentication token |
personId |
string |
β | Person identifier |
useFaceAuthenticator |
boolean |
β | Enables facial authentication if true. (default: false) |
environment |
"dev" "beta" "prod" |
β | Execution environment. (default: "prod") |
language |
string |
β | Language code ("en_US", "pt_BR", "es_MX") |
disableDesktopExecution |
boolean |
β | Prevents execution on desktop devices (default: false) |
disableVisibilityChangeSecurity |
boolean |
β | Prevents the SDK from closing when switching browser tabs (default: false) |
disabledSecurityModule |
boolean |
β | Disables image injection protection (default: false) |
analytics |
AnalyticsOptions |
β | Tracking and debugging configuration |
appearance |
AppearanceOptions |
β | Visual customization of the SDK |
textSettings |
TextSettings |
β | Text and messages shown in the UI |
| Property | Type | Description |
|---|---|---|
captureButtonIcon |
string |
Capture button icon (URL or base64 SVG) |
captureIconSize |
string |
Icon size (e.g., "40px"). (default: "100%") |
captureButtonColor |
string |
Capture button color (default: "#39c560") |
fontFamily |
string |
Font applied to the entire UI |
hideCameraSwitchButton |
boolean |
Hides the camera switch button (default: false) |
| Property | Type | Description |
|---|---|---|
enabled |
boolean |
Enables/disables tracking (default: true) |
trackingId |
string |
Tracking ID used in the analytics system |
trackingInfo |
{ [key: string]: any } |
Extra data added to analytics events |
enableDebugMode |
boolean |
Enables detailed logs (default: false) |
| Property | Type | Description |
|---|---|---|
title |
string |
Title displayed in the UI |
messages |
Messages |
Messages shown during the capture flow |
Checks if the current browser supports the SDK.
if (sdk.isSupported()) {
// OK to proceed
}Requests the necessary permissions (such as camera access).
const granted = await sdk.initPermissions();
if (!granted) {
console.error("Permissions denied.");
}Initializes the SDK.
await sdk.initialize();Executes the face capture process.
| Name | Type | Description |
|---|---|---|
sdkDisplayer |
HTMLElement |
HTML element where the SDK will be rendered |
stages |
CaptureStage[] |
Capture stages with duration and attempt configurations |
params? |
CaptureOptions |
Additional capture configurations |
const container = document.getElementById("sdk-container");
const result = await sdk.capture(container, [
{ mode: "automatic", attempts: 3, duration: 20 },
{ mode: "manual", attempts: 0, duration: 0 },
]);| Property | Type | Description |
|---|---|---|
mode |
CaptureMode |
Capture mode ("automatic" or "manual") |
duration |
number |
Duration of the stage in seconds. 0 means unlimited duration |
attempts |
number |
Number of allowed attempts. 0 means unlimited attempts |
The capture method returns a signed JWT (signedResponse) that contains the following decoded data:
(Note: the return is a string; you must decode the JWT manually)
{
"sessionId": "string",
"personId": "string",
"isAlive": boolean,
"imageUrl": "string",
"createdAt": "ISO8601 string",
"iat": number
}| Field | Type | Description |
|---|---|---|
sessionId |
string |
Session identifier |
personId |
string |
Unique identifier of the person |
isAlive |
boolean |
Indicates if the person was detected as alive |
imageUrl |
string |
Captured image URL |
createdAt |
string |
Creation timestamp (ISO8601 format) |
iat |
number |
UNIX timestamp of token issuance |
Closes the SDK and hides the UI.
await sdk.close();Releases resources used by the SDK.
await sdk.dispose();-
Initialize SDK:
sdk.initPermissions()βsdk.initialize() -
Run Capture:
sdk.capture(container, stages) -
Close SDK:
sdk.close()βsdk.dispose()
This project is a reference integration of Caf's proprietary SDK for Liveness. All rights to the SDKs belong to Caf.