@aparajita/capacitor-biometric-auth 7.1.1 → 7.2.0
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
|
@@ -33,11 +33,9 @@ Not using [pnpm](https://pnpm.js.org/)? You owe it to yourself to give it a try.
|
|
|
33
33
|
|
|
34
34
|
The API is extensively documented in the [TypeScript definitions file](src/definitions.ts). There is also (somewhat incomplete auto-generated) documentation [below](#api). For a complete example of how to use this plugin in practice, see the [demo app](https://github.com/aparajita/capacitor-biometric-auth-demo).
|
|
35
35
|
|
|
36
|
-
👉 **NOTE:** Your Android app must use a base theme named "AppTheme".
|
|
37
|
-
|
|
38
36
|
### Checking availability
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
Although not strictly necessary, before giving the user the option to use biometry (such as displaying a biometry icon), you will probably want to call [`checkBiometry()`](#checkbiometry) and inspect the [`CheckBiometryResult`](#checkbiometryresult) to see what (if any) biometry and/or device credentials are available on the device. Note the following:
|
|
41
39
|
|
|
42
40
|
- `isAvailable` may be `false` but `biometryType` may indicate the presence of biometry on the device. This occurs if the current user is not enrolled in biometry, or if biometry has been disabled for the current app. In such cases the `reason` and `code` will tell you why.
|
|
43
41
|
|
|
@@ -42,8 +42,10 @@ public class AuthActivity extends AppCompatActivity {
|
|
|
42
42
|
BiometricManager.Authenticators.BIOMETRIC_WEAK
|
|
43
43
|
);
|
|
44
44
|
|
|
45
|
-
allowDeviceCredential =
|
|
46
|
-
|
|
45
|
+
allowDeviceCredential = intent.getBooleanExtra(
|
|
46
|
+
BiometricAuthNative.DEVICE_CREDENTIAL,
|
|
47
|
+
false
|
|
48
|
+
);
|
|
47
49
|
|
|
48
50
|
// Android docs say that BIOMETRIC_STRONG | DEVICE_CREDENTIAL cannot be used on API 28-29.
|
|
49
51
|
// If that is the case, fall back to BIOMETRIC_WEAK.
|
package/android/src/main/java/com/aparajita/capacitor/biometricauth/BiometricAuthNative.java
CHANGED
|
@@ -7,6 +7,7 @@ import android.content.Context;
|
|
|
7
7
|
import android.content.Intent;
|
|
8
8
|
import android.content.pm.PackageManager;
|
|
9
9
|
import androidx.activity.result.ActivityResult;
|
|
10
|
+
import androidx.annotation.NonNull;
|
|
10
11
|
import androidx.biometric.BiometricManager;
|
|
11
12
|
import androidx.biometric.BiometricPrompt;
|
|
12
13
|
import com.getcapacitor.JSArray;
|
|
@@ -113,6 +114,10 @@ public class BiometricAuthNative extends Plugin {
|
|
|
113
114
|
*/
|
|
114
115
|
@PluginMethod
|
|
115
116
|
public void checkBiometry(PluginCall call) {
|
|
117
|
+
call.resolve(checkBiometry());
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private JSObject checkBiometry() {
|
|
116
121
|
JSObject result = new JSObject();
|
|
117
122
|
BiometricManager manager = BiometricManager.from(getContext());
|
|
118
123
|
|
|
@@ -162,7 +167,7 @@ public class BiometricAuthNative extends Plugin {
|
|
|
162
167
|
result.put("deviceIsSecure", false);
|
|
163
168
|
}
|
|
164
169
|
|
|
165
|
-
|
|
170
|
+
return result;
|
|
166
171
|
}
|
|
167
172
|
|
|
168
173
|
private static void setReasonAndCode(
|
|
@@ -207,6 +212,7 @@ public class BiometricAuthNative extends Plugin {
|
|
|
207
212
|
result.put(strong ? "strongCode" : "code", errorCode);
|
|
208
213
|
}
|
|
209
214
|
|
|
215
|
+
@NonNull
|
|
210
216
|
private ArrayList<BiometryType> getDeviceBiometryTypes() {
|
|
211
217
|
ArrayList<BiometryType> types = new ArrayList<>();
|
|
212
218
|
PackageManager manager = getContext().getPackageManager();
|
|
@@ -223,7 +229,7 @@ public class BiometricAuthNative extends Plugin {
|
|
|
223
229
|
types.add(BiometryType.IRIS);
|
|
224
230
|
}
|
|
225
231
|
|
|
226
|
-
if (types.
|
|
232
|
+
if (types.isEmpty()) {
|
|
227
233
|
types.add(BiometryType.NONE);
|
|
228
234
|
}
|
|
229
235
|
|
|
@@ -235,16 +241,26 @@ public class BiometricAuthNative extends Plugin {
|
|
|
235
241
|
*/
|
|
236
242
|
@PluginMethod
|
|
237
243
|
public void internalAuthenticate(final PluginCall call) {
|
|
244
|
+
// If the user has not called checkBiometry() first, we need to get the list
|
|
245
|
+
// of supported biometry.
|
|
246
|
+
if (biometryTypes == null) {
|
|
247
|
+
biometryTypes = getDeviceBiometryTypes();
|
|
248
|
+
}
|
|
249
|
+
|
|
238
250
|
// The result of an intent is supposed to have the package name as a prefix.
|
|
239
251
|
RESULT_EXTRA_PREFIX = getContext().getPackageName() + ".";
|
|
240
252
|
|
|
241
253
|
Intent intent = new Intent(getContext(), AuthActivity.class);
|
|
242
254
|
|
|
243
255
|
// Pass the options to the activity.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
)
|
|
256
|
+
String title = "";
|
|
257
|
+
|
|
258
|
+
// If no biometry is available, biometryTypes will be an empty list.
|
|
259
|
+
if (!biometryTypes.isEmpty()) {
|
|
260
|
+
title = biometryNameMap.get(biometryTypes.get(0));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
intent.putExtra(TITLE, call.getString(TITLE, title));
|
|
248
264
|
intent.putExtra(SUBTITLE, call.getString(SUBTITLE));
|
|
249
265
|
intent.putExtra(REASON, call.getString(REASON));
|
|
250
266
|
intent.putExtra(CANCEL_TITLE, call.getString(CANCEL_TITLE));
|
|
@@ -291,10 +307,9 @@ public class BiometricAuthNative extends Plugin {
|
|
|
291
307
|
String resultTypeName = null;
|
|
292
308
|
|
|
293
309
|
if (data != null) {
|
|
294
|
-
resultTypeName =
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
);
|
|
310
|
+
resultTypeName = data.getStringExtra(
|
|
311
|
+
RESULT_EXTRA_PREFIX + BiometricAuthNative.RESULT_TYPE
|
|
312
|
+
);
|
|
298
313
|
}
|
|
299
314
|
|
|
300
315
|
if (resultTypeName == null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aparajita/capacitor-biometric-auth",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "Provides access to the native biometric auth & device security APIs for Capacitor apps",
|
|
5
5
|
"author": "Aparajita Fishman",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,36 +57,36 @@
|
|
|
57
57
|
"@aparajita/eslint-config-base": "^1.1.6",
|
|
58
58
|
"@aparajita/prettier-config": "^2.0.0",
|
|
59
59
|
"@aparajita/swiftly": "^1.0.4",
|
|
60
|
-
"@capacitor/cli": "^5.
|
|
61
|
-
"@commitlint/cli": "^
|
|
62
|
-
"@commitlint/config-conventional": "^
|
|
60
|
+
"@capacitor/cli": "^5.7.4",
|
|
61
|
+
"@commitlint/cli": "^19.2.1",
|
|
62
|
+
"@commitlint/config-conventional": "^19.1.0",
|
|
63
63
|
"@ionic/swiftlint-config": "^1.1.2",
|
|
64
64
|
"@rollup/plugin-json": "^6.1.0",
|
|
65
|
-
"@types/node": "^20.
|
|
66
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
67
|
-
"@typescript-eslint/parser": "^
|
|
65
|
+
"@types/node": "^20.12.4",
|
|
66
|
+
"@typescript-eslint/eslint-plugin": "^7.5.0",
|
|
67
|
+
"@typescript-eslint/parser": "^7.5.0",
|
|
68
68
|
"commit-and-tag-version": "^12.2.0",
|
|
69
|
-
"eslint": "^8.
|
|
69
|
+
"eslint": "^8.57.0",
|
|
70
70
|
"eslint-config-prettier": "^9.1.0",
|
|
71
71
|
"eslint-config-standard": "^17.1.0",
|
|
72
72
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
73
73
|
"eslint-plugin-import": "^2.29.1",
|
|
74
74
|
"eslint-plugin-n": "^16.6.2",
|
|
75
75
|
"eslint-plugin-promise": "^6.1.1",
|
|
76
|
-
"nodemon": "^3.0
|
|
77
|
-
"prettier": "^3.2.
|
|
78
|
-
"prettier-plugin-java": "^2.
|
|
76
|
+
"nodemon": "^3.1.0",
|
|
77
|
+
"prettier": "^3.2.5",
|
|
78
|
+
"prettier-plugin-java": "^2.6.0",
|
|
79
79
|
"rimraf": "^5.0.5",
|
|
80
|
-
"rollup": "^4.
|
|
81
|
-
"simple-git-hooks": "^2.
|
|
80
|
+
"rollup": "^4.14.0",
|
|
81
|
+
"simple-git-hooks": "^2.11.1",
|
|
82
82
|
"swiftlint": "^1.0.2",
|
|
83
|
-
"typescript": "~5.
|
|
83
|
+
"typescript": "~5.4.3"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@capacitor/android": "^5.
|
|
87
|
-
"@capacitor/app": "^5.0.
|
|
88
|
-
"@capacitor/core": "^5.
|
|
89
|
-
"@capacitor/ios": "^5.
|
|
86
|
+
"@capacitor/android": "^5.7.4",
|
|
87
|
+
"@capacitor/app": "^5.0.7",
|
|
88
|
+
"@capacitor/core": "^5.7.4",
|
|
89
|
+
"@capacitor/ios": "^5.7.4"
|
|
90
90
|
},
|
|
91
91
|
"scripts": {
|
|
92
92
|
"clean": "rimraf dist",
|