Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@biopassid/face-sdk-react-native

Package Overview
Dependencies
Maintainers
5
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@biopassid/face-sdk-react-native

BioPass ID Face React Native module.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
490
increased by89.92%
Maintainers
5
Weekly downloads
 
Created
Source

BioPass ID

BioPass ID Face SDK React Native

React Native NPM Instagram BioPass ID Contact us

Key FeaturesCustomizationsQuick Start GuideFaceConfigFaceEventChangelogLicenseSupport

Key features

  • Face Detection
    • We ensure that there will be only one face in the capture.
  • Face Positioning
    • Ensure face position in your capture for better enroll and match.
  • Auto Capture
    • When a face is detected the capture will be performed in how many seconds you configure.
  • Resolution Control
    • Configure the image size thinking about the tradeoff between image quality and API's response time.
  • Aspect Ratio Control
  • Fully customizable interface

Customizations

Increase the security of your applications without harming your user experience.

All customization available:

  • Title Text
  • Help Text
  • Loading Text
  • Font Family
  • Face Frame
  • Overlay
  • Default Camera
  • Capture button

Enable or disable components:

  • Tittle text
  • Help Text
  • Capture button
  • Button icons
  • Flip Camera button
  • Flash button

Change all colors:

  • Overlay color and opacity
  • Capture button color
  • Capture button text color
  • Flip Camera color
  • Flash Button color
  • Text colors

Quick Start Guide

First, you will need a license key to use the SDK. To get your license key contact us through our website BioPass ID.

Check out our official documentation for more in depth information on BioPass ID.

1. Prerequisites:

AndroidiOS
SupportSDK 21+iOS 13+
- A device with a camera
- License key
- Internet connection is required to verify the license

2. Installation

npm install @biopassid/face-sdk-react-native

Android

Change the minimum Android sdk version to 21 (or higher) in your android/app/build.gradle file.

minSdkVersion 21

Change the compile Android sdk version to 31 (or higher) in your android/app/build.gradle file.

compileSdkVersion 31

iOS

Requires iOS 13.0 or higher.

Add two rows to the ios/Info.plist:

  • one with the key Privacy - Camera Usage Description and a usage description.
  • and one with the key Privacy - Photo Library Usage Description and a usage description.

If editing Info.plist as text, add:

<key>NSCameraUsageDescription</key>
<string>Your camera usage description</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Your library usage description</string>

Then go into your project's ios folder and run pod install.

# Go into ios folder
$ cd ios

# Install dependencies
$ pod install

3. How to use

Basic Example

To call Face Capture in your React Native project is as easy as follow:

import React from "react";
import { StyleSheet, View, Button } from "react-native";
import {
  FaceConfigPreset,
  FaceConfigType,
  FaceEvent,
  buildCameraView,
  FaceCameraLensDirection,
} from "@biopassid/face-sdk-react-native";

export function App() {
  const config = FaceConfigPreset.getConfig(
    FaceConfigType.FACE_CAPTURE
  )
    .setLicenseKey("your-license-key")
    .setDefaultCameraPosition(FaceCameraLensDirection.FRONT)
    .setShowFlipCameraButton(true)
    .setStringsScreenTitle("Capturando Face")
    .setStylesOverlayColor("#CC000000");

  function callback(event: FaceEvent) {
    // handle Face return
    console.log('Photo: ', event.photo.substring(0, 20));
  }

  function handleButton() {
    buildCameraView(config, callback);
  };

  return (
    <View style={styles.container}>
      <Button onPress={handleButton} title="Capture Face" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: "center",
    justifyContent: "center",
    backgroundColor: '#FFFFFF',
  },
});

Example using Fetch API to call the BioPass ID API

For this example we used the Enroll from the Multibiometrics plan.

Here, you will need an API key to be able to make requests to the BioPass ID API. To get your API key contact us through our website BioPass ID.

import React from 'react';
import {StyleSheet, View, Button} from 'react-native';
import {
  FaceConfigPreset,
  FaceConfigType,
  FaceEvent,
  buildCameraView,
} from '@biopassid/face-sdk-react-native';

