Giter Site home page Giter Site logo

capacitor-biometric-auth's Introduction

Capacitor Biometric Auth

NPM Downloads CI

Installation

  • npm i capacitor-biometric-auth
  • yarn add capacitor-biometric-auth

Setup

Don't for get to run npx cap sync before doing the next steps.

Android

To get android working please add this code to your MainActivity file.

MainActivity.java

++ import com.ahm.capacitor.biometric.BiometricAuth;

this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
++ add(BiometricAuth.class);
}});

IOS

@TODO

Usage

import { Plugins } from "@capacitor/core";

const { BiometricAuth } = Plugins;

const available = await BiometricAuth.isAvailable()

if (available.has) {
  const authResult = await BiometricAuth.verify({...})
  if (authResult.verified) {
    // success authentication
  } else {
    // fail authentication
  }
} else {
  // biometric not available
}

Methods

verify(options)

Open biometric popup

option values decription
reason any string Popup label for iOS
title any string Title of prompt in Android
subTitle any string Subtitle of prompt in Android
description any string Description of prompt in Android
cancel any string Text for cancel button on prompt in Android
const result = await BiometricAuth.verify({reason: "Message ..."})

result

{
  verified: true // true if biometric auth was succes or false otherwise,
  status: {} // an object with errors matching biometric auth fails (on if verified === false)
}

status

error description
10 The user failed to provide valid credentials
11 Authentication was cancelled by application
12 The context is invalid
13 Not interactive
14 Passcode is not set on the device
15 Authentication was cancelled by the system
16 The user did cancel
17 The user chose to use the fallback

isAvailable()

Checks if biometric is enabled

const result = await BiometricAuth.isAvailable()

result

{
  has: true, // true if has biometric auth enabled, false otherwise
  status: {...} // an object with errors
}

status

error description
1 Biometric not available
2 Authentication could not continue because the user has been locked out of biometric authentication, due to failing authentication too many times.
3 Authentication could not start because the user has not enrolled in biometric authentication.

capacitor-biometric-auth's People

Contributors

ahernandez-technisys avatar arielhernandezmusa avatar iwantwin avatar jjasloot avatar larsvankleef avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

capacitor-biometric-auth's Issues

How to cancel BiometricAuth.verify()

I am using this plugin. On ios it works great because the touch ID popup has a "cancel" button that can be pressed.

However, in my Android device (One Plus 6T with in-screen fingerprint scanner), the fingerprint overlay appears, but there's no way to cancel it.

If I add a button labeled "Cancel", I can't dismiss it because the plugin is still waiting for the fingerprint to be entered.

Is there any way to cancel or dismiss the action that was initiated by BiometricAuth.verify() ?

That would help with my integration a lot because I can let the user cancel the authentication and enter their login details manually instead. Otherwise they would be forced to use the biometric authentication.

faceId unlock not working in iPhone 11

hi,

I am getting screen for passcode instead of face unlock,even when face is registered and setup as unlock mechanism in iPhone 11.

In Samsung M31, If fingerprint is not registered, only face is registered, BiometricAuth.isAvailable() is returning result.has as false. for Samsung face unlock option only comes if fingerprint and face both are registered

Is anyone else facing same issue?

Plugin no longer compatible - Compiling for iOS 11

Using Capacitor 3 which targets iOS 12 and above (the last three iOS versions), this plugin is no longer supported as it requires iOS 11 according to the Plugin.swift file.

Error:

Compiling for iOS 11.0, but module 'Capacitor' has a minimum deployment target of iOS 12.0: /Users/me/Library/Developer/Xcode/DerivedData/App-fagvejonowsphfanxptpzbgafzge/Build/Products/Debug-iphonesimulator/Capacitor/Capacitor.framework/Modules/Capacitor.swiftmodule/x86_64-apple-ios-simulator.swiftmodule

Changing the target in the podspec clears the Xcode issue, however, it's not possible to implement any of the interfaces correctly.

I think this needs upgrading for use in Capacitor 3.

BiometricAuth.verify fails in Android

