Skip to content
Add Ver-ID Credentials SDK to your Cordova projects
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
src
verid @ 85a4bd4
www
.gitmodules
README.md
package.json
plugin.xml

README.md

Ver-ID Credentials Plugin for Cordova

Introduction

Ver-ID gives your application the ability to capture and parse government-issued ID cards.

Using Ver-ID Credentials Plugin with Ver-ID Person Plugin

The Ver-ID Credentials Plugin contains Ver-ID Person plugin. The two plugins cannot be installed at the same time.

Adding Ver-ID Credentials Plugin to Your Cordova App

  1. Request an API secret for your app.

  2. Clone the plugin Git repo into your file system:

    git clone --recurse-submodules https://github.com/AppliedRecognition/Ver-ID-Credentials-Cordova-Plugin.git
  3. Navigate to your Cordova project directory and install the plugin substituting path/to/plugin with the path of the plugin you checked out in the previous step:

    cordova plugin add path/to/plugin
    
  4. If your app includes iOS platform:

    • Navigate to platforms/ios and open the Podfile in a text editor. Add use_frameworks! in the target that's using the Ver-ID pod.

    • Set the platform to iOS 11: platform :ios, '11.0'.

    • Run pod install to update the project.

    • Open Cordova app's iOS work space in Xcode.

    • Ensure the project's deployment target is iOS 11 or newer.

    • Open your app's Info.plist file and and ensure it contains an entry for NSCameraUsageDescription.

    • Still in the Info.plist file add the following entry, substituting [your API secret] for the API secret obtained after registration in step 1:

       <key>com.appliedrec.verid.apiSecret</key>
       <string>[your API secret]</string>
    • Select your app target and click on the Build Settings tab. Under Build Options ensure Enable Bitcode is set to No.

    • Under Build Settings set Swift Language Version to 4.2.

  5. If your app includes Android platform:

    • Ensure your app targets Android API level 18 or newer.

    • Open your app's AndroidManifest.xml file and add the following tag in <application> replacing [your API secret] with the API secret your received in step 1:

       <meta-data 
          android:name="com.appliedrec.verid.apiSecret" 
          android:value="[your API secret]" />
    • Your application must use Theme.AppCompat theme (or its descendant).

    • Open your application's build.gradle file and under android/defaultConfig add:

      renderscriptTargetApi 18
      renderscriptSupportModeEnabled true

Loading Ver-ID

Ver-ID must be loaded before you can run face detection sessions or compare faces.

The load operation may take up to a few of seconds. Load Ver-ID using the load call:

verid.load().then(function() {
    // Ver-ID loaded successfully
    // You can now run registration, authentication or liveness detection
}).catch(function(error) {
    // Ver-ID failed to load
});

If you prefer, you can to specify the API secret in your code instead of your app's manifest or plist:

var apiSecret = "..."; // Alternative way to set your Ver-ID API secret

verid.load(apiSecret).then(function() {
    // Ver-ID loaded successfully
    // You can now run registration, authentication or liveness detection
}).catch(function(error) {
    // Ver-ID failed to load
});

Running an ID Capture Session From Javascript

The Ver-ID Credentials plugin will be available in your script as a global variable veridcredentials.

  1. Create an instance of veridcredentials.IDCaptureSessionSettings specifying what kind of ID document you wish to scan and how the user should be guided through the session.
  2. Call veridcredentials.captureId with the settings from step 1 and success and failure callbacks.
  3. Inspect the result of the callbacks.

Specify the ID document and create session settings

To scan a document Ver-ID needs to know how many pages it should capture and what features to expect on each page. You will specify this in the document property of the IDCaptureSettings object.

For example, to capture an ID card with ID-1 ISO format (credit card size) with a face photo on the front and a PDF417 barcode on the back, set the document property to:

// Specify the front of the card as ISO ID-1 page with a face photo feature
var front = new veridcredentials.Page(veridcredentials.ISOFormat.id1, new veridcredentials.FacePhotoFeature());
// Specify the back of the card as ISO ID-1 page with a barcode feature
var back = new veridcredentials.Page(veridcredentials.ISOFormat.id1, new veridcredentials.BarcodeFeature());
// Specify the ID document
var document = new veridcredentials.IDDocument([front, back]);
// Create settings
var settings = new veridcredentials.IDCaptureSessionSettings(document);
// To detect a face you will be using for face recognition:
settings.detectFaceForRecognition = true;
// To show a session guide to the user:
settings.showGuide = true;
// To show the result of the session to the user:
settings.showResult = true;

Run the ID capture session

Run the ID capture session with the settings and callbacks:

verid.load().then(function() {
	return veridcredentials.captureId(settings);
}).then(function(response) {
	// See example response below
}).catch(function(error) {
	// ID capture session failed
});

Example response

{
	"document": {
		"pages": [
			{
				"format": {
					"width": 85.6,
					"height": 53.98,
					"cornerRadius": 3.4
				},
				"faces": [
					{
						"bounds": {
							"x": 130.0,
							"y": 441.0,
							"width": 684.0,
							"height": 856.0
						}, // The bounds of the face in the image in pixels,
						"faceTemplate": {
							"data": "base64-encoded-data",
							"version": 1
						} // Template used for face comparison (see below)
					}
				],
				"image": {
					"data:image/jpeg;base64,encodedJpegData"
				}
			}, {
				"format": {
					"width": 85.6,
					"height": 53.98,
					"cornerRadius": 3.4
				},
				"barcodes": [
					{
						"format": "PDF417", // PDF417
						"data": "base64-encoded-data", // Raw barcode data,
						"parsed": {
							"DL": {
								"firstName": "Jane",
								// etc.
							}
						}
					}
				]
			}
		]
	}
}

Example: Collecting a "Live" Face and Comparing it to The Face on The ID Card

var cardFaceTemplate;

verid.load().then(function() {
	// Ver-ID loaded
	// Collect an ID card
	var front = new veridcredentials.Page(veridcredentials.ISOFormat.id1, new veridcredentials.FacePhotoFeature());
	// Specify the ID document
	var document = new veridcredentials.IDDocument([front]);
	// Create settings
	var settings = new veridcredentials.IDCaptureSessionSettings(document);
	// To detect a face you will be using for face recognition:
	settings.detectFaceForRecognition = true;
	return veridcredentials.captureId(settings);
}).then(function(response) {
	cardFaceTemplate = response.document.pages[0].faces[0].faceTemplate;
	// Capture live face
	var settings = new verid.LivenessDetectionSessionSettings();
	settings.includeFaceTemplatesInResult = true;
	return verid.captureLiveFace(settings);
}).then(function(result) {
	if (result.outcome == verid.SessionOutcome.SUCCESS) {
		var liveFaceTemplate = result.getFaces()[0].faceTemplate;
		return verid.compareFaceTemplates(cardFaceTemplate, liveFaceTemplate);
	} else if (result.outcome != verid.SessionOutcome.CANCEL) {
		throw new Error(result.outcome);
	}
}).then(function(score) {
	if (score) {
		// Score is a value between 0.0 and 1.0 indicating similarity between the face templates. 
		// Higher scores mean higher similarity.
	} else {
		// Session canceled
	}
}).catch(function(error) {
	// Handle the failure
});

API Reference

You can’t perform that action at this time.