export default function App() {
  // Instantiate Face config by passing your license key
  const config = FaceConfigPreset.getConfig(
    FaceConfigType.FACE_CAPTURE,
  ).setLicenseKey('your-license-key');

  // Handle Face callback
  async function callback(event: FaceEvent) {
    // Create headers passing your api key
    const headers = {
      'Content-Type': 'application/json',
      'Ocp-Apim-Subscription-Key': 'your-api-key',
    };

    // Create json body
    const body = JSON.stringify({
      Person: {
        CustomID: 'your-customID',
        Face: [{'Face-1': event.photo}],
      },
    });

    // Execute request to BioPass ID API
    const response = await fetch(
      'https://api.biopassid.com/multibiometrics/enroll',
      {
        method: 'POST',
        headers,
        body,
      },
    );
    const data = await response.json();

    // Handle API response
    console.log('Response status: ', response.status);
    console.log('Response body: ', data);
  }

  // Build Face camera view
  function handleButton() {
    buildCameraView(config, callback);
  }

  return (
    <View style={styles.container}>
      <Button onPress={handleButton} title="Capture Face" />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: '#FFFFFF',
  },
});

4. Callback

Setting the Callback

You can pass a function callback to receive the captured image. Images are returned in Base64 string format. You can write you own callback following this example:

function callback(event: FaceEvent) {
  console.log('Photo: ', event.photo.substring(0, 20));
  doSomething(event);
}

5. License

First, you will need a license key to use the SDK. To get your license key contact us through our website BioPass ID.

To use Face Capture you need a license key. To set the license key needed is simple as setting another attribute. Simply doing:

const config = FaceConfigPreset.getConfig(FaceConfigType.FACE_CAPTURE)
  .setLicenseKey('your-license-key');

6. AutoCapture

For automatic capture to work, the autoCapture needs to be enabled. By default, autoCapture is already enabled. If autoCapture is disabled, automatic capture will be disabled and the responsibility for capturing will be the user's responsibility through a button. For continuous capture, autoCapture will be ignored and automatic capture will always occur. To set the autoCapture is simple as setting another attribute. Simply doing:

const config = FaceConfigPreset.getConfig(FaceConfigType.FACE_CAPTURE)
  .setLicenseKey('your-license-key')
  .setAutoCapture(true);

7. AutoCaptureTimeout

To use the autoCaptureTimeout, the autoCapture needs to be on and a time in milliseconds needs to be passed to autoCaptureTimeout. By default, the autoCaptureTimeout value is 3000ms for single capture and 1000ms for continuous capture. If the autoCaptureTimeout is equal to zero, the capture will be instantaneous. To set the autoCaptureTimeout is simple as setting another attribute. Simply doing:

const config = FaceConfigPreset.getConfig(FaceConfigType.FACE_CAPTURE)
  .setLicenseKey('your-license-key')
  .setAutoCapture(true)
  .setAutoCaptureTimeout(3000);

8. MaxNumberFrames

You can use the maxNumberFrames to set a maximum number of frames to be captured during continuous capture. For the single capture, the maxNumberFrames will always be ignored. If the maxNumberFrames is less than one or null, the capture will continue until the user presses the back button. Setting maxNumberFrames is as simple as setting another attribute. Simply by doing:

const config = FaceConfigPreset.getConfig(FaceConfigType.CONTINUOUS_CAPTURE)
  .setLicenseKey('your-license-key')
  .setMaxNumberFrames(5);

FaceConfig

You can also use pre-build configurations on your application, so you can automatically start using multiples services and features that better suit your application. You can instantiate each one and use it's default properties, or if you prefer you can change every config available. Here are the types that are supported right now:

FaceCaptureConfig

Variable nameTypeDefault value
licenseKeystring""
cameraPresetFaceCameraPresetFaceCameraPreset.MEDIUM
defaultCameraPositionFaceCameraLensDirectionFaceCameraLensDirection.FRONT
outputFormatFaceOutputFormatFaceOutputFormat.JPEG
captureButtonTypeFaceCaptureButtonTypeFaceCaptureButtonType.DEFAULT
showFlashButtonbooleanfalse
showFlipCameraButtonbooleantrue
flashEnabledByDefaultbooleanfalse
showHelpTextbooleantrue
showScreenTitlebooleantrue
autoCapturebooleantrue
autoCaptureTimeoutnumber3000 // time in milliseconds
maxNumberFrames?numbernull
stringsFaceStrings
stylesFaceStyles

ContinuousCaptureConfig

