sjhoeksma / cordova-plugin-keychain-touch-id

Touch ID plugin with saving password in keychain for IOS and android
87 stars 160 forks source link

isAvailable() doesn't return biometryType #39

Open kristof01 opened 6 years ago

kristof01 commented 6 years ago

The success callback of isAvailable() returns null instead of the biometryType. Is it possible that this functionality is currently broken? I'm working with version 3.2.1 in IONIC 3.

SleimanB commented 6 years ago

Yes, I'm facing the same issue isAvailable() returns null of the biometryType.

dylan-westbury commented 6 years ago

Same here, even when I try with promises or observables.

isAvailable() and save() both return null.

jurgen-reconcept commented 6 years ago

You can see in the source that this functionality is only implemented in later version (3.3.0), but this is not installed by default. Npm installs 3.2.1. The readme has instructions for installing the latest straight from repository.

kristof01 commented 6 years ago

@sjhoeksma Can you make a new release including this functionality? I would be very grateful.

dmason30 commented 6 years ago

@sjhoeksma +1, forking for now I guess 😞

gopi014 commented 5 years ago

any updates on this ? I am also getting null in the iOS

SleimanB commented 5 years ago

Hey @gopi014 override isAvailable function in TouchID.m with this one

- (void) isAvailable:(CDVInvokedUrlCommand*)command {

  LAContext *context = [[LAContext alloc] init];

  if (NSClassFromString(@"LAContext") == NULL) {
      [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR] callbackId:command.callbackId];
      return;
  }

  [self.commandDelegate runInBackground:^{
      NSError *error = nil;
      LAContext *laContext = [[LAContext alloc] init];
      if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
          NSString *biometryType = @"touch";
          if (@available(iOS 11.0, *)) {
              if (laContext.biometryType == LABiometryTypeFaceID) {
                  biometryType = @"face";
              }
          }
          [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:biometryType]
                                      callbackId:command.callbackId];
      } else {
          NSArray *errorKeys = @[@"code", @"localizedDescription"];
          [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[error dictionaryWithValuesForKeys:errorKeys]]
                                      callbackId:command.callbackId];
      }
  }];
}
gopi014 commented 5 years ago

Thanks for your reply. It is working fine now.

ghost commented 5 years ago

Any news on this one? Still getting null with the official release.

punixxher commented 4 years ago

Hey @gopi014 override isAvailable function in TouchID.m with this one

- (void) isAvailable:(CDVInvokedUrlCommand*)command {

  LAContext *context = [[LAContext alloc] init];

  if (NSClassFromString(@"LAContext") == NULL) {
      [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR] callbackId:command.callbackId];
      return;
  }

  [self.commandDelegate runInBackground:^{
      NSError *error = nil;
      LAContext *laContext = [[LAContext alloc] init];
      if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
          NSString *biometryType = @"touch";
          if (@available(iOS 11.0, *)) {
              if (laContext.biometryType == LABiometryTypeFaceID) {
                  biometryType = @"face";
              }
          }
          [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:biometryType]
                                      callbackId:command.callbackId];
      } else {
          NSArray *errorKeys = @[@"code", @"localizedDescription"];
          [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[error dictionaryWithValuesForKeys:errorKeys]]
                                      callbackId:command.callbackId];
      }
  }];
}

Work for me. Thanks

qliqdev commented 3 years ago

@sjhoeksma please include this code to your repo 🙏! don't wan't to fork.

Hey @gopi014 override isAvailable function in TouchID.m with this one

- (void) isAvailable:(CDVInvokedUrlCommand*)command {

  LAContext *context = [[LAContext alloc] init];

  if (NSClassFromString(@"LAContext") == NULL) {
      [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR] callbackId:command.callbackId];
      return;
  }

  [self.commandDelegate runInBackground:^{
      NSError *error = nil;
      LAContext *laContext = [[LAContext alloc] init];
      if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
          NSString *biometryType = @"touch";
          if (@available(iOS 11.0, *)) {
              if (laContext.biometryType == LABiometryTypeFaceID) {
                  biometryType = @"face";
              }
          }
          [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:biometryType]
                                      callbackId:command.callbackId];
      } else {
          NSArray *errorKeys = @[@"code", @"localizedDescription"];
          [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[error dictionaryWithValuesForKeys:errorKeys]]
                                      callbackId:command.callbackId];
      }
  }];
}
qliqdev commented 3 years ago

Hey @gopi014 override isAvailable function in TouchID.m with this one

- (void) isAvailable:(CDVInvokedUrlCommand*)command {

  LAContext *context = [[LAContext alloc] init];

  if (NSClassFromString(@"LAContext") == NULL) {
      [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR] callbackId:command.callbackId];
      return;
  }

  [self.commandDelegate runInBackground:^{
      NSError *error = nil;
      LAContext *laContext = [[LAContext alloc] init];
      if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
          NSString *biometryType = @"touch";
          if (@available(iOS 11.0, *)) {
              if (laContext.biometryType == LABiometryTypeFaceID) {
                  biometryType = @"face";
              }
          }
          [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:biometryType]
                                      callbackId:command.callbackId];
      } else {
          NSArray *errorKeys = @[@"code", @"localizedDescription"];
          [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:[error dictionaryWithValuesForKeys:errorKeys]]
                                      callbackId:command.callbackId];
      }
  }];
}

How about android? Does it returns biometry type on android? or we should add some code also?