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

capacitor-native-biometric-auth

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

capacitor-native-biometric-auth

This plugin gives access to the native biometric apis for android and iOS

  • 3.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Capacitor Native Biometric

Use biometrics confirm device owner presence or authenticate users. A couple of methods are provided to handle user credentials. These are securely stored using Keychain (iOS) and Keystore (Android).

Installation (Only supports Capacitor 3)

  • npm i capacitor-native-biometric-auth

Usage

import { NativeBiometric } from "capacitor-native-biometric-auth";

// Check if biometrics are available and which type is supported
NativeBiometric.isAvailable().then(
  (result: AvailableResult) => {
    const isAvailable = result.isAvailable;
    const isFaceId = result.biometryType == BiometryType.FACE_ID;

    if (isAvailable) {
      // Get user's credentials
      NativeBiometric.getCredentials({
        server: "www.example.com",
      }).then((credentials: Credentials) => {
        // Authenticate using biometrics before logging the user in
        NativeBiometric.verifyIdentity({
          reason: "For easy log in",
          title: "Log in",
          subtitle: "Maybe add subtitle here?",
          description: "Maybe a description too?",
          retries: 5,
        }).then(
          () => {
            // Authentication successful
            this.login(credentials.username, credentials.password);
          },
          (error) => {
            // Failed to authenticate
          }
        );
      });
    }
  },
  (error) => {
    // Couldn't check availability
  }
);

// Save user's credentials
NativeBiometric.setCredentials({
  username: "username",
  password: "password",
  server: "www.example.com",
}).then();

// Delete user's credentials
NativeBiometric.deleteCredentials({
  server: "www.example.com",
}).then();

Methods

MethodDefaultTypeDescription
isAvailable()Promise<AvailableOptions>Gets available biometrics
verifyIdentity(options?: BiometricOptions)Promise<any>Shows biometric prompt
setCredentials(options: SetCredentialOptions)Promise<any>Securely stores user's credentials in Keychain (iOS) or encypts them using Keystore (Android)
getCredentials(options: GetCredentialOptions)Promise<Credentials>Retrieves user's credentials if any
deleteCredentials(options: DeleteCredentialOptions)Promise<any>Removes user's credentials if any

Interfaces

AvailableOptions

PropertiesDefaultTypeDescription
isAvailablebooleanSpecifies if the devices has biometric enrollment
biometryTypeBiometricTypeSpecifies if the available biometric hardware on the device

BiometryType - enum

PropertiesDescription
NONEThere is no biometry available
TOUCH_IDTouchID is available (iOS)
FACE_IDFaceID is available (iOS)
FINGERPRINTFingerprint is available (Android)
FACE_AUTHENTICATIONFace Authentication is available (Android)
IRIS_AUTHENTICATIONIris Authentication is available (Android)

BiometricOptions

PropertiesDefaultTypeDescription
reason?"For biometric authentication"stringReason for requesting authentication in iOS. Displays in the authentication dialog presented to the user.
title?"Authenticate"stringTitle for the Android prompt
subtitle?stringSubtitle for the Android prompt
description?stringDescription for the Android prompt
negativeButtonText?"Cancel"stringText for the negative button displayed on Android
retires?5numberNumber of possible retries for the Android prompt

VerifyIdentityErrors

codeDescription
"0"Biometrics error or unavailable
"10"authenticationFailed
"11"appCancel
"12"invalidContext
"13"notInteractive
"14"passcodeNotSet
"15"systemCancel
"16"userCancel
"17"userFallback

SetCredentialOptions

PropertiesDefaultTypeDescription
usernamestringThe string used as the alias at the time of loggin in. It doesn't have to be a username. For example if you're using email to log in your users then provide the email.
passwordstringThe users' password
serverstringAny string to identify the credentials object with

GetCredentialOptions

PropertiesDefaultTypeDescription
serverstringThe string used to identify the credentials object when setting the credentials.

DeleteCredentialOptions

PropertiesDefaultTypeDescription
serverstringThe string used to identify the credentials object when setting the credentials.

Face ID (iOS)

To use FaceID Make sure to provide a value for NSFaceIDUsageDescription, otherwise your app may crash on iOS devices with FaceID.

This value is just the reason for using FaceID. You can add something like the following example to App/info.plist:

<key>NSFaceIDUsageDescription</key>
<string>For an easier and faster log in.</string>

Biometric (Android)

To use android's BiometricPrompt api you must add the following permission to your AndroidManifest.xml:

<uses-permission android:name="android.permission.USE_BIOMETRIC">

And register the plugin by adding it to you MainActivity's onCreate (Not needed for Capacitor 3):

import com.epicshaggy.biometric.NativeBiometric;

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
      // Additional plugins you've installed go here
      // Ex: add(TotallyAwesomePlugin.class);
      add(NativeBiometric.class);
    }});
  }
}

Contributors

Jonthia One Click Web Studio

Notes

Hasn't been tested on Android API level 22 or lower.

Keywords

FAQs

Package last updated on 21 Jan 2022

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