Variable nameTypeDefault value
licenseKeystring""
cameraPresetFaceCameraPresetFaceCameraPreset.MEDIUM
defaultCameraPositionFaceCameraLensDirectionFaceCameraLensDirection.FRONT
outputFormatFaceOutputFormatFaceOutputFormat.JPEG
captureButtonTypeFaceCaptureButtonTypeFaceCaptureButtonType.DEFAULT
showFlashButtonbooleanfalse
showFlipCameraButtonbooleanfalse
flashEnabledByDefaultbooleanfalse
showHelpTextbooleantrue
showScreenTitlebooleantrue
autoCapturebooleantrue
autoCaptureTimeoutnumber1000 // time in milliseconds
maxNumberFrames?numbernull
stringsFaceStrings
stylesFaceStyles

FaceStrings

Variable nameTypeDefault value
screenTitlestring"Capturando Face"
helpTextstring"Encaixe seu rosto no formato acima e aguarde o sinal verde"
loadingstring"Processando..."
customCaptureButtonTextstring"Capture Face"
noFaceDetectedMessagestring"Nenhuma face detectada"
multipleFacesDetectedMessagestring"Múltiplas faces detectadas"
detectedFaceIsCenteredMessagestring"Mantenha o celular parado"
detectedFaceIsCloseMessagestring"Afaste o rosto da câmera"
detectedFaceIsDistantMessagestring"Aproxime o rosto da câmera"
detectedFaceIsOnTheLeftMessagestring"Mova o celular para a direita"
detectedFaceIsOnTheRightMessagestring"Mova o celular para a esquerda"
detectedFaceIsTooUpMessagestring"Mova o celular para baixo"
detectedFaceIsTooDownMessagestring"Mova o celular para cima"

FaceStyles

Variable nameTypeDefault value
faceShapeFaceScreenShapeFaceScreenShape.CUSTOM
faceColorstring"#FFFFFF"
faceEnabledColorstring"#16AC81"
faceDisabledColorstring"#E25353"
overlayColorstring"#CC000000"
backButtonIcon?stringnull
backButtonColorstring"#FFFFFF"
backButtonSizeFaceSizeFaceSize(24, 24)
flashButtonIcon?stringnull
flashButtonSizeFaceSizeFaceSize(24, 24)
flashButtonEnabledColorstring"#FFCC01"
flashButtonDisabledColorstring"#FFFFFF"
flipCameraButtonIcon?stringnull
flipCameraButtonColorstring"#FFFFFF"
flipCameraButtonSizeFaceSizeFaceSize(65, 43)
textColorstring"#FFFFFF"
textSizenumber20
customFont?stringnull
captureButtonIcon?stringnull
captureButtonColorstring"#D9D9D9"
captureButtonSizeFaceSizeFaceSize(76, 76)
customCaptureButtonBackgroundColorstring"#D6A262"
customCaptureButtonSizeFaceSizeFaceSize(300, 45)
customCaptureButtonTextColorstring"#FFFFFF"
customCaptureButtonTextSizenumber20

Changing Font Family

Android

You can use the default font family or set a font you prefer. To set a font, create a folder font under res directory in your android/app/src/main/res. Download the font which ever you want and paste it inside font folder. All font file names must be only: lowercase a-z, 0-9, or underscore. The structure should be some thing like below.

iOS

To add the font files to your Xcode project:

  1. In Xcode, select the Project navigator.
  2. Drag your fonts from a Finder window into your project. This copies the fonts to your project.
  3. Select the font or folder with the fonts, and verify that the files show their target membership checked for your app’s targets.

Then, add the "Fonts provided by application" key to your app’s Info.plist file. For the key’s value, provide an array of strings containing the relative paths to any added font files.

In the following example, the font file is inside the fonts directory, so you use fonts/roboto_mono_bold_italic.ttf as the string value in the Info.plist file.

React Native

Finally, just set the font passing the name of the font file when instantiating FaceConfig in your React Native app.

const config = FaceConfigPreset.getConfig(FaceConfigType.FACE_CAPTURE)
  .setStylesFontFamily("roboto_mono_bold_italic");

Changing Icon

Android

You can use the default icon or set a icon you prefer. To set a icon, download the icon which ever you want and paste it inside drawable folder in your android/app/src/main/res. All icon file names must be only: lowercase a-z, 0-9, or underscore. The structure should be some thing like below.

iOS

To add icon files to your Xcode project:

  1. In the Project navigator, select an asset catalog: a file with a .xcassets file extension.
  2. Drag an image from the Finder to the outline view. A new image set appears in the outline view, and the image asset appears in a well in the detail area.

React Native

Finally, just set the icon passing the name of the icon file when instantiating FaceConfig in your React Native app.

