mjwheatley / cordova-plugin-android-fingerprint-auth

A cordova plugin for fingerprint authentication using the hardware fingerprint scanner on devices running Android 6+
Apache License 2.0
168 stars 131 forks source link

FingerprintAuth is not defined #8

Closed dudunegrinhu closed 8 years ago

dudunegrinhu commented 8 years ago

I'm getting this error:

Error: FingerprintAuth is not defined @http://192.168.0.5:8100/js/controllers.js:99:1 e@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:67:313 h/<.instantiate@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:67:432 Fe/this.$get</<@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:107:3 I.appendViewElement@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:385:1024 L.create/z.render@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:384:15511 L.create/z.init@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:384:14746 I.render@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:385:62 I.register@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:384:31838 a@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:386:2325 .compile/<@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:386:2485 $@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:101:149 v@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:90:203 g@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:82:299 v@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:90:147 g@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:82:299 v@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:90:147 g@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:82:299 E/<@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:81:413 I.appendViewElement@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:385:1098 L.create/z.render@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:384:15511 L.create/z.init@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:384:14746 I.render@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:385:62 I.register@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:384:31838 a@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:386:2325 .compile/</<@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:386:2430 Pe/this.$get</l.prototype.$broadcast@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:159:120 u/x.transitionTo/x.transition<@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:361:17403 f/<@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:143:20 Pe/this.$get</l.prototype.$eval@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:156:301 Pe/this.$get</l.prototype.$digest@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:153:390 Pe/this.$get</l.prototype.$apply@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:157:56 l@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:112:169 P@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:116:301 vf/</w.onload@http://192.168.0.5:8100/lib/ionic/js/ionic.bundle.min.js:117:315

mjwheatley commented 8 years ago

Hello @dudunegrinhu

What platform are you using and how did you install this plugin? All I can tell is that you are trying to use Ionic in some way. Are you using Ionic CLI?

mjwheatley commented 8 years ago

Also, this does not look like the stack trace from an Android device. FingerprintAuth is only available on Android devices. You need to put a conditional statement to check if the code is being executed on an Android Cordova device.

dudunegrinhu commented 8 years ago

Hi, I'm using Android and using ionic (first version) via terminal. I added the plugin and I added the check to see if the device is an android so when I run on the device I just get a blank screen. Is this plugin just to work with ionic 2? Is there any specific requirements?

mjwheatley commented 8 years ago

Does your app run on the Android device without this plugin? Are you waiting for the device ready event to make the call? http://ionicframework.com/docs/ionic-cli-faq/#platform-ready

What device are you running it on? Have you successfully implemented other cordova plugins?

dudunegrinhu commented 8 years ago

I'm getting somewhere. Now I'm not getting the blank screen. I'm getting the message minimum SDK 23 version required. So I added

<preference name="android-minSdkVersion" value="23"/>

and now I'm getting the message Error: Failed to install apk to device: pkg: /data/local/tmp/android-debug.apk Failure [INSTALL_FAILED_OLDER_SDK]

I'm using Galaxy S5

mjwheatley commented 8 years ago

You would also need to set your targetSdkVersion to 23.

<preference name="android-targetSdkVersioin" value="23">
dudunegrinhu commented 8 years ago

Yes I did. I must be missing something. Maybe my SDK configuration is messed up

dudunegrinhu commented 8 years ago

@mjwheatley I found the issue. I had to update my phone to Android 6.0 but now I get the message:

isAvailable:false isHardwareDetected:false hasEnrolledFingerprints: false

I even put the code to check:

if (device.platform === "Android" && device.version.startsWith("6.")) { FingerprintAuth.isAvailable(isAvailableSuccess, isAvailableError); }

and it's an Android and version is 6.0.1 now.

but I do have finger prints on my phone. Any clue that what could be the issue? Thanks.

malwatte commented 8 years ago

I don't think S5 supports Google fingerprint API.

rushabh138 commented 8 years ago

We had built our hybrid app using Telerik Kendo UI framework. We are trying to add cordova-plugin-finger-auth plugin into our project. However, we are getting error “FingerprintAuth is not defined”.

We followed steps to import custom plugin into our IDE i.e. Visual Studio. We did specified minimum SDK version 23 and we are using Android phone with version 6 and above. We call FingerprintAuth method when device OS type is Android. Still, we are getting error.

Also, for clientId and clientSecret, how and what value should be specify. Is there any format we need to follow to setup id and key?

mjwheatley commented 8 years ago

When are you making a call to FingerprintAuth? Are you waiting for deviceready? The clientId and clientSecret are arbitrary and can be any value you choose.

rushabh138 commented 8 years ago

Thanks for a response.