When the Device Runs BiometricAuth.verify throws an Exception and the app crashes.

Tested on Device Motorola G5 Plus Android 8.1:

Android Studio Debug Error:

E/Capacitor: Serious error executing plugin
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99)
at com.getcapacitor.Bridge$1.run(Bridge.java:521)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/hardware/biometrics/BiometricPrompt$Builder;
at com.ahm.capacitor.biometric.BiometricAuth.displayBiometricPrompt(BiometricAuth.java:51)
at com.ahm.capacitor.biometric.BiometricAuth.verify(BiometricAuth.java:44)
at java.lang.reflect.Method.invoke(Native Method) 
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99) 
at com.getcapacitor.Bridge$1.run(Bridge.java:521) 
at android.os.Handler.handleCallback(Handler.java:790) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:164) 
at android.os.HandlerThread.run(HandlerThread.java:65) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.hardware.biometrics.BiometricPrompt$Builder" on path: DexPathList[[zip file "/data/app/com.authtest.test-Voezn6eKdFjD322ANuCwjA==/base.apk"],nativeLibraryDirectories=[/data/app/com.authtest.test-Voezn6eKdFjD322ANuCwjA==/lib/arm, /system/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.ahm.capacitor.biometric.BiometricAuth.displayBiometricPrompt(BiometricAuth.java:51) 
at com.ahm.capacitor.biometric.BiometricAuth.verify(BiometricAuth.java:44) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99) 
at com.getcapacitor.Bridge$1.run(Bridge.java:521) 
at android.os.Handler.handleCallback(Handler.java:790) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:164) 
at android.os.HandlerThread.run(HandlerThread.java:65) 
E/AndroidRuntime: FATAL EXCEPTION: CapacitorPlugins
Process: com.authtest.test, PID: 4858
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.getcapacitor.Bridge$1.run(Bridge.java:530)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99)
at com.getcapacitor.Bridge$1.run(Bridge.java:521)
at android.os.Handler.handleCallback(Handler.java:790) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:164) 
at android.os.HandlerThread.run(HandlerThread.java:65) 
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/hardware/biometrics/BiometricPrompt$Builder;
at com.ahm.capacitor.biometric.BiometricAuth.displayBiometricPrompt(BiometricAuth.java:51)
at com.ahm.capacitor.biometric.BiometricAuth.verify(BiometricAuth.java:44)
at java.lang.reflect.Method.invoke(Native Method) 
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99) 
at com.getcapacitor.Bridge$1.run(Bridge.java:521) 
at android.os.Handler.handleCallback(Handler.java:790) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:164) 
at android.os.HandlerThread.run(HandlerThread.java:65) 
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.hardware.biometrics.BiometricPrompt$Builder" on path: DexPathList[[zip file "/data/app/com.authtest.test-Voezn6eKdFjD322ANuCwjA==/base.apk"],nativeLibraryDirectories=[/data/app/com.authtest.test-Voezn6eKdFjD322ANuCwjA==/lib/arm, /system/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.ahm.capacitor.biometric.BiometricAuth.displayBiometricPrompt(BiometricAuth.java:51) 
at com.ahm.capacitor.biometric.BiometricAuth.verify(BiometricAuth.java:44) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99) 
at com.getcapacitor.Bridge$1.run(Bridge.java:521) 
at android.os.Handler.handleCallback(Handler.java:790) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:164) 
at android.os.HandlerThread.run(HandlerThread.java:65) 

Unable to use in Android

iOS worked great but when I built and installed for Android .isAvailable was triggering a type error. So I console logged BiometricAuth and it came back undefined.

BiometricAuth.verify crashed app - Android

Huawei P8 lite 2017
Android version 8.0.0

I use Android device.

In my case its not working. If I call

const authResult = await BiometricAuth.verify( { reason: 'text', title: 'text', } );
the app crashed.

const isAvailable = await BiometricAuth.isAvailable(); isAvailable.has
return true