const config = FaceConfigPreset.getConfig(FaceConfigType.FACE_CAPTURE)
  // changing back button icon
  .setStylesBackButtonIcon("ic_baseline_camera")
  // changing flash button icon
  .setStylesFlashButtonIcon("ic_baseline_camera")
  // changing flip camera button icon
  .setStylesFlipCameraButtonIcon("ic_baseline_camera")
  // changing capture button icon
  .setStylesCaptureButtonIcon("ic_baseline_camera");

FaceSize

Variable nameType
widthnumber
heightnumber

FaceCameraPreset (enum)

NameResolution
FaceCameraPreset.LOW240p (352x288 on iOS, 320x240 on Android)
FaceCameraPreset.MEDIUM480p (640x480 on iOS, 720x480 on Android)
FaceCameraPreset.HIGH720p (1280x720)
FaceCameraPreset.VERYHIGH1080p (1920x1080)
FaceCameraPreset.ULTRAHIGH2160p (3840x2160)
FaceCameraPreset.MAXThe highest resolution available

FaceCameraLensDirection (enum)

Name
FaceCameraLensDirection.FRONT
FaceCameraLensDirection.BACK

FaceCaptureFormat (enum)

Name
FaceCaptureFormat.JPEG
FaceCaptureFormat.PNG

FaceCaptureButtonType (enum)

Name
FaceCaptureButtonType.CUSTOM
FaceCaptureButtonType.ICON

FaceScreenShape (enum)

Name
FaceScreenShape.SQUARE
FaceScreenShape.ELLIPSE
FaceScreenShape.CUSTOM

Using Custom Capture Button

const config = FaceConfigPreset.getConfig(FaceConfigType.FACE_CAPTURE)
  .setCaptureButtonType(FaceCaptureButtonType.CUSTOM)
  .setStylesCustomButtonBackgroundColor("#FFFF00")
  .setStylesCustomButtonTextColor("#FF00FF")
  .setStringsCustomButtonText("Capture");

Using Icon Capture Button

const config = FaceConfigPreset.getConfig(FaceConfigType.FACE_CAPTURE)
    .setCaptureButtonType(FaceCaptureButtonType.ICON)
    .setStylesCaptureButtonIcon("ic_baseline_camera")
    .setStylesCaptureButtonColor("#FF0000")
    .setStylesCaptureButtonSize({width: 76, height: 76});

How to instantiate and functionalities

To instantiate it's easy as to do one function call (as we have seen previously on the example). You only need to specify which type of config you want using a ENUM FaceConfigType. Every type however can have different features implemented, here are the supported types:

Config TypeEnumfeature
Face CaptureFaceConfigType.FACE_CAPTURECapture still image and detects face
Continuous CaptureFaceConfigType.CONTINUOUS_CAPTURECapture every frame per second

FaceEvent

On your Face callback function, you receive a FaceEvent.

FaceEvent

NameType
photostring // Base64 string

Changelog

v1.1.0

  • New feature maxNumberFrames:
    • It is now possible to set a maximum number of frames to be captured during continuous capture.
  • Documentation update.

v1.0.1

  • Documentation update;
  • Fixed a bug that caused the camera preview image to be stretched during continuous capture for Android;
  • Improved license functionality for iOS.

v1.0.0

  • Documentation update;
  • FaceCameraPreset Refactoring;
  • FaceEvent refactoring:
    • Now the photo is returned in Base64 string format.
  • Fix autoCaptute and autoCaptuteTimeout for iOS;
  • Fix CustomFonts feature for iOS.

v0.1.23

  • Documentation update;
  • New config option autoCaptureTimeout;
  • UI customization improvements:
    • Added FaceScreenShape with more face shape options;
    • Added progress animation during face detection.

v0.1.22

  • Bug fixes;
  • Documentation update.

v0.1.21

  • Bug fixes.

v0.1.20

  • New licensing feature.

v0.1.19

  • Bug fix.

v0.1.18

  • Bug fixes;
  • Flash mode fixes;
  • Face detection improvement;
  • New feature automatic capture;
  • UI customization improvements;
  • New feature face detection;
  • Camera preset fix;
  • Camera preview fix;
  • New icon capture button;
  • Fix in requesting permissions;
  • Fix in performance of ContinuousCapture;
  • Parameterizable screenTitle;
  • New option to set text color;
  • New custom capture button;
  • Class name standardization;
  • New option to set the font.

v0.1.13

  • Face Capture SDK for Android and iOS.

License

This project is proprietary software. See the LICENSE for more information.

Keywords

FAQs

Package last updated on 27 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc