@aparajita/capacitor-biometric-auth 7.1.0 → 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;
|
|
@@ -94,13 +95,14 @@ public class BiometricAuthNative extends Plugin {
|
|
|
94
95
|
private ArrayList<BiometryType> biometryTypes;
|
|
95
96
|
|
|
96
97
|
private int getAuthenticatorFromCall(PluginCall call) {
|
|
98
|
+
int authenticator = BiometricManager.Authenticators.BIOMETRIC_WEAK;
|
|
99
|
+
|
|
97
100
|
Integer value = call.getInt(
|
|
98
101
|
"androidBiometryStrength",
|
|
99
102
|
BiometryStrength.WEAK.ordinal()
|
|
100
103
|
);
|
|
101
|
-
int authenticator = BiometricManager.Authenticators.BIOMETRIC_WEAK;
|
|
102
104
|
|
|
103
|
-
if (value == BiometryStrength.STRONG.ordinal()) {
|
|
105
|
+
if (value != null && value == BiometryStrength.STRONG.ordinal()) {
|
|
104
106
|
authenticator = BiometricManager.Authenticators.BIOMETRIC_STRONG;
|
|
105
107
|
}
|
|
106
108
|
|
|
@@ -112,6 +114,10 @@ public class BiometricAuthNative extends Plugin {
|
|
|
112
114
|
*/
|
|
113
115
|
@PluginMethod
|
|
114
116
|
public void checkBiometry(PluginCall call) {
|
|
117
|
+
call.resolve(checkBiometry());
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private JSObject checkBiometry() {
|
|
115
121
|
JSObject result = new JSObject();
|
|
116
122
|
BiometricManager manager = BiometricManager.from(getContext());
|
|
117
123
|
|
|
@@ -161,7 +167,7 @@ public class BiometricAuthNative extends Plugin {
|
|
|
161
167
|
result.put("deviceIsSecure", false);
|
|
162
168
|
}
|
|
163
169
|
|
|
164
|
-
|
|
170
|
+
return result;
|
|
165
171
|
}
|
|
166
172
|
|
|
167
173
|
private static void setReasonAndCode(
|
|
@@ -206,6 +212,7 @@ public class BiometricAuthNative extends Plugin {
|
|
|
206
212
|
result.put(strong ? "strongCode" : "code", errorCode);
|
|
207
213
|
}
|
|
208
214
|
|
|
215
|
+
@NonNull
|
|
209
216
|
private ArrayList<BiometryType> getDeviceBiometryTypes() {
|
|
210
217
|
ArrayList<BiometryType> types = new ArrayList<>();
|
|
211
218
|
PackageManager manager = getContext().getPackageManager();
|
|
@@ -222,7 +229,7 @@ public class BiometricAuthNative extends Plugin {
|
|
|
222
229
|
types.add(BiometryType.IRIS);
|
|
223
230
|
}
|
|
224
231
|
|
|
225
|
-
if (types.
|
|
232
|
+
if (types.isEmpty()) {
|
|
226
233
|
types.add(BiometryType.NONE);
|
|
227
234
|
}
|
|
228
235
|
|
|
@@ -234,16 +241,26 @@ public class BiometricAuthNative extends Plugin {
|
|
|
234
241
|
*/
|
|
235
242
|
@PluginMethod
|
|
236
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
|
+
|
|
237
250
|
// The result of an intent is supposed to have the package name as a prefix.
|
|
238
251
|
RESULT_EXTRA_PREFIX = getContext().getPackageName() + ".";
|
|
239
252
|
|
|
240
253
|
Intent intent = new Intent(getContext(), AuthActivity.class);
|
|
241
254
|
|
|
242
255
|
// Pass the options to the activity.
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
)
|
|
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));
|
|
247
264
|
intent.putExtra(SUBTITLE, call.getString(SUBTITLE));
|
|
248
265
|
intent.putExtra(REASON, call.getString(REASON));
|
|
249
266
|
intent.putExtra(CANCEL_TITLE, call.getString(CANCEL_TITLE));
|
|
@@ -290,10 +307,9 @@ public class BiometricAuthNative extends Plugin {
|
|
|
290
307
|
String resultTypeName = null;
|
|
291
308
|
|
|
292
309
|
if (data != null) {
|
|
293
|
-
resultTypeName =
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
);
|
|
310
|
+
resultTypeName = data.getStringExtra(
|
|
311
|
+
RESULT_EXTRA_PREFIX + BiometricAuthNative.RESULT_TYPE
|
|
312
|
+
);
|
|
297
313
|
}
|
|
298
314
|
|
|
299
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": "^
|
|
68
|
-
"commit-and-tag-version": "^12.
|
|
69
|
-
"eslint": "^8.
|
|
65
|
+
"@types/node": "^20.12.4",
|
|
66
|
+
"@typescript-eslint/eslint-plugin": "^7.5.0",
|
|
67
|
+
"@typescript-eslint/parser": "^7.5.0",
|
|
68
|
+
"commit-and-tag-version": "^12.2.0",
|
|
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.
|
|
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",
|