E/Capacitor: Serious error executing plugin
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99)
at com.getcapacitor.Bridge$1.run(Bridge.java:542)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/hardware/biometrics/BiometricPrompt$Builder;
at com.ahm.capacitor.biometric.BiometricAuth.displayBiometricPrompt(BiometricAuth.java:51)
at com.ahm.capacitor.biometric.BiometricAuth.verify(BiometricAuth.java:44)
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99)
at com.getcapacitor.Bridge$1.run(Bridge.java:542)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.hardware.biometrics.BiometricPrompt$Builder" on path: DexPathList[[zip file "/data/app/de.testapp.test-4s8qI1pkoXXHAo4q-0JTAQ==/base.apk"],nativeLibraryDirectories=[/data/app/de.testapp.test-4s8qI1pkoXXHAo4q-0JTAQ==/lib/arm64, /system/lib64, /vendor/lib64, /product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.ahm.capacitor.biometric.BiometricAuth.displayBiometricPrompt(BiometricAuth.java:51)
at com.ahm.capacitor.biometric.BiometricAuth.verify(BiometricAuth.java:44)
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:99)
at com.getcapacitor.Bridge$1.run(Bridge.java:542)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.os.HandlerThread.run(HandlerThread.java:65)

Installed: "capacitor-biometric-auth": "^0.1.1"

varibles.gradle file:

ext {
minSdkVersion = 23
compileSdkVersion = 30
targetSdkVersion = 30
androidxAppCompatVersion = '1.1.0'
androidxCoreVersion = '1.2.0'
androidxMaterialVersion = '1.1.0-rc02'
androidxBrowserVersion = '1.2.0'
androidxLocalbroadcastmanagerVersion = '1.0.0'
androidxExifInterfaceVersion = '1.2.0'
firebaseMessagingVersion = '20.1.2'
playServicesLocationVersion = '17.0.0'
junitVersion = '4.12'
androidxJunitVersion = '1.1.1'
androidxEspressoCoreVersion = '3.2.0'
cordovaAndroidVersion = '7.0.0'
}

Ionic info:
Ionic:

Ionic CLI : 6.13.1 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.4.1
@angular-devkit/build-angular : 0.1000.8
@angular-devkit/schematics : 10.0.8
@angular/cli : 10.0.8
@ionic/angular-toolkit : 2.3.3

Capacitor:

Capacitor CLI : 2.4.6
@capacitor/core : 2.4.6

Cordova:

Cordova CLI : 10.0.0
Cordova Platforms : not available
Cordova Plugins : not available

Utility:

cordova-res (update available: 0.15.3) : 0.15.2
native-run : 1.3.0

System:

Android SDK Tools : 26.1.1 (/mnt/Mango/sdk/android)
NodeJS : v12.18.3 (/usr/local/bin/node)
npm : 7.7.5
OS : Linux 5.4

Plugin not compatible with Capacitor 2

@arielhernandezmusa thanks a lot for this wonderful plugin.

Could you please update it for capacitor 2 ? Because it seems not to be working well with it.

On Android the plugin makes the app crashes.
On iOS, the call.reject parameters of verify function seem to be wrong.

Could it be also possible that the available function returns the type of auth available (fingerprint or face) ?

Thanks a lot

Interface 'CapacitorInstance' incorrectly extends interface 'CapacitorGlobal'

Hi, I'm getting folloing exception when trying to use this plugin.

Please help anyone

