Installation
- npm
- Yarn
- CDN (jsDelivr)
- CDN (UNPKG)
Integration steps
1
Generate a session ID and a session token on your backend
The SDK doesn’t generate session tokens itself. Your backend calls the Youverify API with your secret API key and passes both values to the page. See Generate the session ID and session token.
2
Import and initialize the SDK
options, see Options.3
Start the liveness check
start() override the tasks you set during initialization.Generate the session ID and session token
Both calls must come from your backend. Use the base URL for the environment you are testing against.Session ID
POST /v2/api/identity/sdk/session/generate
Headers
Request body
Response
sessionId to the SDK constructor.
Session token
POST /v2/api/identity/sdk/liveness/token
Headers
Request body
Response
authToken to the SDK constructor as sessionToken. The deviceCorrelationId should be a unique identifier for the user’s device or session. It helps track and prevent abuse.
Full example
Preloading
The SDK downloads its face detection model, several MB, before the liveness check can begin. The download doesn’t depend on the session, so start it early, before you generate thesessionId and sessionToken.
- It’s safe to call more than once. Later calls, including the one the constructor makes, reuse the download already in progress.
- If you don’t call it, the download starts when the SDK is constructed.
preload()keeps the detector in memory, so it only carries over to the liveness check if the page isn’t reloaded in between. That’s the case in single-page apps that navigate with their router.
Single-page apps
Callpreload() in your app’s entry module.
Multi-page sites
If users reach the liveness check through full page loads, the preloaded detector is discarded on every navigation. Callprefetch() on the pages before the liveness check instead.
- It’s safe to call on every page. Files already requested aren’t added again.
- It relies on the browser’s HTTP cache. It has no effect if caching is disabled, for example in a webview configured with
LOAD_NO_CACHE. <link rel="prefetch">is supported in Chromium-based browsers and Firefox, but not in Safari, whereprefetch()does nothing.
Options
string
required
ID generated by your backend using your API key. The SDK validates it before initialization and attaches it to submissions.
string
required
Token generated by your backend for liveness verification.
string
Your Youverify public merchant key.
boolean
default:"true"
Whether the session runs in sandbox or live mode. Set to
false for production.string
default:"modal"
How the UI is displayed. One of
modal or page.string
Optional entity identifier to include when the liveness result is submitted.
boolean
default:"false"
Whether to narrate information to the user during tasks.
object
Details of the user being checked.
object
Customizes the UI to fit your brand.
function
Called when the modal is closed.
function
Called when all tasks have been completed and passed. Receives the callback data.
function
Called when at least one task fails. Receives the callback data.
Tasks
A task is a series of instructions the user follows to confirm liveness. Pass tasks in thetasks option or to start(). Every task takes these options:
Complete the Circle
The user completes an imaginary circle with head movement. Useid: "complete-the-circle".
Yes or No
The user answers questions you set by tilting their head: right for yes, left for no. Useid: "yes-or-no".
Motions
The user performs random motions in random sequences: nodding, blinking and opening the mouth. Useid: "motions".
Blink
The user blinks a set number of times. Useid: "blink".
Callback data
onSuccess and onFailure receive an object with these properties.
boolean
Whether the liveness check passed.
string
Face image of the user performing the check.
string
Video of the user performing the check.
any
Metadata passed in during initialization.
object
Present only on failure. Contains
key (eyes_closed, image_capture_failed or API_ERROR) and message.sdkVersion (the SDK package version, 1.2.3) and, if you passed it during initialization, entityId.
Errors and retries
- If session validation fails, generate a new
sessionIdand retry. - If liveness fails, the user can retry while the current
sessionIdremains valid. - If the
sessionIdexpires, create a new session and restart the process.
Use
sandboxEnvironment: true for testing and sandboxEnvironment: false for production.