npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-biometric

v0.0.3

Published

Scan the fingerprint of your user with the TouchID sensor, or the user's Face with Face ID on iPhone X

Downloads

116

Readme

Cordova Biometric Plugin

Works with Face ID on iPhone X 🚀

Index

  1. Description
  2. Installation
  3. Usage
  4. Security++
  5. Face ID support

Description

Scan the fingerprint of your user with the TouchID sensor (iPhone 5S).

  • Compatible with Cordova Plugman.
  • Minimum iOS version is 8 (error callbacks will be gracefully invoked on lower versions).
  • Requires a fingerprint scanner, so an iPhone 5S or newer is required.

Installation

Automatically (CLI / Plugman)

Compatible with Cordova Plugman, compatible with PhoneGap 3.0 CLI, here's how it works with the CLI (backup your project first!):

From npm:

$ cordova plugin add cordova-plugin-biometric
$ cordova prepare

Biometric.js is brought in automatically. There is no need to change or add anything in your html.

Manually

1. Add the following xml to your config.xml in the root directory of your www folder:

<feature name="Biometric">
  <param name="ios-package" value="Biometric" />
</feature>

You'll need to add the LocalAuthentication.framework and Security.framework to your project. Click your project, Build Phases, Link Binary With Libraries, search for and add the frameworks.

2. Grab a copy of Biometric.js, add it to your project and reference it in index.html:

<script type="text/javascript" src="js/Biometric.js"></script>

3. Download the source files and copy them to your project.

iOS: Copy the two .h and two .m files to platforms/ios/<ProjectName>/Plugins

Usage

First you'll want to check whether or not the user has a configured biometrics. You can use this to show a 'log in with your biometrics' button next to a username/password login form.

window.plugins.biometric.isAvailable(
  function(type) {alert(type)}, // type returned to success callback: 'face' on iPhone X, 'touch' on other devices
  function(msg) {alert('not available, message: ' + msg)} // error handler: no TouchID available
);

If the onSuccess handler was called, you can verify the biometric. There are two options: verifyBiometric and verifyBiometricWithCustomPasswordFallback. The first method will offer a fallback option called 'enter passcode' which shows the default passcode UI when pressed. The second method will offer a fallback option called 'enter password' (not passcode) which allows you to provide your own password dialog.

window.plugins.biometric.verifyBiometric(
  'Scan your biometric please', // this will be shown in the native scanner popup
   function(msg) {alert('ok: ' + msg)}, // success handler: biometric accepted
   function(msg) {alert('not ok: ' + JSON.stringify(msg))} // error handler with errorcode and localised reason
);

The errorhandler of the method above can receive an error code of -2 which means the user pressed the 'enter password' fallback.

window.plugins.biometric.verifyBiometricWithCustomPasswordFallback(
  'Scan your biometric please', // this will be shown in the native scanner popup
   function(msg) {alert('ok: ' + msg)}, // success handler: biometric accepted
   function(msg) {alert('not ok: ' + JSON.stringify(msg))} // error handler with errorcode and localised reason
);

This will render a button labelled 'Enter password' in case the biometric is not recognized. If you want to provide your own label ('Enter PIN' perhaps), you can use awkwardly named function (added in version 3.1.0):

window.plugins.biometric.verifyBiometricWithCustomPasswordFallbackAndEnterPasswordLabel(
  'Scan your biometric please', // this will be shown in the native scanner popup
  'Enter PIN', // this will become the 'Enter password' button label
   function(msg) {alert('ok: ' + msg)}, // success handler: biometric accepted
   function(msg) {alert('not ok: ' + JSON.stringify(msg))} // error handler with errorcode and localised reason
);

You can copy-paste these lines of code for a quick test:

<button onclick="window.plugins.biometric.isAvailable(function(msg) {alert('ok: ' + msg)}, function(msg) {alert('not ok: ' + msg)})">Biometric available?</button>
<button onclick="window.plugins.biometric.verifyBiometric('Scan your biometric please', function(msg) {alert('ok: ' + msg)}, function(msg) {alert('not ok: ' + JSON.stringify(msg))})">Verify Biometric</button>

Security++

Since iOS9 it's possible to check whether or not the list of enrolled biometrics changed since the last time you checked it. It's recommended you add this check so you can counter hacker attacks to your app. See this article for more details.

So instead of checking the biometric after isAvailable add another check. In case didBiometricDatabaseChange returns true you probably want to re-authenticate your user before accepting valid biometrics again.

window.plugins.biometric.isAvailable(
    // success handler; available
    function() {
      window.plugins.biometric.didBiometricDatabaseChange(
          function(changed) {
            if (changed) {
              // re-auth the user by asking for his credentials before allowing a biometric scan again
            } else {
              // call the biometric scanner
            }
          }
      );
    },
    // error handler; not available
    function(msg) {
      // use a more traditional auth mechanism
    }
);

Face ID Support

Since iOS 11, LocalAuthentication also supports Face ID for biometrics. This is a drop-in replacement for Touch ID and any existing apps using Touch ID will work identically on devices that use Face ID.

Since plugin version 3.3.0 the success callback of isAvailable receives the type of biometric ID, which is either touch or face.

You can use this to display "Face ID" or "Touch ID" as appropriate in your app.

window.plugins.biometric.isAvailable(
  function(type) {alert(type)}, // type returned to success callback: 'face' on iPhone X, 'touch' on other devices
  function(msg) {alert('not available, message: ' + msg)} // error handler: no biometric available
);

If you want to alter the usage description in the consent popup, then override the default empty adds an empty NSFaceIDUsageDescription. To do so, pass the following variable when installing the plugin:

cordova plugin add cordova-plugin-biometric --variable FACEID_USAGE_DESCRIPTION="For easy authentication"