@aparajita/capacitor-biometric-auth 5.0.2 → 5.1.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
@@ -137,12 +137,13 @@ Register a function that will be called when the app resumes. The function will
137
137
 
138
138
  #### CheckBiometryResult
139
139
 
140
- | Prop | Type | Description |
141
- | :----------- | :------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
142
- | isAvailable | boolean | True if the device has biometric authentication capability and the current user has enrolled in biometry. |
143
- | biometryType | <a href="#biometrytype">BiometryType</a> | The type of biometry available on the device. |
144
- | reason | string | If biometry is not available and the system gives a reason why, it will be returned here. Otherwise it's an empty string. |
145
- | code | <a href="#biometryerrortype">BiometryErrorType</a> | If biometry is not available, the error code will be returned here. Otherwise it's an empty string. The error code will be one of the <a href="#biometryerrortype">`BiometryErrorType`</a> enum values, and is consistent across platforms. This allows you to check for specific errors in a platform- independent way, for example:<br><br>if (result.code === <a href="#biometryerrortype">BiometryErrorType.biometryNotEnrolled</a>) { ... } |
140
+ | Prop | Type | Description |
141
+ | :------------ | :------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
142
+ | isAvailable | boolean | True if the device has biometric authentication capability and the current user has enrolled in some form of biometry. |
143
+ | biometryType | <a href="#biometrytype">BiometryType</a> | The primary type of biometry available on the device. If the device supports both fingerprint and face authentication, this will be <a href="#biometrytype">`BiometryType.touchId`</a>. |
144
+ | biometryTypes | BiometryType[] | All of the biometry types supported by the device (currently only Android devices support multiple biometry types). If no biometry is available, this will be an empty array. If multiple types are supported, Android only guarantees that one of them is actually available. |
145
+ | reason | string | If biometry is not available and the system gives a reason why, it will be returned here. Otherwise it's an empty string. |
146
+ | code | <a href="#biometryerrortype">BiometryErrorType</a> | If biometry is not available, the error code will be returned here. Otherwise it's an empty string. The error code will be one of the <a href="#biometryerrortype">`BiometryErrorType`</a> enum values, and is consistent across platforms. This allows you to check for specific errors in a platform- independent way, for example:<br><br>if (result.code === <a href="#biometryerrortype">BiometryErrorType.biometryNotEnrolled</a>) { ... } |
146
147
 
147
148
  #### AuthenticateOptions
148
149
 
@@ -151,7 +152,7 @@ Register a function that will be called when the app resumes. The function will
151
152
  | reason | string | The reason for requesting authentication. Displays in the authentication dialog presented to the user. If not supplied, a default message is displayed. |
152
153
  | cancelTitle | string | iOS: The system presents a cancel button during biometric authentication to let the user abort the authentication attempt. The button appears every time the system asks the user to present a finger registered with Touch ID. For Face ID, the button only appears if authentication fails and the user is prompted to try again. Either way, the user can stop trying to authenticate by tapping the button.<br><br>Android: The text for the negative button. This would typically be used as a "Cancel" button, but may be also used to show an alternative method for authentication, such as a screen that asks for a backup password.<br><br>Default: "Cancel" |
153
154
  | allowDeviceCredential | boolean | If true, allows for authentication using device unlock credentials. Default is false.<br><br>iOS: If biometry is available, enrolled, and not disabled, the system uses that first. After the first Touch ID failure or second Face ID failure, if `iosFallbackTitle` is not an empty string, a fallback button appears in the authentication dialog. If the user taps the fallback button, the system prompts the user for the device passcode or the user’s password. If `iosFallbackTitle` is an empty string, no fallback button will appear.<br><br>If biometry is not available, enrolled and enabled, and a passcode is set, the system immediately prompts the user for the device passcode or user’s password. Authentication fails with the error code `passcodeNotSet` if the device passcode isn’t enabled.<br><br>If a passcode is not set on the device, a `passcodeNotSet` error is returned.<br><br>The system disables passcode authentication after 6 unsuccessful attempts, with progressively increasing delays between attempts.<br><br>The title of the fallback button may be customized by setting `iosFallbackTitle` to a non-empty string.<br><br>Android: The user will first be prompted to authenticate with biometrics, but also given the option to authenticate with their device PIN, pattern, or password by tapping a button in the authentication dialog. The title of the button is supplied by the system. |
