This page demonstrates how to integrate the VouchID Widget SDK into your application. Follow the steps below to get started and see a live demo.
Initializing VouchID Widget...
Add the script to your HTML. The SDK will be available as `window.VouchIDWidget`.
<script src="https://your-cdn-url.com/vouchid-widget-sdk/latest/index.js"></script>
Install the package using NPM or Yarn.
npm install @vouchid/widget-sdk
Add a `div` to your HTML where the widget will be mounted.
<div id="vouchid-widget-container"></div>
Create a new instance of `VouchIDWidget` and mount it.
// Import if using NPM
// import VouchIDWidget from '@vouchid/widget-sdk';
const vouchIdWidget = new VouchIDWidget({
elementId: 'vouchid-widget-container',
platformKey: 'YOUR_PUBLIC_PLATFORM_KEY',
// IMPORTANT: This is NOT a redirect URI.
// The user is NEVER sent to this address.
// The SDK uses the ORIGIN of this URI (e.g., 'https://your-app.com')
// to securely send the final token to your page via window.postMessage.
// The path (e.g., /vouchid/callback) is ignored.
redirectUri: 'https://your-app.com',
onSuccess: (data) => {
console.log('VouchID Success!', data);
// data -> { platformSessionToken: "a-long-secret-string" }
// This platformSessionToken is ready to be used by your backend.
// Send this to your backend to establish a user session or get more info.
},
onFailure: (error) => {
console.error('VouchID Failed:', error);
// error -> { code: "ERROR_CODE", message: "Error message." }
},
onClose: () => {
console.log('Widget was closed by the user.');
}
});
vouchIdWidget.mount();
The `platformSessionToken` received in the `onSuccess` callback is the **VouchID platform-specific session token**. It's a ready-to-use Bearer token for your backend to make authenticated calls to VouchID APIs. It is NOT an OAuth authorization code that requires a separate token exchange step.
This example page demonstrates calling a local API route (`/api/platform-actions/get-user-info`) which then securely calls the VouchID backend to retrieve user information using this token.