Skip to content

Commit 0463867

Browse files
Android: Cipher error #12
1 parent 9575e4c commit 0463867

7 files changed

+28
-16
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Note that on the iOS simulator this will just `resolve()`.
7171
fingerprintAuth.verifyFingerprint({
7272
title: 'Android title', // optional title (used only on Android)
7373
message: 'Scan yer finger', // optional (used on both platforms) - for FaceID on iOS see the notes about NSFaceIDUsageDescription
74-
authenticationValidityDuration: 10 // optional (used on Android, default 0)
74+
authenticationValidityDuration: 10 // optional (used on Android, default 5)
7575
}).then(
7676
function() {
7777
console.log("Fingerprint was OK");
@@ -89,7 +89,8 @@ Just show that when the error callback is invoked.
8989
```js
9090
fingerprintAuth.verifyFingerprintWithCustomFallback({
9191
message: 'Scan yer finger', // optional, shown in the fingerprint dialog (default: 'Scan your finger').
92-
fallbackMessage: 'Enter PIN' // optional, the button label when scanning fails (default: 'Enter password').
92+
fallbackMessage: 'Enter PIN', // optional, the button label when scanning fails (default: 'Enter password').
93+
authenticationValidityDuration: 10 // optional (used on Android, default 5)
9394
}).then(
9495
function() {
9596
console.log("Fingerprint was OK");

demo/app/main-view-model.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export class HelloWorldModel extends Observable {
3131

3232
public doVerifyFingerprint(): void {
3333
this.fingerprintAuth.verifyFingerprint({
34-
message: 'Scan yer finger' // optional
34+
message: 'Scan yer finger', // optional
35+
authenticationValidityDuration: 10 // Android
3536
}).then(
3637
() => {
3738
alert({
@@ -51,7 +52,8 @@ export class HelloWorldModel extends Observable {
5152
public doVerifyFingerprintWithCustomFallback(): void {
5253
this.fingerprintAuth.verifyFingerprintWithCustomFallback({
5354
message: 'Scan yer finger', // optional
54-
fallbackMessage: 'Enter PIN' // optional
55+
fallbackMessage: 'Enter PIN', // optional
56+
authenticationValidityDuration: 10 // Android
5557
}).then(
5658
() => {
5759
alert({

demo/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"nativescript": {
33
"id": "org.nativescript.fingerprintauth",
4-
"tns-ios": {
5-
"version": "3.3.0"
6-
},
74
"tns-android": {
5+
"version": "3.3.1"
6+
},
7+
"tns-ios": {
88
"version": "3.3.0"
99
}
1010
},

src/fingerprint-auth.android.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const KeyGenParameterSpec = android.security.keystore.KeyGenParameterSpec;
1717

1818
const KEY_NAME = "fingerprintauth";
1919
const SECRET_BYTE_ARRAY = Array.create("byte", 16);
20-
const REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS = 1;
20+
const REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS = 788; // arbitrary
2121

2222
export class FingerprintAuth implements FingerprintAuthApi {
2323
private keyguardManager: any;
@@ -72,12 +72,9 @@ export class FingerprintAuth implements FingerprintAuthApi {
7272
verifyFingerprint(options: VerifyFingerprintOptions): Promise<any> {
7373
return new Promise((resolve, reject) => {
7474
try {
75-
app.android.foregroundActivity.onActivityResult = function onActivityResult(requestCode, resultCode, data) {
76-
console.log(">>> onActivityResult 1: " + requestCode);
75+
app.android.foregroundActivity.onActivityResult = (requestCode, resultCode, data) => {
7776
if (requestCode === REQUEST_CODE_CONFIRM_DEVICE_CREDENTIALS) {
78-
console.log(">>> onActivityResult 2: " + resultCode);
79-
console.log(">>> android.app.Activity.RESULT_OK: " + android.app.Activity.RESULT_OK);
80-
if (resultCode === android.app.Activity.RESULT_OK) {
77+
if (resultCode === android.app.Activity.RESULT_OK) { // OK = -1
8178
// the user has just authenticated via the ConfirmDeviceCredential activity
8279
resolve({
8380
any: true,
@@ -132,7 +129,7 @@ export class FingerprintAuth implements FingerprintAuthApi {
132129
new KeyGenParameterSpec.Builder(KEY_NAME, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
133130
.setBlockModes([KeyProperties.BLOCK_MODE_CBC])
134131
.setUserAuthenticationRequired(true)
135-
.setUserAuthenticationValidityDurationSeconds(options && options.authenticationValidityDuration ? options.authenticationValidityDuration : 0)
132+
.setUserAuthenticationValidityDurationSeconds(options && options.authenticationValidityDuration ? options.authenticationValidityDuration : 5)
136133
.setEncryptionPaddings([KeyProperties.ENCRYPTION_PADDING_PKCS7])
137134
.build()
138135
);

src/fingerprint-auth.common.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ export interface VerifyFingerprintOptions {
1010
* Default: 'Scan your finger' on iOS and the device default on Android (which is likely 'Enter your device password to continue').
1111
*/
1212
message?: string;
13+
14+
/**
15+
* Default 5 (seconds). Can be 0 to always trigger auth.
16+
* Android only.
17+
*/
18+
authenticationValidityDuration?: number;
1319
}
1420

1521
export interface VerifyFingerprintWithCustomFallbackOptions {
@@ -24,6 +30,12 @@ export interface VerifyFingerprintWithCustomFallbackOptions {
2430
* Default: 'Enter password'.
2531
*/
2632
fallbackMessage?: string;
33+
34+
/**
35+
* Default 5 (seconds). Can be 0 to always trigger auth.
36+
* Android only.
37+
*/
38+
authenticationValidityDuration?: number;
2739
}
2840

2941
export interface BiometricIDAvailableResult {

src/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-fingerprint-auth",
3-
"version": "5.0.0",
3+
"version": "5.1.0",
44
"description": "A fingerprint authentication plugin for use in NativeScript apps",
55
"main": "fingerprint-auth",
66
"nativescript": {

0 commit comments

Comments
 (0)