154
- | iosFallbackTitle | string | The system presents a fallback button when biometric authentication fails — for example, because the system doesn’t recognize the presented finger, or after several failed attempts to recognize the user’s face.<br><br>If `allowDeviceCredential` is false, tapping this button dismisses the authentication dialog and returns the error code userFallback. If undefined, the localized systetm default title is used. Passing an empty string hides the fallback button completely.<br><br>If `allowDeviceCredential` is true and this is undefined, the localized system default title is used. |
155
+ | iosFallbackTitle | string | The system presents a fallback button when biometric authentication fails — for example, because the system doesn’t recognize the presented finger, or after several failed attempts to recognize the user’s face.<br><br>If `allowDeviceCredential` is false, tapping this button dismisses the authentication dialog and returns the error code userFallback. If undefined, the localized system default title is used. Passing an empty string hides the fallback button completely.<br><br>If `allowDeviceCredential` is true and this is undefined, the localized system default title is used. |
155
156
  | androidTitle | string | Title for the Android dialog. If not supplied, the system default is used. |
156
157
  | androidSubtitle | string | Subtitle for the Android dialog. If not supplied, the system default is used. |
157
158
 
@@ -1,6 +1,5 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
- >
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
4
3
 
5
4
  <application>
6
5
  <activity
@@ -8,12 +8,14 @@ import android.os.Build;
8
8
  import androidx.activity.result.ActivityResult;
9
9
  import androidx.biometric.BiometricManager;
10
10
  import androidx.biometric.BiometricPrompt;
11
+ import com.getcapacitor.JSArray;
11
12
  import com.getcapacitor.JSObject;
12
13
  import com.getcapacitor.Plugin;
13
14
  import com.getcapacitor.PluginCall;
14
15
  import com.getcapacitor.PluginMethod;
15
16
  import com.getcapacitor.annotation.ActivityCallback;
16
17
  import com.getcapacitor.annotation.CapacitorPlugin;
18
+ import java.util.ArrayList;
17
19
  import java.util.HashMap;
18
20
 
19
21
  @SuppressLint("RestrictedApi")
