diff --git a/docs/pages/versions/unversioned/sdk/local-authentication.md b/docs/pages/versions/unversioned/sdk/local-authentication.md index e8825bb6e2609..bb56f44c00905 100644 --- a/docs/pages/versions/unversioned/sdk/local-authentication.md +++ b/docs/pages/versions/unversioned/sdk/local-authentication.md @@ -7,7 +7,7 @@ import InstallSection from '~/components/plugins/InstallSection'; import PlatformsSection from '~/components/plugins/PlatformsSection'; import TableOfContentSection from '~/components/plugins/TableOfContentSection'; -**`expo-local-authentication`** allows you to use FaceID and TouchID (iOS) or the Fingerprint API (Android) to authenticate the user with a face or fingerprint scan. +**`expo-local-authentication`** allows you to use FaceID and TouchID (iOS) or the Biometric Prompt (Android) to authenticate the user with a face or fingerprint scan. @@ -58,10 +58,10 @@ Attempts to authenticate via Fingerprint/TouchID (or FaceID if available on the #### Arguments - **options (_object_)** -- An object of options. - - **promptMessage (_string_)** -- A message that is shown alongside the TouchID or FaceID prompt. (**iOS only**) - - **cancelLabel (_string_)** -- Allows to customize the default `Cancel` label shown. (**iOS only**) + - **promptMessage (_string_)** -- A message that is shown alongside the TouchID or FaceID prompt. + - **cancelLabel (_string_)** -- Allows to customize the default `Cancel` label shown. - **fallbackLabel (_string_)** -- Allows to customize the default `Use Passcode` label shown after several failed authentication attempts. Setting this option to an empty string disables this button from showing in the prompt. (**iOS only**) - - **disableDeviceFallback (_boolean_)** -- After several failed attempts the system will fallback to the device passcode. This setting allows you to disable this option and instead handle the fallback yourself. This can be preferable in certain custom authentication workflows. This behaviour maps to using the iOS [LAPolicyDeviceOwnerAuthenticationWithBiometrics](https://developer.apple.com/documentation/localauthentication/lapolicy/lapolicydeviceownerauthenticationwithbiometrics?language=objc) policy rather than the [LAPolicyDeviceOwnerAuthentication](https://developer.apple.com/documentation/localauthentication/lapolicy/lapolicydeviceownerauthentication?language=objc) policy. Defaults to `false`. (**iOS only**) + - **disableDeviceFallback (_boolean_)** -- After several failed attempts the system will fallback to the device passcode. This setting allows you to disable this option and instead handle the fallback yourself. This can be preferable in certain custom authentication workflows. This behaviour maps to using the iOS [LAPolicyDeviceOwnerAuthenticationWithBiometrics](https://developer.apple.com/documentation/localauthentication/lapolicy/lapolicydeviceownerauthenticationwithbiometrics?language=objc) policy rather than the [LAPolicyDeviceOwnerAuthentication](https://developer.apple.com/documentation/localauthentication/lapolicy/lapolicydeviceownerauthentication?language=objc) policy. Defaults to `false`. #### Returns diff --git a/packages/expo-local-authentication/CHANGELOG.md b/packages/expo-local-authentication/CHANGELOG.md index 98989f9974ac7..57993dca47d67 100644 --- a/packages/expo-local-authentication/CHANGELOG.md +++ b/packages/expo-local-authentication/CHANGELOG.md @@ -7,5 +7,8 @@ ### 🎉 New features - Added support for `promptMessage`, `cancelLabel` and `disableDeviceFallback` on Android. ([#8219](https://github.com/expo/expo/pull/8219) by [@diegolmello](https://github.com/diegolmello)) +- Added iris local authentication type for Android. ([#8431](https://github.com/expo/expo/pull/8364) by [@bycedric](https://github.com/bycedric)) ### 🐛 Bug fixes + +- Added estimate of supported authentication types for Android. ([#8431](https://github.com/expo/expo/pull/8431) by [@bycedric](https://github.com/bycedric)) diff --git a/packages/expo-local-authentication/android/src/main/java/expo/modules/localauthentication/LocalAuthenticationModule.java b/packages/expo-local-authentication/android/src/main/java/expo/modules/localauthentication/LocalAuthenticationModule.java index 7285e6926ce56..8b9647bc3891b 100644 --- a/packages/expo-local-authentication/android/src/main/java/expo/modules/localauthentication/LocalAuthenticationModule.java +++ b/packages/expo-local-authentication/android/src/main/java/expo/modules/localauthentication/LocalAuthenticationModule.java @@ -5,6 +5,7 @@ import android.app.Activity; import android.app.KeyguardManager; import android.content.Context; +import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import androidx.core.os.CancellationSignal; @@ -28,6 +29,7 @@ public class LocalAuthenticationModule extends ExportedModule { private final BiometricManager mBiometricManager; + private final PackageManager mPackageManager; private CancellationSignal mCancellationSignal; private Promise mPromise; private boolean mIsAuthenticating = false; @@ -35,6 +37,8 @@ public class LocalAuthenticationModule extends ExportedModule { private UIManager mUIManager; private static final int AUTHENTICATION_TYPE_FINGERPRINT = 1; + private static final int AUTHENTICATION_TYPE_FACIAL_RECOGNITION = 2; + private static final int AUTHENTICATION_TYPE_IRIS = 3; private final BiometricPrompt.AuthenticationCallback mAuthenticationCallback = new BiometricPrompt.AuthenticationCallback () { @@ -61,6 +65,7 @@ public LocalAuthenticationModule(Context context) { super(context); mBiometricManager = BiometricManager.from(context); + mPackageManager = context.getPackageManager(); } @Override @@ -78,9 +83,19 @@ public void onCreate(ModuleRegistry moduleRegistry) { public void supportedAuthenticationTypesAsync(final Promise promise) { int result = mBiometricManager.canAuthenticate(); List results = new ArrayList<>(); - if (result != BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE) { + if (result == BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE) { + promise.resolve(results); + return; + } + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) { results.add(AUTHENTICATION_TYPE_FINGERPRINT); } + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)) { + results.add(AUTHENTICATION_TYPE_FACIAL_RECOGNITION); + } + if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_IRIS)) { + results.add(AUTHENTICATION_TYPE_IRIS); + } promise.resolve(results); } diff --git a/packages/expo-local-authentication/build/LocalAuthentication.types.d.ts b/packages/expo-local-authentication/build/LocalAuthentication.types.d.ts index 17fa82db86625..5d67bab917ba2 100644 --- a/packages/expo-local-authentication/build/LocalAuthentication.types.d.ts +++ b/packages/expo-local-authentication/build/LocalAuthentication.types.d.ts @@ -6,7 +6,8 @@ export declare type LocalAuthenticationResult = { }; export declare enum AuthenticationType { FINGERPRINT = 1, - FACIAL_RECOGNITION = 2 + FACIAL_RECOGNITION = 2, + IRIS = 3 } export declare type LocalAuthenticationOptions = { promptMessage?: string; diff --git a/packages/expo-local-authentication/build/LocalAuthentication.types.js b/packages/expo-local-authentication/build/LocalAuthentication.types.js index b9985553a2623..df725bc0e48cc 100644 --- a/packages/expo-local-authentication/build/LocalAuthentication.types.js +++ b/packages/expo-local-authentication/build/LocalAuthentication.types.js @@ -2,5 +2,7 @@ export var AuthenticationType; (function (AuthenticationType) { AuthenticationType[AuthenticationType["FINGERPRINT"] = 1] = "FINGERPRINT"; AuthenticationType[AuthenticationType["FACIAL_RECOGNITION"] = 2] = "FACIAL_RECOGNITION"; + // Android only + AuthenticationType[AuthenticationType["IRIS"] = 3] = "IRIS"; })(AuthenticationType || (AuthenticationType = {})); //# sourceMappingURL=LocalAuthentication.types.js.map \ No newline at end of file diff --git a/packages/expo-local-authentication/build/LocalAuthentication.types.js.map b/packages/expo-local-authentication/build/LocalAuthentication.types.js.map index e413ea04f6399..4d6690ad45f35 100644 --- a/packages/expo-local-authentication/build/LocalAuthentication.types.js.map +++ b/packages/expo-local-authentication/build/LocalAuthentication.types.js.map @@ -1 +1 @@ -{"version":3,"file":"LocalAuthentication.types.js","sourceRoot":"","sources":["../src/LocalAuthentication.types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,yEAAe,CAAA;IACf,uFAAsB,CAAA;AACxB,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B","sourcesContent":["export type LocalAuthenticationResult = { success: true } | { success: false; error: string };\n\nexport enum AuthenticationType {\n FINGERPRINT = 1,\n FACIAL_RECOGNITION = 2,\n}\n\nexport type LocalAuthenticationOptions = {\n promptMessage?: string;\n cancelLabel?: string;\n disableDeviceFallback?: boolean;\n // iOS only\n fallbackLabel?: string;\n};\n"]} \ No newline at end of file +{"version":3,"file":"LocalAuthentication.types.js","sourceRoot":"","sources":["../src/LocalAuthentication.types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,yEAAe,CAAA;IACf,uFAAsB,CAAA;IACtB,eAAe;IACf,2DAAQ,CAAA;AACV,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B","sourcesContent":["export type LocalAuthenticationResult = { success: true } | { success: false; error: string };\n\nexport enum AuthenticationType {\n FINGERPRINT = 1,\n FACIAL_RECOGNITION = 2,\n // Android only\n IRIS = 3,\n}\n\nexport type LocalAuthenticationOptions = {\n promptMessage?: string;\n cancelLabel?: string;\n disableDeviceFallback?: boolean;\n // iOS only\n fallbackLabel?: string;\n};\n"]} \ No newline at end of file diff --git a/packages/expo-local-authentication/src/LocalAuthentication.types.ts b/packages/expo-local-authentication/src/LocalAuthentication.types.ts index 52af52e131132..c480caffdf02c 100644 --- a/packages/expo-local-authentication/src/LocalAuthentication.types.ts +++ b/packages/expo-local-authentication/src/LocalAuthentication.types.ts @@ -3,6 +3,8 @@ export type LocalAuthenticationResult = { success: true } | { success: false; er export enum AuthenticationType { FINGERPRINT = 1, FACIAL_RECOGNITION = 2, + // Android only + IRIS = 3, } export type LocalAuthenticationOptions = {