Skip to main content
Version: v2

Quick start

This guide shows you how to run a verification in your web app with our default screens.

The SDK doesn't create transactions. Your backend creates the transaction with the Agent API, and passes the sdkConfiguration from the response to your web app. Your web app passes it to the SDK, which runs the verification from there.

Prerequisites​

  • A workflow and its ID.
  • API credentials (client_id and client_secret) for the Agent API.
  • A backend endpoint that creates a transaction and returns its sdkConfiguration. See Create the transaction on your backend.
  • A web app served over HTTPS, or from localhost during development. Browsers allow camera access only on secure pages.

Installation​

Install using your preferred package manager:

npm install @microblink/platform-sdk

The SDK has no required peer dependencies. You only need react (version 18 or later) if you use the React entry point, and vite (version 5 or later) if you use the Vite plugin.

Create the transaction on your backend​

When the user starts a verification, your backend:

  1. Makes sure that the user is authenticated.
  2. Collects the user's consent, if you haven't already.
  3. Calls POST /api/v2/transaction on the Agent API, with the workflow ID, "platform": "Browser", and the consent.
  4. Returns the sdkConfiguration from the response to your web app.

Your API credentials never leave your backend. Pass sdkConfiguration to the SDK as it is; don't parse or modify it.

For an example backend, see No proxy in the migration guide.

Run a verification​

In both examples below, /start-verification is your own backend endpoint from the previous section.

Vanilla JavaScript​

createPlatformSdk takes the sdkConfiguration as sessionToken, and renders our screens into target. If you don't set target, the SDK renders in a full-screen overlay.

import { createPlatformSdk } from '@microblink/platform-sdk';

const response = await fetch('/start-verification', { method: 'POST' });
const { sdkConfiguration } = await response.json();

const sdk = createPlatformSdk({
sessionToken: sdkConfiguration,
target: document.getElementById('verification'),
});

sdk.onTransactionEnd((result) => {
// "Accept", "Reject", or "Review"
console.log(result.transactionId, result.verificationStatus);
});

sdk.onAbort((info) => {
console.log('User left the verification on step', info.step);
});

Give the target element a defined height.

React​

In React, the usePlatformSdk hook owns the session, and the PlatformFlowUI component renders our screens. The hook reads its configuration only once, when the component mounts, so render the component after you have the session token:

import { useEffect } from 'react';
import { usePlatformSdk, PlatformFlowUI } from '@microblink/platform-sdk/react';

// sessionToken is the sdkConfiguration your backend returned.
function Verification({ sessionToken }) {
const sdk = usePlatformSdk({ sessionToken });

useEffect(() => {
if (sdk.currentStep === 'END' && sdk.state.verificationStatus) {
console.log(sdk.state.transactionId, sdk.state.verificationStatus);
}
}, [sdk.currentStep, sdk.state.verificationStatus]);

if (sdk.unmounted) {
return <p>Done</p>;
}

return <PlatformFlowUI config={sdk} />;
}

sdk.unmounted becomes true when the SDK removes its screens, for example after the user closes the result screen or leaves the verification.

Serve the camera resources​

The document scanning, card scanning, and face capture steps load WebAssembly (WASM) and worker files at runtime. Copy them into your public directory as part of your build, with the platform-web-sdk copy-resources command that comes with the SDK:

package.json
{
"scripts": {
"prebuild": "platform-web-sdk copy-resources public"
}
}

By default, the SDK loads the files from a resources/ folder next to the current page. To copy only the files your workflows need, to use the Vite plugin, or to serve the files from a CDN, see Hosting resources.

Next steps​