1
- # NativeScript Fingerprint authentication Plugin
2
- Formerly known as [ ` nativescript-touchid ` ] ( https://github.com/EddyVerbruggen/nativescript-fingerprint-auth/tree/nativescript-touchid )
1
+ # NativeScript Fingerprint Authentication
3
2
4
- <img src =" images/fingerprint.png " />
3
+ [ ![ Build Status] [ build-status ]] [ build-url ]
4
+ [ ![ NPM version] [ npm-image ]] [ npm-url ]
5
+ [ ![ Downloads] [ downloads-image ]] [ npm-url ]
6
+ [ ![ Twitter Follow] [ twitter-image ]] [ twitter-url ]
5
7
6
- ### Use when
7
- * You want to know if the device runing your app has enrolled for [ Touch ID] ( https://support.apple.com/en-us/HT201371 ) ,
8
- * You want to leverage a fingerprint scanner in your {N} app.
8
+ [ build-status ] :https://travis-ci.org/EddyVerbruggen/nativescript-fingerprint-auth.svg?branch=master
9
+ [ build-url ] :https://travis-ci.org/EddyVerbruggen/nativescript-fingerprint-auth
10
+ [ npm-image ] :http://img.shields.io/npm/v/nativescript-fingerprint-auth.svg
11
+ [ npm-url ] :https://npmjs.org/package/nativescript-fingerprint-auth
12
+ [ downloads-image ] :http://img.shields.io/npm/dm/nativescript-fingerprint-auth.svg
13
+ [ twitter-image ] :https://img.shields.io/twitter/follow/eddyverbruggen.svg?style=social&label=Follow%20me
14
+ [ twitter-url ] :https://twitter.com/eddyverbruggen
15
+
16
+ <img src =" https://github.com/EddyVerbruggen/nativescript-fingerprint-auth/tree/master/media/fingerprint.png " />
9
17
10
18
## Installation
11
19
From the command prompt go to your app's root folder and execute:
12
20
```
13
21
tns plugin add nativescript-fingerprint-auth
14
22
```
15
23
16
- ## Usage
24
+ ## Demo
25
+ If you want a quickstart, [ check out the demo app] ( https://github.com/EddyVerbruggen/nativescript-fingerprint-auth/tree/master/demo ) .
17
26
18
- If you want a quickstart, [ clone our demo app] ( https://github.com/EddyVerbruggen/nativescript-fingerprint-auth-demo ) .
27
+ <img src =" https://github.com/EddyVerbruggen/nativescript-fingerprint-auth/tree/master/media/ios-demo-01.png " width =" 200px " />
28
+ <img src =" https://github.com/EddyVerbruggen/nativescript-fingerprint-auth/tree/master/media/ios-demo-02.png " width =" 200px " />
29
+ <img src =" https://github.com/EddyVerbruggen/nativescript-fingerprint-auth/tree/master/media/ios-demo-03.png " width =" 200px " />
30
+ <img src =" https://github.com/EddyVerbruggen/nativescript-fingerprint-auth/tree/master/media/ios-demo-04.png " width =" 200px " />
31
+ <img src =" https://github.com/EddyVerbruggen/nativescript-fingerprint-auth/tree/master/media/ios-demo-05.png " width =" 200px " />
19
32
33
+ ## API
20
34
Want a nicer guide than these raw code samples? Read [ Nic Raboy's blog post about this plugin] ( https://www.thepolyglotdeveloper.com/2016/03/add-touch-id-authentication-support-to-your-nativescript-app/ ) .
21
35
22
- ### function: available
36
+ ### ` available `
37
+
38
+ #### JavaScript
23
39
``` js
24
- var fingerprintAuth = require (" nativescript-fingerprint-auth" );
40
+ var fingerprintAuthPlugin = require (" nativescript-fingerprint-auth" );
41
+ var fingerprintAuth = new fingerprintAuthPlugin.FingerprintAuth ();
25
42
26
- fingerprintAuth .available ().then (
27
- function (avail ) {
28
- console .log (" Available? " + avail);
29
- }
30
- )
43
+ fingerprintAuth .available ().then (
44
+ function (avail ) {
45
+ console .log (" Available? " + avail);
46
+ }
47
+ )
31
48
```
32
49
33
- ### function: verifyFingerprint
34
-
50
+ #### TypeScript
35
51
``` js
36
- fingerprintAuth .verifyFingerprint ({
37
- title: ' Android title' , // optional title (used only on Android)
38
- message: ' Scan yer finger' , // optional (used on both platforms)
39
- authenticationValidityDuration: 10 // optional (used on Android, default 0)
40
- }).then (
41
- function () {
42
- console .log (" Fingerprint was OK" );
43
- },
44
- function (error ) {
45
- console .log (" Fingerprint NOT OK" + (error .code ? " . Code: " + error .code : " " ));
46
- }
47
- )
52
+ import { FingerprintAuth } from " nativescript-fingerprint-auth" ;
53
+
54
+ class MyClass {
55
+ private fingerprintAuth: FingerprintAuth;
56
+
57
+ constructor () {
58
+ this .fingerprintAuth = new FingerprintAuth ();
59
+ }
60
+
61
+ this .fingerprintAuth .available ().then (
62
+ (avail : boolean ) => {
63
+ console .log (` Available? ${ avail} ` );
64
+ });
65
+ );
66
+ }
48
67
```
49
68
50
- ### function: verifyFingerprintWithCustomFallback
69
+ ### ` verifyFingerprint `
70
+ Note that on the iOS simulator this will just ` resolve() ` .
71
+
72
+ ``` js
73
+ fingerprintAuth .verifyFingerprint ({
74
+ title: ' Android title' , // optional title (used only on Android)
75
+ message: ' Scan yer finger' , // optional (used on both platforms)
76
+ authenticationValidityDuration: 10 // optional (used on Android, default 0)
77
+ }).then (
78
+ function () {
79
+ console .log (" Fingerprint was OK" );
80
+ },
81
+ function () {
82
+ console .log (" Fingerprint NOT OK" );
83
+ }
84
+ )
85
+ ```
51
86
52
- #### Note: not implemented in android yet
87
+ ### ` verifyFingerprintWithCustomFallback ` (iOS only, falls back to ` verifyFingerprint ` on Android)
88
+ Instead of falling back to the default Passcode UI of iOS you can roll your own.
89
+ Just show that when the error callback is invoked.
53
90
54
91
``` js
55
- fingerprintAuth .verifyFingerprintWithCustomFallback ({
56
- message: ' Scan yer finger' , // optional, shown in the fingerprint dialog (default: 'Scan your finger').
57
- fallbackMessage: ' Enter PIN' // optional, the button label when scanning fails (default: 'Enter password').
58
- }).then (
59
- function () {
60
- console .log (" Fingerprint was OK" );
61
- },
62
- function (error ) {
63
- console .log (" Fingerprint NOT OK" + (error .code ? " . Code: " + error .code : " " ));
64
- }
65
- )
92
+ fingerprintAuth .verifyFingerprintWithCustomFallback ({
93
+ message: ' Scan yer finger' , // optional, shown in the fingerprint dialog (default: 'Scan your finger').
94
+ fallbackMessage: ' Enter PIN' // optional, the button label when scanning fails (default: 'Enter password').
95
+ }).then (
96
+ function () {
97
+ console .log (" Fingerprint was OK" );
98
+ },
99
+ function (error ) {
100
+ // when error.code === -3, the user pressed the button labeled with your fallbackMessage
101
+ console .log (" Fingerprint NOT OK. Error code: " + error .code + " . Error message: " + error .message );
102
+ }
103
+ )
66
104
```
67
105
68
- ## Security++
106
+ ## Security++ (iOS)
69
107
Since iOS9 it's possible to check whether or not the list of enrolled fingerprints changed since
70
108
the last time you checked it. It's recommended you add this check so you can counter hacker attacks
71
109
to your app. See [ this article] ( https://godpraksis.no/2016/03/fingerprint-trojan/ ) for more details.
@@ -74,8 +112,6 @@ So instead of checking the fingerprint after `available` add another check.
74
112
In case ` didFingerprintDatabaseChange ` returns ` true ` you probably want to re-authenticate your user
75
113
before accepting valid fingerprints again.
76
114
77
- #### Note: not implemented in android yet
78
-
79
115
``` js
80
116
fingerprintAuth .available ().then (
81
117
function (avail ) {
@@ -95,7 +131,8 @@ fingerprintAuth.available().then(
95
131
```
96
132
97
133
## Changelog
98
- - 3.0.0 Android support added. Renamed ` nativescript-touchid ` to ` nativescript-fingerprint-auth ` (sorry for any inconvenience!)
134
+ - 4.0.0 Converted to TypeScript. Changed the error response type of ` verifyFingerprintWithCustomFallback ` .
135
+ - 3.0.0 Android support added. Renamed ` nativescript-touchid ` to ` nativescript-fingerprint-auth ` (sorry for any inconvenience!).
99
136
- 2.1.1 Xcode 8 compatibility - requires NativeScript 2.3.0+.
100
137
- 2.1.0 Added ` didFingerprintDatabaseChange ` for enhanced security.
101
138
- 2.0.0 Added ` verifyFingerprintWithCustomFallback ` , ` verifyFingerprint ` now falls back to the passcode.
0 commit comments