Exception:
] Error: node_modules/@capacitor/core/types/definitions-internal.d.ts:16:18 - error TS2430: Interface 'CapacitorInstance' incorrectly extends interface 'CapacitorGlobal'.
[ng] Types of property 'Plugins' are incompatible.
[ng] Property 'BiometricAuth' is missing in type '{ [pluginName: string]: { [prop: string]: any; }; }' but required in type 'PluginRegistry'.
[ng] 16 export interface CapacitorInstance extends CapacitorGlobal {
[ng] ~~~~~~~~~~~~~~~~~
[ng] node_modules/capacitor-biometric-auth/dist/esm/definitions.d.ts:3:9
[ng] 3 BiometricAuth: BiometricAuthPlugin;
[ng] ~~~~~~~~~~~~~
[ng] 'BiometricAuth' is declared here.

Code:

import { BiometricAuth } from 'capacitor-biometric-auth';

@component({
selector: 'app-login',
templateUrl: './login.page.html',
styleUrls: ['./login.page.scss'],
})
export class LoginPage extends BaseComponent implements OnInit {
loginModel: LoginModel;
loginForm = this.fb.group({
username: [, Validators.required],
password: [, Validators.required]
});
showFallback = true;
password = '1234';
hasBiometricAuth = false;
constructor(
injector: Injector,
private modalController: ModalController
) {
super(injector);
}

async ngOnInit() {
const available = await BiometricAuth.isAvailable();
this.hasBiometricAuth = available.has;
if (this.hasBiometricAuth) {

}

}

async openBiometricAuth() {
const authResult = await BiometricAuth.verify({
reason: 'Your session has timed out',
});
if (authResult.verified) {
this.dismissLockScreen();
}
}

dismissLockScreen() {
this.modalController.dismiss({ reset: true });
}

unLock() {
if (this.password === '1234') {
this.dismissLockScreen();
}
}

}

iOS - Issue after getting : Error 17

In case the user's face ID didn't work, the user is asked to enter the passcode and by that is getting Error 17 however, the OS passcode screen is never shown.

Currently on iOS: 13

Ionic:

   Ionic CLI                     : 5.4.13 
   Ionic Framework               : @ionic/angular 5.0.0-dev.202001032123.aac4bb0
   @angular-devkit/build-angular : 0.803.21
   @angular-devkit/schematics    : 8.3.21
   @angular/cli                  : 8.3.21
   @ionic/angular-toolkit        : 2.1.1

Capacitor:

   Capacitor CLI   : 1.4.0
   @capacitor/core : 1.4.0

Cordova:

   Cordova CLI       : 7.1.0
   Cordova Platforms : none
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.0, (and 10 other plugins)

Utility:

   cordova-res : 0.8.1
   native-run  : 0.3.0

System:

   ios-deploy : 1.9.2
   ios-sim    : 6.0.0
   NodeJS     : v10.10.0 (/usr/local/bin/node)
   npm        : 6.11.2
   OS         : macOS Mojave
   Xcode      : Xcode 11.2.1 Build version 11B500

Unable to use in Android ( Capacitor 5, Ionic 7)

In my MainActivity there's no init method to begin with.

Event after manually typing in the method contents i got from Youtube, I got an error 'init()' has private access in 'androidx.fragment.app.FragmentActivity'.

How do I fix this error pls it's urgent.

BTW I'm using Android Studio Flamingo

Cannot read property 'isAvailable' of undefined.

Follow Step mentioned in Instruction .
Bellow one is may package.json
{
"name": "biotest",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"postinstall": "jetifier",
"private": true,
"dependencies": {
"@angular/common": "~9.1.6",
"@angular/core": "~9.1.6",
"@angular/forms": "~9.1.6",
"@angular/platform-browser": "~9.1.6",
"@angular/platform-browser-dynamic": "~9.1.6",
"@angular/router": "~9.1.6",
"@capacitor/android": "^2.2.0",
"@capacitor/core": "2.2.0",
"@ionic-native/core": "^5.0.7",
"@ionic-native/splash-screen": "^5.0.0",
"@ionic-native/status-bar": "^5.0.0",
"@ionic/angular": "^5.0.0",
"capacitor-biometric-auth": "^0.1.0",
"jetifier": "^1.6.6",
"rxjs": "~6.5.1",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.901.5",
"@angular/cli": "~9.1.5",
"@angular/compiler": "~9.1.6",
"@angular/compiler-cli": "~9.1.6",
"@angular/language-service": "~9.1.6",
"@capacitor/cli": "2.2.0",
"@ionic/angular-toolkit": "^2.1.1",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~3.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"protractor": "~5.4.3",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~3.8.3"
},
"description": "An Ionic project"
}

Creating apk and try to test but not working .
is there any thing i am missing . @arielhernandezmusa .

When i try to debugge it in plugings list biomatric-auth is not showing.

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.