Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[local-authentication] add new biometric type for android biometric prompt #8364

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions docs/pages/versions/unversioned/sdk/local-authentication.md
Expand Up @@ -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.

<PlatformsSection android emulator ios simulator web={{ pending: 'https://github.com/expo/expo/issues/4045' }} />

Expand Down Expand Up @@ -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()`

Expand All @@ -58,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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the iOS only tags here because this is also implemented in Android now (via #8219)

- **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

Expand Down
Expand Up @@ -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 () {
Expand Down Expand Up @@ -79,7 +79,7 @@ public void supportedAuthenticationTypesAsync(final Promise promise) {
int result = mBiometricManager.canAuthenticate();
List<Integer> results = new ArrayList<>();
if (result != BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE) {
results.add(AUTHENTICATION_TYPE_FINGERPRINT);
results.add(AUTHENTICATION_TYPE_BIOMETRIC);
}
promise.resolve(results);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -9,6 +9,7 @@
typedef NS_ENUM(NSInteger, EXAuthenticationType) {
EXAuthenticationTypeFingerprint = 1,
EXAuthenticationTypeFacialRecognition = 2,
EXAuthenticationTypeBiometric = 3,
};

@implementation EXLocalAuthentication
Expand All @@ -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);
}

Expand Down
@@ -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,
}
Expand Down