Skip to content

Commit

Permalink
[local-authentication] added supported authentication type estimate w…
Browse files Browse the repository at this point in the history
…ith package manager (#8431)

# Why

See #8364

# How

See #8364

# Test Plan

See #7838 or https://snack.expo.io/@ouihealth/a78fc1
  • Loading branch information
byCedric committed May 22, 2020
1 parent bd2e6ff commit 34808ad
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
8 changes: 4 additions & 4 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 @@ -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

Expand Down
3 changes: 3 additions & 0 deletions packages/expo-local-authentication/CHANGELOG.md
Expand Up @@ -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))
Expand Up @@ -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;
Expand All @@ -28,13 +29,16 @@

public class LocalAuthenticationModule extends ExportedModule {
private final BiometricManager mBiometricManager;
private final PackageManager mPackageManager;
private CancellationSignal mCancellationSignal;
private Promise mPromise;
private boolean mIsAuthenticating = false;
private ModuleRegistry mModuleRegistry;
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 () {
Expand All @@ -61,6 +65,7 @@ public LocalAuthenticationModule(Context context) {
super(context);

mBiometricManager = BiometricManager.from(context);
mPackageManager = context.getPackageManager();
}

@Override
Expand All @@ -78,9 +83,19 @@ public void onCreate(ModuleRegistry moduleRegistry) {
public void supportedAuthenticationTypesAsync(final Promise promise) {
int result = mBiometricManager.canAuthenticate();
List<Integer> 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);
}

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 @@ -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 = {
Expand Down

0 comments on commit 34808ad

Please sign in to comment.