From df4b086f8b740aab6e3c980d97345b8b16d98e85 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Tue, 19 May 2020 18:06:13 +0200 Subject: [PATCH 1/3] [local-authentication] add vague biometric type for Android --- .../versions/unversioned/sdk/local-authentication.md | 8 +++++++- .../localauthentication/LocalAuthenticationModule.java | 4 ++-- .../build/LocalAuthentication.types.d.ts | 1 + .../build/LocalAuthentication.types.js | 2 ++ .../build/LocalAuthentication.types.js.map | 2 +- .../ios/EXLocalAuthentication/EXLocalAuthentication.m | 4 ++++ .../src/LocalAuthentication.types.ts | 2 ++ 7 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/pages/versions/unversioned/sdk/local-authentication.md b/docs/pages/versions/unversioned/sdk/local-authentication.md index e8825bb6e2609..1b6d3dd31c84c 100644 --- a/docs/pages/versions/unversioned/sdk/local-authentication.md +++ b/docs/pages/versions/unversioned/sdk/local-authentication.md @@ -39,7 +39,13 @@ Determine what kinds of authentications are available on the device. #### Returns -Returns a promise resolving to an array containing `LocalAuthentication.AuthenticationType.{FINGERPRINT, FACIAL_RECOGNITION}`. A value of `1` indicates Fingerprint support and `2` indicates Facial Recognition support. Eg: `[1,2]` means the device has both types supported. If neither authentication type is supported, returns an empty array. +Returns a promise resolving to an array containing any of the types below. If neither authentication type is supported, returns an empty array. + +- `LocalAuthentication.AuthenticationType.BIOMETRIC` indicates either Fingerprint or Facial Recognition support +- `LocalAuthentication.AuthenticationType.FINGERPRINT` indicates Fingerprint support **iOS only** +- `LocalAuthentication.AuthenticationType.FACIAL_RECOGNITION` indicates Facial Recognition support **iOS only** + +> **Note:** On Android, this only returns the `BIOMETRIC` type if fingerprint or facial recognition is available. The new [BiometricPrompt](https://developer.android.com/training/sign-in/biometric-auth) doesn't allow selecting a specific method of biometric authentication. ### `LocalAuthentication.isEnrolledAsync()` 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..706c0483f83c3 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 @@ -34,7 +34,7 @@ public class LocalAuthenticationModule extends ExportedModule { private ModuleRegistry mModuleRegistry; private UIManager mUIManager; - private static final int AUTHENTICATION_TYPE_FINGERPRINT = 1; + private static final int AUTHENTICATION_TYPE_BIOMETRIC = 3; private final BiometricPrompt.AuthenticationCallback mAuthenticationCallback = new BiometricPrompt.AuthenticationCallback () { @@ -79,7 +79,7 @@ public void supportedAuthenticationTypesAsync(final Promise promise) { int result = mBiometricManager.canAuthenticate(); List results = new ArrayList<>(); if (result != BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE) { - results.add(AUTHENTICATION_TYPE_FINGERPRINT); + results.add(AUTHENTICATION_TYPE_BIOMETRIC); } 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..e56370b2e2b7f 100644 --- a/packages/expo-local-authentication/build/LocalAuthentication.types.d.ts +++ b/packages/expo-local-authentication/build/LocalAuthentication.types.d.ts @@ -5,6 +5,7 @@ export declare type LocalAuthenticationResult = { error: string; }; export declare enum AuthenticationType { + BIOMETRIC = 3, FINGERPRINT = 1, FACIAL_RECOGNITION = 2 } diff --git a/packages/expo-local-authentication/build/LocalAuthentication.types.js b/packages/expo-local-authentication/build/LocalAuthentication.types.js index b9985553a2623..e3c1b24cdda32 100644 --- a/packages/expo-local-authentication/build/LocalAuthentication.types.js +++ b/packages/expo-local-authentication/build/LocalAuthentication.types.js @@ -1,5 +1,7 @@ export var AuthenticationType; (function (AuthenticationType) { + AuthenticationType[AuthenticationType["BIOMETRIC"] = 3] = "BIOMETRIC"; + // iOS only AuthenticationType[AuthenticationType["FINGERPRINT"] = 1] = "FINGERPRINT"; AuthenticationType[AuthenticationType["FACIAL_RECOGNITION"] = 2] = "FACIAL_RECOGNITION"; })(AuthenticationType || (AuthenticationType = {})); diff --git a/packages/expo-local-authentication/build/LocalAuthentication.types.js.map b/packages/expo-local-authentication/build/LocalAuthentication.types.js.map index e413ea04f6399..1e597e283e63a 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,qEAAa,CAAA;IACb,WAAW;IACX,yEAAe,CAAA;IACf,uFAAsB,CAAA;AACxB,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B","sourcesContent":["export type LocalAuthenticationResult = { success: true } | { success: false; error: string };\n\nexport enum AuthenticationType {\n BIOMETRIC = 3,\n // iOS only\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 diff --git a/packages/expo-local-authentication/ios/EXLocalAuthentication/EXLocalAuthentication.m b/packages/expo-local-authentication/ios/EXLocalAuthentication/EXLocalAuthentication.m index 1f129b3a50333..79a42d48a83fe 100644 --- a/packages/expo-local-authentication/ios/EXLocalAuthentication/EXLocalAuthentication.m +++ b/packages/expo-local-authentication/ios/EXLocalAuthentication/EXLocalAuthentication.m @@ -9,6 +9,7 @@ typedef NS_ENUM(NSInteger, EXAuthenticationType) { EXAuthenticationTypeFingerprint = 1, EXAuthenticationTypeFacialRecognition = 2, + EXAuthenticationTypeBiometric = 3, }; @implementation EXLocalAuthentication @@ -26,6 +27,9 @@ @implementation EXLocalAuthentication if ([[self class] isFaceIdDevice]) { [results addObject:@(EXAuthenticationTypeFacialRecognition)]; } + if ([[self class] isTouchIdDevice] || [[self class] isFaceIdDevice]) { + [results addObject:@(EXAuthenticationTypeBiometric)]; + } resolve(results); } diff --git a/packages/expo-local-authentication/src/LocalAuthentication.types.ts b/packages/expo-local-authentication/src/LocalAuthentication.types.ts index 52af52e131132..a54f355836ef6 100644 --- a/packages/expo-local-authentication/src/LocalAuthentication.types.ts +++ b/packages/expo-local-authentication/src/LocalAuthentication.types.ts @@ -1,6 +1,8 @@ export type LocalAuthenticationResult = { success: true } | { success: false; error: string }; export enum AuthenticationType { + BIOMETRIC = 3, + // iOS only FINGERPRINT = 1, FACIAL_RECOGNITION = 2, } From 3ce314942561bd435aa7722cf4dd0c0a1a3eebfe Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Tue, 19 May 2020 18:09:09 +0200 Subject: [PATCH 2/3] [docs][local-authentication] update docs with biometric prompt references and options --- .../versions/unversioned/sdk/local-authentication.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/pages/versions/unversioned/sdk/local-authentication.md b/docs/pages/versions/unversioned/sdk/local-authentication.md index 1b6d3dd31c84c..59af655400b1b 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. @@ -64,10 +64,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, FaceID or Biometric 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 From 505fbd13e415580fdbaa9d38bfdfde2d73080b7c Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Wed, 20 May 2020 11:04:29 +0200 Subject: [PATCH 3/3] [local-authentication] add changelog entry for breaking type change --- packages/expo-local-authentication/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/expo-local-authentication/CHANGELOG.md b/packages/expo-local-authentication/CHANGELOG.md index 98989f9974ac7..16f3236bafff5 100644 --- a/packages/expo-local-authentication/CHANGELOG.md +++ b/packages/expo-local-authentication/CHANGELOG.md @@ -4,6 +4,8 @@ ### 🛠 Breaking changes +- Added new biometric type to local authentication for Android BiometricPrompt. ([#8364](https://github.com/expo/expo/pull/8364) by [@byCedric](https://github.com/byCedric)) + ### 🎉 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))