Onfido Smart Capture Web SDK

repository·master·Indexed 41 days ago

https://github.com/onfido/onfido-sdk-ui

A Web SDK providing pre-built UI components and logic for identity verification flows, including document capture and video selfies. It features image quality detection, fraud detection signals, and orchestration via Onfido Studio workflows. Supports integration via CDN, NPM, or Yarn, with official TypeScript support since version 6.5.0.

Tokens
10.1K
Snippets
32
Records
45
Agent score
51%

What's inside Onfido

  1. Overview of Onfido Smart Capture Web SDK

    master

    The Onfido Smart Capture Web SDK provides a set of UI screens and functionality to implement user identity verification flows. It is designed to guide users through photo or video capture processes with built-in image quality detection and direct upload to Onfido services.

    Key features include:

    • Modular design for seamless integration into existing application flows.
    • Advanced image quality detection to ensure high success rates.
    • Fraud detection signals to protect against malicious users.
    • Orchestration via Onfido Studio workflows.
    • Cross-device experience management specifically for web applications.
  2. Supported environments and accessibility

    master

    Supported Browsers

    • Chrome (Latest)
    • Firefox (Latest)
    • Edge (Latest)
    • Safari (Latest)

    Node.js Support

    • Compatible with all supported Node.js versions (currently starting with Node.js 16).

    Accessibility

    The SDK provides default support for:

    • Screen reader support (accessible labels and dynamic alerts).
    • Keyboard navigation.
    • Sufficient color contrast.
    • Sufficient touch target size.

    Warning: If you implement custom UI, you are responsible for maintaining these accessibility standards (e.g., color contrast and font legibility).

  3. Advanced flow customization via manual steps

    master

    You can initialize the Onfido Web SDK without Onfido Studio by manually defining the verification steps in the steps parameter. This allows for granular control over the user journey.

    Warning: This method is not recommended for most users as new features are primarily released for Studio workflows.

    When using this method, the steps parameter is mutually exclusive with workflowRunId.

    Onfido.init({
      token: "<YOUR_SDK_TOKEN>",
      // ... other params
      steps: [
        { type: "welcome", options: { title: "Custom Title" } },
        "document",
        "face",
        "complete"
      ]
    });
  4. Manage SDK analytics cookies

    master

    The Web SDK creates a single cookie named onfido-web-sdk-analytics containing a randomly generated UUID. This is used for internal analytics to link verification sessions for the same end user.

    • Persistence: The cookie persists for 30 days.
    • Disabling: You can disable this cookie using the disableAnalyticsCookies option in the SDK configuration. Setting this will also remove the cookie if it already exists.
  5. Understand the relationship between the SDK and verification reports

    master

    The Onfido Web SDK is responsible for capturing and uploading user media and data. It does not generate the identity verification reports itself.

    Verification reports are generated by Onfido Studio based on workflows. To manage the results of a verification:

    1. Automated Workflows: Use Onfido Studio to create workflows.
    2. Manual Management: If using advanced customization, you can manually create checks and retrieve report results via the Onfido API.
    3. Asynchronous Notifications: Configure webhooks to be notified when report results are ready.
  6. Manage Onfido SDK environments and testing

    master

    The SDK operates in two distinct environments. The environment is automatically determined by the API token used to generate the SDK token during authentication:

    • sandbox: Use this for testing with sample documents.
    • live: Use this only for real documents in production applications.

    Going Live: To transition to production, replace your sandbox token with a live API token obtained from Onfido Customer Support. Ensure your billing details are correctly configured in the Onfido Dashboard before going live.

  7. Import the SDK using JavaScript modules

    master

    You can import the SDK directly into your components or objects using ES6 or CommonJS syntax. When using this method, the CSS is included inline with the JavaScript code.

    Warning: The library is for Browser use only and does not support the Node context.

    // ES6 module import
    import { Onfido } from 'onfido-sdk-ui'
    
    // commonjs style require
    var Onfido = require('onfido-sdk-ui').Onfido
  8. Migrate to Onfido Web SDK v14.0.0

    master

    Version 14.0.0 introduced several breaking changes regarding package installation, imports, and visual behavior.

    Package and Import Changes

    • NPM Package: The "split bundle" library is no longer available on npm. Use the default onfido-sdk-ui package.
    • Styles: You no longer need to import style.css separately; it is included in the main library.
    • Import Syntax: The import method changed from a named init function to the Onfido object.
    // Old way
    import { init } from 'onfido-sdk-ui';
    
    // New way
    import { Onfido } from 'onfido-sdk-ui';

    Visual and Flow Changes

    • Default Screen Size: On desktop, the default size changed from 510px x 598px to 600px x 800px (using width: 100%, height: 100%, max-width: 600px, max-height: 800px, and min-height: 600px).
    • Capture Flow: The "Capture Guide" screen now appears earlier in the document capture flow.
    • Cross-Device Flow: Users are now prevented from switching to a cross-device flow once the first side (front) of a document has been captured. The entire flow must be completed on a single device.
    • Cross-Device Link Configuration: The options _crossDeviceLinkMethods and _initialCrossDeviceLinkView have been merged into a single option _initialCrossDeviceLinkView. Note that the separator changed from | to ,.
    // Old way
    _crossDeviceLinkMethods: ['qr_code' | 'copy_link' | 'sms'],
    _initialCrossDeviceLinkView: 'qr_code'
    
    // New way
    _initialCrossDeviceLinkView: ['qr_code', 'copy_link', 'sms']
    import { Onfido } from 'onfido-sdk-ui';
  9. Implement Custom Media Callbacks via `enterpriseFeatures`

    master

    Custom media callbacks allow you to intercept and control the data collected by the SDK before it is sent to Onfido. This feature must be enabled by your Onfido Solution Engineer or Customer Success Manager.

    To use them, add the enterpriseFeatures object to Onfido.init() and set useCustomizedApiRequests: true. You can then define onSubmitDocument, onSubmitSelfie, and onSubmitVideo.

    Data Formats:

    • By default, callbacks return a FormData object.
    • To receive data in json format, add formatter: 'raw' inside the enterpriseFeatures object.

    Controlling the Upload Flow:

    • Manual Upload: By default, these callbacks prevent the SDK from sending requests to Onfido, requiring you to upload the media from your backend. You should include all provided data in your request to the /documents or /live_photos endpoints and use the applicant's SDK token in the Authorization: Bearer <SDK token> header.
    • Automatic Upload: To let the SDK proceed with the upload after your callback executes, resolve the promise with { continueWithOnfidoSubmission: true }.
    • Managing Responses: After your backend processes the upload, resolve the promise with { onfidoSuccessResponse: <onfidoResponse> } on success, or reject it with the Onfido error response on failure.
    Onfido.init({
      ...
      enterpriseFeatures: {
        useCustomizedApiRequests: true,
        onSubmitDocument: (documentData) => {
          // Your callback code here
          // ...
          // To allow SDK to continue: 
          // return Promise.resolve({ continueWithOnfidoSubmission: true })
        },
        onSubmitSelfie: (selfieData) => {
          // Your callback code here
        },
        onSubmitVideo: (videoData) => {
          // Your callback code here
        },
      },
    })
  10. Integrate the SDK via Direct CDN

    master

    The quickest way to integrate the SDK is via the Onfido-hosted CDN. You can control the update frequency by how you specify the version in the URL:

    • Major release (e.g., v14): Receives the latest minor and patch updates.
    • Minor release (e.g., v14.11): Receives the latest patch updates.
    • Specific patch (e.g., v14.11.0): Pins the library to that exact version.

    Note: From version 14 onwards, a separate stylesheet is no longer required as it is included in the default library.

    <!-- Replace "<version>" with the actual SDK version you want to use, example: v14.11.0 -->
    <script src="https://sdk.onfido.com/<version>" charset="utf-8"></script>
  11. Track user progress with `userAnalytics` events

    master

    You can track the user's journey through the verification process by adding an EventListener to the window that listens for userAnalytics events.

    Each event contains:

    • eventName {String}: The name of the triggered event.
    • properties {Object}: Event-specific metadata.
    • isCrossDevice {Boolean}: true if the event originates from a mobile session.

    To access the SDK version within an event listener, use the handle returned by Onfido.init().

    addEventListener('userAnalytics', (event) => /*Your code here*/);
    
    // Accessing version
    const onfidoOut = Onfido.init({...})
    onfidoOut.addEventListener('userAnalyticsEvent', (event) => {
      console.log('Version', onfidoOut.version)
    });
  12. Initialize the Onfido Web SDK

    master

    To load the Onfido flow, you must provide an empty HTML element to serve as the mount point. Starting from version 14.0.0, the SDK container automatically inherits 100% of the height and width of its parent wrapper (constrained to a max width of 600px and max height of 800px on desktop).

    Use Onfido.init() to start the session. You must provide a token (SDK token) and a workflowRunId. You can specify the mount point using either containerId (the ID of the element) or containerEl (the element itself). If containerEl is provided, containerId is ignored.

    <div id="onfido-mount"></div>
    Onfido.init({
      token: '<YOUR_SDK_TOKEN>',
      containerId: 'onfido-mount',
      //containerEl: document.getElementById('root'), // Alternative to containerId
      onComplete: function (data) {
        console.log('everything is complete')
      },
      workflowRunId: '<YOUR_WORKFLOW_RUN_ID>',
    })