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] added supported authentication type estimate with package manager #8431

Merged
merged 6 commits into from May 22, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
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
2 changes: 2 additions & 0 deletions packages/expo-local-authentication/CHANGELOG.md
Expand Up @@ -9,3 +9,5 @@
- Added support for `promptMessage`, `cancelLabel` and `disableDeviceFallback` on Android. ([#8219](https://github.com/expo/expo/pull/8219) by [@diegolmello](https://github.com/diegolmello))

### 🐛 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,15 @@

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 final BiometricPrompt.AuthenticationCallback mAuthenticationCallback =
new BiometricPrompt.AuthenticationCallback () {
Expand All @@ -61,6 +64,7 @@ public LocalAuthenticationModule(Context context) {
super(context);

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

@Override
Expand All @@ -78,9 +82,16 @@ 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);
}
promise.resolve(results);
}

Expand Down