Giter VIP home page Giter VIP logo

react-native-bio-id's Introduction

React Native Touch ID

react-native version npm version npm downloads Code Climate

For some reason project react-native-touch-id was not updated in npm

React Native Touch ID is a React Native library for authenticating users with biometric authentication methods like Face ID and Touch ID on both iOS and Android (experimental).

react-native-bio-id

Documentation

Install

npm i --save react-native-bio-id

or

yarn add react-native-bio-id

Support

Due to the rapid changes being made in the React Native ecosystem, we are not officially going to support this module on anything but the latest version of React Native. The current supported version is indicated on the React Native badge at the top of this README. If it's out of date, we encourage you to submit a pull request!

Usage

Linking the Library

In order to use Biometric Authentication, you must first link the library to your project. There's excellent documentation on how to do this in the React Native Docs.

Or use the built-in command:

react-native link react-native-bio-id

Platform Differences

iOS and Android differ slightly in their TouchID authentication.

On Android you can customize the title and color of the pop-up by passing in the optional config object with a color and title key to the authenticate method. Even if you pass in the config object, iOS does not allow you change the color nor the title of the pop-up.

Error handling is also different between the platforms, with iOS currently providing much more descriptive error codes.

Requesting Face ID/Touch ID Authentication

Once you've linked the library, you'll want to make it available to your app by requiring it:

var BioID = require('react-native-bio-id');

or

import BioID from 'react-native-bio-id'

Requesting Face ID/Touch ID Authentication is as simple as calling:

BioID.authenticate('to demo this react-native component', optionalConfigObject)
  .then(success => {
    // Success code
  })
  .catch(error => {
    // Failure code
  });

Example

Using Face ID/Touch ID in your app will usually look like this:

import React from "react"
var BioID = require('react-native-bio-id');
//or import BioID from 'react-native-bio-id'

class YourComponent extends React.Component {
  _pressHandler() {
    BioID.authenticate('to demo this react-native component', optionalConfigObject)
      .then(success => {
        AlertIOS.alert('Authenticated Successfully');
      })
      .catch(error => {
        AlertIOS.alert('Authentication Failed');
      });
  },

  render() {
    return (
      <View>
        ...
        <TouchableHighlight onPress={this._pressHandler}>
          <Text>
            Authenticate with Touch ID
          </Text>
        </TouchableHighlight>
      </View>
    );
  }
};

Methods

authenticate(reason, config)

Attempts to authenticate with Face ID/Touch ID. Returns a Promise object.

Arguments

  • reason - An optional String that provides a clear reason for requesting authentication.

  • config - optional - Android only (does nothing on iOS) - an object that specifies the title and color to present in the confirmation dialog.

Examples

//config is optional to be passed in on Android
const optionalConfigObject = {
  title: "Authentication Required",
  color: "#e00606"
}

BioID.authenticate('to demo this react-native component', optionalConfigObject)
  .then(success => {
    AlertIOS.alert('Authenticated Successfully');
  })
  .catch(error => {
    AlertIOS.alert('Authentication Failed');
  });

isSupported()

Verify's that Touch ID is supported. Returns a Promise that resolves to a String of FaceID or TouchID .

Examples

BioID.isSupported()
  .then(biometryType => {
    // Success code
    if (biometryType === 'FaceID') {
        console.log('FaceID is supported.');
    } else {
        console.log('TouchID is supported.');
    }
  })
  .catch(error => {
    // Failure code
    console.log(error);
  });

Errors

There are various reasons why biomentric authentication may fail. When it does fails, BioID.authenticate will return an error code representing the reason.

Below is a list of error codes that can be returned on iOS:

Code Description
LAErrorAuthenticationFailed Authentication was not successful because the user failed to provide valid credentials.
LAErrorUserCancel Authentication was canceled by the user—for example, the user tapped Cancel in the dialog.
LAErrorUserFallback Authentication was canceled because the user tapped the fallback button (Enter Password).
LAErrorSystemCancel Authentication was canceled by system—for example, if another application came to foreground while the authentication dialog was up.
LAErrorPasscodeNotSet Authentication could not start because the passcode is not set on the device.
LAErrorTouchIDNotAvailable Authentication could not start because Touch ID is not available on the device
LAErrorTouchIDNotEnrolled Authentication could not start because Touch ID has no enrolled fingers.
RCTTouchIDUnknownError Could not authenticate for an unknown reason.
RCTTouchIDNotSupported Device does not support Touch ID.
RCTFaceIDNotAllow User not allow use Face ID.

More information on errors can be found in Apple's Documentation.

License

Copyright (c) 2015, Naoufal Kadhom

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

react-native-bio-id's People

Contributors

dannyvanderjagt avatar davidgruebl avatar mahlon-gumbs avatar naoufal avatar richardvanwill avatar zibs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.