We did specify FingerprintAuth call on device ready state and now I’m getting error message FingerprintAuthAvailable:False, isHardwareDetected:False and hasEnrolledFingerprints: False.

For testing purpose, we specified clientId as ‘OurAppName’ and clientSecret as ‘123456789’.

Also, after declaring minimum SDK and target SDK version 23, we are not able to run app on SDK version less than 23. Is there a way to run on lower version at same time?

mjwheatley commented 8 years ago

You can set the minimum SDK version below 23, but this plugin will not work for you. The Fingerprint API is only available on version 23 and up. So you will need to detect the device version in your app and only make calls to this plugin if it is running the correct version. Otherwise you will get false for isAvailable().

mihirp1730 commented 7 years ago

i got this error while executing on my device. "Uncaught (in promise) TypeError: FingerprintAuth.encrypt is not a function"

mjwheatley commented 7 years ago

Looks like it is just a TypeScript error. Either add declare var FingerprintAuth; at the top of your typescript file or add it to a definitions.d.ts file.

mihirp1730 commented 7 years ago

Thanks for the reply and your valuable time to give me, its not ionic 2 project, i'm working on AngularJS. if i'm "declare var FingerprintAuth;" than i got "isAvailable is not define" Error, this is the error i'm facing right now. Please make me clear what it is? I got token(every time different), I got all equip true. than why it happens? please help me out.

FingerprintAuth available: {"isAvailable":true,"isHardwareDetected":true,"hasEnrolledFingerprints":true} cordova.js:312 Error in Success callbackId: FingerprintAuth481881663 : ReferenceError: encryptSuccessCallback is not defined app.js:71 Uncaught (in promise) ReferenceError: encryptSuccessCallback is not defined(…) app.js:63 FingerprintAuth available: {"withFingerprint":"+LoLg7yBf4/md+815bwRvg==\n"} app.js:36 +LoLg7yBf4/md+815bwRvg==

mjwheatley commented 7 years ago

Please provide snippets of your code.

mihirp1730 commented 7 years ago

angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.services', 'app.directives','ngCordova']) // <--include ngCordova

