react-native-keychain icon indicating copy to clipboard operation
react-native-keychain copied to clipboard

Android: setGenericPassword and fallbacks

Open JeffreyLeeDave opened this issue 4 years ago • 1 comments

So I have been using this package and it works great. However, in regards to Android on biometrics failure, we don't see a screen to fallback to PIN/Pattern/Password. On iOS we do see the screen to fallback to PIN. Has anyone been able to get this working? Here is what I have:

useEffect(() => {
  async function testingLocalAuthentication() {
    const username = 'fakeUser';
    const password = 'fakePassword';

    const biometryType = await Keychain.getSupportedBiometryType();
    console.log('------------------biometryType: ', biometryType);

    // Store the credentials
    const setResult = await Keychain.setGenericPassword(username, password, {
      accessControl: Keychain.ACCESS_CONTROL.BIOMETRY_ANY_OR_DEVICE_PASSCODE,
      authenticationType: Keychain.AUTHENTICATION_TYPE.DEVICE_PASSCODE_OR_BIOMETRICS,
      accessible: Keychain.ACCESSIBLE.WHEN_PASSCODE_SET_THIS_DEVICE_ONLY,
      securityLevel: Keychain.SECURITY_LEVEL.SECURE_HARDWARE,
      storage: Keychain.STORAGE_TYPE.RSA,
      service: 'fakeService',
    });
    console.log('-------------------setResult', setResult);
    try {
      // Retrieve the credentials
      const credentials = await Keychain.getGenericPassword({
        accessControl: Keychain.ACCESS_CONTROL.BIOMETRY_ANY_OR_DEVICE_PASSCODE,
        authenticationType: Keychain.AUTHENTICATION_TYPE.DEVICE_PASSCODE_OR_BIOMETRICS,
        accessible: Keychain.ACCESSIBLE.WHEN_PASSCODE_SET_THIS_DEVICE_ONLY,
        securityLevel: Keychain.SECURITY_LEVEL.SECURE_HARDWARE,
        storage: Keychain.STORAGE_TYPE.RSA,
        service: 'fakeService',
      });
      console.log('---------------------credentials: ', credentials);
      if (credentials) {
        console.log('Credentials successfully loaded for user ', credentials.username);
      } else {
        console.log('No credentials stored');
      }
    } catch (error) {
      console.log("Keychain couldn't be accessed!", error);
    }
    await Keychain.resetGenericPassword();
  }
  testingLocalAuthentication();
});

JeffreyLeeDave avatar Aug 26 '20 20:08 JeffreyLeeDave