@@ -40,6 +42,7 @@ public class BiometricAuthNative extends Plugin {
40
42
 
41
43
  static {
42
44
  biometryErrorCodeMap = new HashMap<>();
45
+ biometryErrorCodeMap.put(BiometricManager.BIOMETRIC_SUCCESS, "");
43
46
  biometryErrorCodeMap.put(BiometricPrompt.ERROR_CANCELED, "systemCancel");
44
47
  biometryErrorCodeMap.put(
45
48
  BiometricPrompt.ERROR_HW_NOT_PRESENT,
@@ -84,7 +87,7 @@ public class BiometricAuthNative extends Plugin {
84
87
  biometryNameMap.put(BiometryType.IRIS, "Iris Authentication");
85
88
  }
86
89
 
87
- private BiometryType biometryType;
90
+ private ArrayList<BiometryType> biometryTypes;
88
91
 
89
92
  /**
90
93
  * Check the device's availability and type of biometric authentication.
@@ -106,8 +109,17 @@ public class BiometricAuthNative extends Plugin {
106
109
  "isAvailable",
107
110
  biometryResult == BiometricManager.BIOMETRIC_SUCCESS
108
111
  );
109
- biometryType = getDeviceBiometryType();
110
- ret.put("biometryType", biometryType.getType());
112
+
113
+ biometryTypes = getDeviceBiometryTypes();
114
+ ret.put("biometryType", biometryTypes.get(0).getType());
115
+
116
+ JSArray returnTypes = new JSArray();
117
+
118
+ for (BiometryType type : biometryTypes) {
119
+ returnTypes.put(type.getType());
120
+ }
121
+
122
+ ret.put("biometryTypes", returnTypes);
111
123
 
112
124
  String reason = "";
113
125
 
@@ -147,22 +159,27 @@ public class BiometricAuthNative extends Plugin {
147
159
  call.resolve(ret);
148
160
  }
149
161
 
150
- private BiometryType getDeviceBiometryType() {
162
+ private ArrayList<BiometryType> getDeviceBiometryTypes() {
163
+ ArrayList<BiometryType> types = new ArrayList<BiometryType>();
151
164
  PackageManager manager = getContext().getPackageManager();
152
165
 
153
166
  if (manager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
154
- return BiometryType.FINGERPRINT;
167
+ types.add(BiometryType.FINGERPRINT);
155
168
  }
156
169
 
157
170
  if (manager.hasSystemFeature(PackageManager.FEATURE_FACE)) {
158
- return BiometryType.FACE;
171
+ types.add(BiometryType.FACE);
159
172
  }
160
173
 
161
174
  if (manager.hasSystemFeature(PackageManager.FEATURE_IRIS)) {
162
- return BiometryType.IRIS;
175
+ types.add(BiometryType.IRIS);
176
+ }
177
+
178
+ if (types.size() == 0) {
179
+ types.add(BiometryType.NONE);
163
180
  }
164
181
 
165
- return BiometryType.NONE;
182
+ return types;
166
183
  }
167
184
 
168
185
  /**
@@ -178,7 +195,7 @@ public class BiometricAuthNative extends Plugin {
178
195
  // Pass the options to the activity
179
196
  intent.putExtra(
180
197
  TITLE,
181
- call.getString(TITLE, biometryNameMap.get(biometryType))
198
+ call.getString(TITLE, biometryNameMap.get(biometryTypes.get(0)))
182
199
  );
183
200
  intent.putExtra(SUBTITLE, call.getString(SUBTITLE));
184
201
  intent.putExtra(REASON, call.getString(REASON));
@@ -85,7 +85,7 @@ export interface AuthenticateOptions {
85
85
  *
86
86
  * If `allowDeviceCredential` is false, tapping this button dismisses the
87
87
  * authentication dialog and returns the error code userFallback. If undefined,
88
- * the localized systetm default title is used. Passing an empty string
88
+ * the localized system default title is used. Passing an empty string
89
89
  * hides the fallback button completely.
90
90
  *
91
91
  * If `allowDeviceCredential` is true and this is undefined,
@@ -135,13 +135,23 @@ export declare class BiometryError implements ResultError {
135
135
  export interface CheckBiometryResult {
136
136
  /**
137
137
  * True if the device has biometric authentication capability
138
- * and the current user has enrolled in biometry.
138
+ * and the current user has enrolled in some form of biometry.
139
139
  */
140
140
  isAvailable: boolean;
141
141
  /**
142
- * The type of biometry available on the device.
142
+ * The primary type of biometry available on the device. If the device
143
+ * supports both fingerprint and face authentication, this will be
144
+ * `BiometryType.touchId`.
143
145
  */
144
146
  biometryType: BiometryType;
147
+ /**
148
+ * All of the biometry types supported by the device (currently only
149
+ * Android devices support multiple biometry types). If no biometry
150
+ * is available, this will be an empty array. If multiple types
151
+ * are supported, Android only guarantees that one of them is actually
152
+ * available.
153
+ */
154
+ biometryTypes: BiometryType[];
145
155
  /**
146
156
  * If biometry is not available and the system gives a reason why,
147
157
  * it will be returned here. Otherwise it's an empty string.
@@ -12,6 +12,7 @@ export class BiometricAuthNative extends BiometricAuthBase {
12
12
  return Promise.resolve({
13
13
  isAvailable: true,
14
14
  biometryType: BiometryType.none,
15
+ biometryTypes: [],
15
16
  reason: '',
16
17
  code: BiometryErrorType.none,
17
18
  });
package/dist/esm/web.js CHANGED
@@ -11,17 +11,18 @@ export class BiometricAuthWeb extends BiometricAuthBase {
11
11
  return Promise.resolve({
12
12
  isAvailable: this.biometryType !== BiometryType.none,
13
13
  biometryType: this.biometryType,
14
+ biometryTypes: [],
14
15
  reason: '',
15
16
  code: BiometryErrorType.none,
16
17
  });
17
18
  }
18
19
  async authenticate(options) {
19
20
  return this.checkBiometry().then(({ isAvailable, biometryType }) => {
21
+ var _a;
20
22
  if (isAvailable) {
21
23
  if (
22
24
  // eslint-disable-next-line no-alert
23
- confirm((options === null || options === void 0 ? void 0 : options.reason) ||
24
- `Authenticate with ${getBiometryName(biometryType)}?`)) {
25
+ confirm((_a = options === null || options === void 0 ? void 0 : options.reason) !== null && _a !== void 0 ? _a : `Authenticate with ${getBiometryName(biometryType)}?`)) {
25
26
  return;
26
27
  }
27
28
  throw new BiometryError('User cancelled', BiometryErrorType.userCancel);
@@ -108,17 +108,18 @@ class BiometricAuthWeb extends BiometricAuthBase {
108
108
  return Promise.resolve({
109
109
  isAvailable: this.biometryType !== exports.BiometryType.none,
110
110
  biometryType: this.biometryType,
111
+ biometryTypes: [],
111
112
  reason: '',
112
113
  code: exports.BiometryErrorType.none,
113
114
  });
114
115
  }
115
116
  async authenticate(options) {
116
117
  return this.checkBiometry().then(({ isAvailable, biometryType }) => {
118
+ var _a;
117
119
  if (isAvailable) {
118
120
  if (
119
121
  // eslint-disable-next-line no-alert
120
- confirm((options === null || options === void 0 ? void 0 : options.reason) ||
121
- `Authenticate with ${getBiometryName(biometryType)}?`)) {
122
+ confirm((_a = options === null || options === void 0 ? void 0 : options.reason) !== null && _a !== void 0 ? _a : `Authenticate with ${getBiometryName(biometryType)}?`)) {
122
123
  return;
123
124
  }
124
125
  throw new BiometryError('User cancelled', exports.BiometryErrorType.userCancel);
@@ -161,6 +162,7 @@ class BiometricAuthNative extends BiometricAuthBase {
161
162
  return Promise.resolve({
162
163
  isAvailable: true,
163
164
  biometryType: exports.BiometryType.none,
165
+ biometryTypes: [],
164
166
  reason: '',
165
167
  code: exports.BiometryErrorType.none,
166
168
  });
package/dist/plugin.js CHANGED
@@ -106,17 +106,18 @@ var capacitorBiometricAuth = (function (exports, core, app) {
106
106
  return Promise.resolve({
107
107
  isAvailable: this.biometryType !== exports.BiometryType.none,
108
108
  biometryType: this.biometryType,
109
+ biometryTypes: [],
109
110
  reason: '',
110
111
  code: exports.BiometryErrorType.none,
111
112
  });
112
113
  }
113
114
  async authenticate(options) {
114
115
  return this.checkBiometry().then(({ isAvailable, biometryType }) => {
116
+ var _a;
115
117
  if (isAvailable) {
116
118
  if (
117
119
  // eslint-disable-next-line no-alert
118
- confirm((options === null || options === void 0 ? void 0 : options.reason) ||
119
- `Authenticate with ${getBiometryName(biometryType)}?`)) {
120
+ confirm((_a = options === null || options === void 0 ? void 0 : options.reason) !== null && _a !== void 0 ? _a : `Authenticate with ${getBiometryName(biometryType)}?`)) {
120
121
  return;
121
122
  }
122
123
  throw new BiometryError('User cancelled', exports.BiometryErrorType.userCancel);
@@ -159,6 +160,7 @@ var capacitorBiometricAuth = (function (exports, core, app) {
159
160
  return Promise.resolve({
160
161
  isAvailable: true,
161
162
  biometryType: exports.BiometryType.none,
163
+ biometryTypes: [],
162
164
  reason: '',
163
165
  code: exports.BiometryErrorType.none,
164
166
  });
@@ -8,6 +8,7 @@ private let kMissingFaceIDUsageEntry = "The device supports Face ID, but NSFaceI
8
8
  @objc(BiometricAuthNative)
9
9
  public class BiometricAuthNative: CAPPlugin {
10
10
  let biometryErrorCodeMap: [Int: String] = [
11
+ 0: "",
11
12
  LAError.appCancel.rawValue: "appCancel",
12
13
  LAError.authenticationFailed.rawValue: "authenticationFailed",
13
14
  LAError.invalidContext.rawValue: "invalidContext",
@@ -57,9 +58,13 @@ public class BiometricAuthNative: CAPPlugin {
57
58
  errorCode = biometryErrorCodeMap[error.code] ?? biometryErrorCodeMap[LAError.biometryNotAvailable.rawValue] ?? ""
58
59
  }
59
60
 
61
+ var types = JSArray()
62
+ types.append(context.biometryType.rawValue)
63
+
60
64
  call.resolve([
61
65
  "isAvailable": available,
62
66
  "biometryType": context.biometryType.rawValue,
67
+ "biometryTypes": types,
63
68
  "reason": reason,
64
69
  "code": errorCode
65
70
  ])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aparajita/capacitor-biometric-auth",
3
- "version": "5.0.2",
3
+ "version": "5.1.0",
4
4
  "description": "Provides access to the native biometric auth APIs for Capacitor apps",
5
5
  "author": "Aparajita Fishman",
6
6
  "license": "MIT",
@@ -53,46 +53,45 @@
53
53
  "devDependencies": {
54
54
  "@aparajita/capacitor-docgen": "github:aparajita/capacitor-docgen",
55
55
  "@aparajita/capacitor-docgen-format": "github:aparajita/capacitor-docgen-format",
56
- "@aparajita/eslint-config-base": "^1.1.5",
57
- "@aparajita/prettier-config": "^1.0.0",
56
+ "@aparajita/eslint-config-base": "^1.1.6",
57
+ "@aparajita/prettier-config": "^2.0.0",
58
58
  "@aparajita/swiftly": "^1.0.4",
59
- "@capacitor/cli": "^5.0.5",
60
- "@commitlint/cli": "^17.6.5",
61
- "@commitlint/config-conventional": "^17.6.5",
59
+ "@capacitor/cli": "^5.4.1",
60
+ "@commitlint/cli": "^17.7.2",
61
+ "@commitlint/config-conventional": "^17.7.0",
62
62
  "@ionic/swiftlint-config": "^1.1.2",
63
63
  "@rollup/plugin-json": "^6.0.0",
64
- "@types/node": "^20.3.1",
65
- "@typescript-eslint/eslint-plugin": "^5.60.0",
66
- "@typescript-eslint/parser": "^5.60.0",
67
- "commit-and-tag-version": "^11.2.2",
68
- "eslint": "^8.43.0",
69
- "eslint-config-prettier": "^8.8.0",
64
+ "@types/node": "^20.8.0",
65
+ "@typescript-eslint/eslint-plugin": "^6.7.3",
66
+ "@typescript-eslint/parser": "^6.7.3",
67
+ "commit-and-tag-version": "^11.2.3",
68
+ "eslint": "^8.50.0",
69
+ "eslint-config-prettier": "^9.0.0",
70
70
  "eslint-config-standard": "^17.1.0",
71
- "eslint-import-resolver-typescript": "^3.5.5",
72
- "eslint-plugin-import": "^2.27.5",
73
- "eslint-plugin-n": "^16.0.0",
74
- "eslint-plugin-prettier": "^4.2.1",
71
+ "eslint-import-resolver-typescript": "^3.6.1",
72
+ "eslint-plugin-import": "^2.28.1",
73
+ "eslint-plugin-n": "^16.1.0",
75
74
  "eslint-plugin-promise": "^6.1.1",
76
- "nodemon": "^2.0.22",
77
- "prettier": "^2.8.8",
78
- "prettier-plugin-java": "^2.1.0",
79
- "rimraf": "^5.0.1",
80
- "rollup": "^3.25.1",
75
+ "nodemon": "^3.0.1",
76
+ "prettier": "^3.0.3",
77
+ "prettier-plugin-java": "^2.3.1",
78
+ "rimraf": "^5.0.5",
79
+ "rollup": "^3.29.4",
81
80
  "swiftlint": "^1.0.2",
82
- "typescript": "~5.1.3"
81
+ "typescript": "~5.2.2"
83
82
  },
84
83
  "dependencies": {
85
- "@capacitor/android": "^5.0.5",
86
- "@capacitor/app": "^5.0.3",
87
- "@capacitor/core": "^5.0.5",
88
- "@capacitor/ios": "^5.0.5"
84
+ "@capacitor/android": "^5.4.1",
85
+ "@capacitor/app": "^5.0.6",
86
+ "@capacitor/core": "^5.4.1",
87
+ "@capacitor/ios": "^5.4.1"
89
88
  },
90
89
  "scripts": {
91
90
  "clean": "rimraf dist",
92
91
  "lint.eslint": "eslint --fix --cache --ext .js,.cjs,.mjs,.ts --max-warnings 0",
93
- "lint.prettier": "prettier --write --plugin ./node_modules/prettier-plugin-java --cache --list-different",
92
+ "lint.prettier": "prettier --write --cache --list-different",
94
93
  "lint.tsc": "tsc --noEmit",
95
- "lint": "pnpm lint.eslint . && pnpm lint.prettier . && pnpm lint.tsc && swiftly ios",
94
+ "lint": "pnpm lint.eslint . && pnpm lint.prettier '**/*.{js,mjs,ts,json,md,java}' && pnpm lint.tsc && swiftly ios",
96
95
  "prebuilder": "pnpm clean",
97
96
  "builder": "tsc ${SOURCE_MAP:-} && rollup -c rollup.config.mjs",
98
97
  "prebuild": "pnpm lint",