.run(function($ionicPlatform, $cordovaSQLite, $rootScope) { $ionicPlatform.ready(function() { // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard // for form inputs) if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); cordova.plugins.Keyboard.disableScroll(true); } if (window.StatusBar) { // org.apache.cordova.statusbar required StatusBar.styleDefault(); }

var client_id = "Finger Scan";
var client_secret = "SHA256withRSA";

FingerprintAuth.isAvailable(function(result) { if (result.isAvailable) { if(result.hasEnrolledFingerprints){ FingerprintAuth.show({ clientId: client_id, clientSecret: client_secret }, function (result) { isAvailableSuccess(result); if (result.withFingerprint) { console.log(result.withFingerprint); alert("Successfully authenticated using a fingerprint"); } else if (result.withPassword) { alert("Authenticated with backup password"); } }, function(error) { console.log(error); // "Fingerprint authentication not available" }); }else{ alert("Fingerprint auth available, but no fingerprint registered on the device"); } } }, function(message) { alert("Cannot detect fingerprint device : "+ message);

});

FingerprintAuth.isAvailable(isAvailableSuccess, isAvailableError);

/**

function isAvailableError(message) { console.log("isAvailableError(): " + message); }

//FingerprintAuth.encrypt(encryptConfig, successCallback, errorCallback);

function successCallback(result) { alert("sucess"); console.log("successCallback(): " + JSON.stringify(result)); if (result.withFingerprint) { console.log("Successfully encrypted credentials."); console.log("Encrypted credentials: " + result.token);
} else if (result.withBackup) { console.log("Authenticated with backup password"); } }

function errorCallback(error) { if (error === "Cancelled") { console.log("FingerprintAuth Dialog Cancelled!"); } else { console.log("FingerprintAuth Error: " + error); } }

mjwheatley commented 7 years ago

You just need to clean up your code.

This should be all you need:

FingerprintAuth.isAvailable(isAvailableSuccess, isAvailableError);

function isAvailableSuccess(result) {
    console.log("FingerprintAuth available: " + JSON.stringify(result));
    if (result.isAvailable) {
        // var encryptConfig = {}; // See config object for required parameters
        var encryptConfig = {
            clientId: "cordova-chatapp",
            username: "dakshesh",
            password: "daksh@123"
        };
        FingerprintAuth.encrypt(encryptConfig, encryptSuccessCallback, encryptErrorCallback);
    }
}

function isAvailableError(message) {
    console.log("isAvailableError(): " + message);
}

function encryptSuccessCallback(result) {
    alert("sucess");
    console.log("successCallback(): " + JSON.stringify(result));
    if (result.withFingerprint) {
        console.log("Successfully encrypted credentials.");
        console.log("Encrypted credentials: " + result.token);
    } else if (result.withBackup) {
        console.log("Authenticated with backup password");
    }
}

function encryptErrorCallback(error) {
    if (error === "Cancelled") {
        console.log("FingerprintAuth Dialog Cancelled!");
    } else {
        console.log("FingerprintAuth Error: " + error);
    }
}
mihirp1730 commented 7 years ago

thanks for the code, but I got the same error. here's my email mihirp1730@gmail.com can you please send me your code? if it is possible. otherwise no problem. i'll try on it. and again thank you so much for your time. if you have any other idea about this please share with me. i want to make an application with employee attendance by finger print on android device, if you can help me for idea about code.

mihirp1730 commented 7 years ago

I got this error after this snippets of your code implementation.

mzXK6Pdgc1vB0IkgvfDSiA==

cordova.js:312 Error in Success callbackId: FingerprintAuth1295497295 : TypeError: FingerprintAuth.encrypt is not a function cordova.js:314 Uncaught TypeError: FingerprintAuth.encrypt is not a function at app.js:44 at Object.callbackFromNative (cordova.js:293) at processMessage (cordova.js:1081) at processMessages (cordova.js:1104) at pollOnce (cordova.js:973) at pollOnceFromOnlineEvent (cordova.js:960)

mihirp1730 commented 7 years ago
FingerprintAuth.isAvailable(function(result) {
    if (result.isAvailable) {
        if(result.hasEnrolledFingerprints){
            FingerprintAuth.show({
                clientId: client_id,
                clientSecret: client_secret
            }, function (result) {
                //isAvailableSuccess(result);
                if (result.withFingerprint) {
                  console.log(result.withFingerprint);
                    alert("Successfully authenticated using a fingerprint");

                    var encryptConfig = {
                    clientId: "Finger Scan",
                    username: "dakshesh",
                    password: "daksh@123"
                };
                    FingerprintAuth.encrypt(encryptConfig, encryptSuccessCallback, encryptErrorCallback);
mjwheatley commented 7 years ago

You are using code from two different versions of the plugin. The show() method was replaced by encrypt() in version 1.2. Please install the latest version of the plugin and make the required changes to your code.

mihirp1730 commented 7 years ago

thank you @mjwheatley it works...

Gauhar commented 7 years ago

@mjwheatley - I have the latest version of Android Fingerprint Auth plugin and even then I am getting an error due to AndroidFingerprintAuth.encrypt. The error that I am getting is:

"Property 'encrypt' does not exist on type 'typeof AndroidFingerprintAuth'.

Please let me know that what am I doing wrong. I have followed the discussion and I seem to be doing everything fine. :-/

mjwheatley commented 7 years ago

The global variable is called FingerprintAuth not AndroidFingerprintAuth.

PreranaKrishna commented 7 years ago

Hi @mjwheatley ,

I have done exactly the way you have suggested above.

Below is my code snippet.

I have installed cordova-plugin-android-fingerprint-auth 1.2.5

and below is my code var FingerprintAuth; document.addEventListener("deviceready", function(){ alert("device ready yeay!!!"); var client_id = "Your client ID"; var client_secret = "A very secret client secret (once per device)";

    FingerprintAuth.isAvailable(isAvailableSuccess, isAvailableError);

function isAvailableSuccess(result) { console.log("FingerprintAuth available: " + JSON.stringify(result)); if (result.isAvailable) { // var encryptConfig = {}; // See config object for required parameters var encryptConfig = { clientId: "cordova-chatapp", username: "test", password: "test@123" }; FingerprintAuth.encrypt(encryptConfig, encryptSuccessCallback, encryptErrorCallback); } }

function isAvailableError(message) { console.log("isAvailableError(): " + message); }

function encryptSuccessCallback(result) { alert("sucess"); console.log("successCallback(): " + JSON.stringify(result)); if (result.withFingerprint) { console.log("Successfully encrypted credentials."); console.log("Encrypted credentials: " + result.token); } else if (result.withBackup) { console.log("Authenticated with backup password"); } }

function encryptErrorCallback(error) { if (error === "Cancelled") { console.log("FingerprintAuth Dialog Cancelled!"); } else { console.log("FingerprintAuth Error: " + error); } }

}, false);

error : Error in Success callbackId: : TypeError: Cannot read property 'isAvailable' of undefined Uncaught (in promise) TypeError: Cannot read property 'isAvailable' of undefined.

Can you please tell me what is wrong with my code.

DharmendraVaishnav91 commented 7 years ago

+1 i am also facing this issue. error : Error in Success callbackId: : TypeError: Cannot read property 'isAvailable' of undefined Uncaught (in promise) TypeError: Cannot read property 'isAvailable' of undefined.