@capgo/capacitor-native-biometric 7.1.6 → 7.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Capacitor Native Biometric
2
2
  <a href="https://capgo.app/"><img src='https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png' alt='Capgo - Instant updates for capacitor'/></a>
3
-
3
+
4
4
  <div align="center">
5
- <h2><a href="https://capgo.app/?ref=plugin"> ➡️ Get Instant updates for your App with Capgo 🚀</a></h2>
6
- <h2><a href="https://capgo.app/consulting/?ref=plugin"> Fix your annoying bug now, Hire a Capacitor expert 💪</a></h2>
5
+ <h2><a href="https://capgo.app/?ref=plugin"> ➡️ Get Instant updates for your App with Capgo</a></h2>
6
+ <h2><a href="https://capgo.app/consulting/?ref=plugin"> Missing a feature? We’ll build the plugin for you 💪</a></h2>
7
7
  </div>
8
8
 
9
9
 
10
10
  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).
11
11
 
12
- ## Installation (Only supports Capacitor 6)
12
+ ## Installation (Only supports Capacitor 7)
13
13
 
14
14
  - `npm i @capgo/capacitor-native-biometric`
15
15
 
@@ -14,6 +14,7 @@ import java.util.concurrent.Executor;
14
14
 
15
15
  public class AuthActivity extends AppCompatActivity {
16
16
 
17
+ private BiometricPrompt biometricPrompt;
17
18
  private int maxAttempts;
18
19
  private int counter = 0;
19
20
 
@@ -76,7 +77,7 @@ public class AuthActivity extends AppCompatActivity {
76
77
 
77
78
  BiometricPrompt.PromptInfo promptInfo = builder.build();
78
79
 
79
- BiometricPrompt biometricPrompt = new BiometricPrompt(
80
+ biometricPrompt = new BiometricPrompt(
80
81
  this,
81
82
  executor,
82
83
  new BiometricPrompt.AuthenticationCallback() {
@@ -86,9 +87,16 @@ public class AuthActivity extends AppCompatActivity {
86
87
  @NonNull CharSequence errString
87
88
  ) {
88
89
  super.onAuthenticationError(errorCode, errString);
89
- int pluginErrorCode = AuthActivity.convertToPluginErrorCode(
90
- errorCode
91
- );
90
+ // Handle lockout cases explicitly
91
+ if (
92
+ errorCode == BiometricPrompt.ERROR_LOCKOUT ||
93
+ errorCode == BiometricPrompt.ERROR_LOCKOUT_PERMANENT
94
+ ) {
95
+ int pluginErrorCode = convertToPluginErrorCode(errorCode);
96
+ finishActivity("error", pluginErrorCode, errString.toString());
97
+ return;
98
+ }
99
+ int pluginErrorCode = convertToPluginErrorCode(errorCode);
92
100
  finishActivity("error", pluginErrorCode, errString.toString());
93
101
  }
94
102
 
@@ -104,11 +112,11 @@ public class AuthActivity extends AppCompatActivity {
104
112
  public void onAuthenticationFailed() {
105
113
  super.onAuthenticationFailed();
106
114
  counter++;
107
- if (counter == maxAttempts) finishActivity(
108
- "failed",
109
- 10,
110
- "Authentication failed."
111
- );
115
+ if (counter >= maxAttempts) {
116
+ biometricPrompt.cancelAuthentication();
117
+ // Use error code 4 for too many attempts to match iOS behavior
118
+ finishActivity("error", 4, "Too many failed attempts");
119
+ }
112
120
  }
113
121
  }
114
122
  );
@@ -146,11 +154,11 @@ public class AuthActivity extends AppCompatActivity {
146
154
  case BiometricPrompt.ERROR_HW_NOT_PRESENT:
147
155
  return 1;
148
156
  case BiometricPrompt.ERROR_LOCKOUT_PERMANENT:
149
- return 2;
157
+ return 2; // Permanent lockout
150
158
  case BiometricPrompt.ERROR_NO_BIOMETRICS:
151
159
  return 3;
152
160
  case BiometricPrompt.ERROR_LOCKOUT:
153
- return 4;
161
+ return 4; // Temporary lockout (too many attempts)
154
162
  // Authentication Failure (10) Handled by `onAuthenticationFailed`.
155
163
  // App Cancel (11), Invalid Context (12), and Not Interactive (13) are not valid error codes for Android.
156
164
  case BiometricPrompt.ERROR_NO_DEVICE_CREDENTIAL:
@@ -161,6 +169,8 @@ public class AuthActivity extends AppCompatActivity {
161
169
  case BiometricPrompt.ERROR_USER_CANCELED:
162
170
  case BiometricPrompt.ERROR_NEGATIVE_BUTTON:
163
171
  return 16;
172
+ case BiometricPrompt.AUTHENTICATION_RESULT_TYPE_BIOMETRIC:
173
+ return 0; // Success case, should not be handled here
164
174
  default:
165
175
  return 0;
166
176
  }
@@ -468,9 +468,18 @@ public class NativeBiometric extends Plugin {
468
468
  )
469
469
  .setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA512)
470
470
  .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
471
+ .setUserAuthenticationRequired(true)
472
+ // Set authentication validity duration to 0 to require authentication for every use
473
+ .setUserAuthenticationParameters(
474
+ 0,
475
+ KeyProperties.AUTH_BIOMETRIC_STRONG
476
+ )
471
477
  .build()
472
478
  );
473
479
  keyPairGenerator.generateKeyPair();
480
+ // Get the newly generated key entry
481
+ privateKeyEntry = (KeyStore.PrivateKeyEntry) getKeyStore()
482
+ .getEntry(KEY_ALIAS, null);
474
483
  }
475
484
 
476
485
  return privateKeyEntry;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-native-biometric",
3
- "version": "7.1.6",
3
+ "version": "7.1.12",
4
4
  "description": "This plugin gives access to the native biometric apis for android and iOS",
5
5
  "main": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",