Jump to content
stacker_liew

Any Demo On How To Use TBiometricAuth In Delphi

Recommended Posts

4 minutes ago, stacker_liew said:

I created a demo app, but it won't work.

You do not have the Biometric Authorization Service option checked in the Entitlement List in Project Options

Share this post


Link to post
1 minute ago, Dave Nottage said:

You do not have the Biometric Authorization Service option checked in the Entitlement List in Project Options

OK, thanks.

Share this post


Link to post
1 minute ago, stacker_liew said:

still won't work.

You'll need to me more specific about what "won't work" means. Please also note that only Android 10 or higher is supported

Share this post


Link to post
1 minute ago, Dave Nottage said:

You'll need to me more specific about what "won't work" means. Please also note that only Android 10 or higher is supported

It should display the request permission dialog, but it won't. I'm using Android 12.

Edited by stacker_liew

Share this post


Link to post
1 minute ago, stacker_liew said:

It should display the request permission dialog

No error messages? Can you provide a reproducible example that does not have dependencies on TFrameStand or other 3rd party code?

Share this post


Link to post
1 minute ago, Dave Nottage said:

No error messages? Can you provide a reproducible example that does not have dependencies on TFrameStand or other 3rd party code?

Wait...I create another one which without third party component.

Share this post


Link to post

@stacker_liew

 

you need this to "work":  tested in Android 11 (API 30)... (using default targetSdkVersion = 32 by Delphi)

Quote
  1.   Needs 2 permissions involved:
    1. USE_BIOMETRIC = new IDEs
    2. USE_FINGERPRINT = if older (deprecated in new IDEs)
  2.   Project->Options:
    1. Entitlement List -> Biometric Authorization Service
    2. Permissions:
      1. Use Biometric   (new IDE)
      2. Use Fingerprint (older IDE)
  3.   TBiometricAuth component: mandatory choices:
    1. BiometricAuth1.PromptDescription
    2. BiometricAuth1.PromptTitle
    3. BiometricAuth1.BiometricStrengths
  4. Request/Rationale events from request permissions!
  5. Biometric events if: success or failed!
PermissionBiometric: TArray<string>;
//...
OnCreate Form:
--------------
PermissionBiometric := ['android.permission.USE_BIOMETRIC']; // , 'android.permission.USE_FINGERPRINT'];  // NOT mandatory == FIXED!
BiometricAuth1.PromptDescription := 'my description'; // mandatory
BiometricAuth1.PromptTitle       := 'my title'; // mandatory
BiometricAuth1.BiometricStrengths := [ TBiometricStrength.DeviceCredential  { ,  others... }]; // mandatory
//...
procedure TForm1.BiometricPermissionRequestResult(Sender: TObject; const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray);
begin
  // 2 permissions involved: USE_BIOMETRIC + USE_FINGERPRINT
  if (Length(AGrantResults) = 1 {2}) and (AGrantResults[0] = TPermissionStatus.Granted) then // and (AGrantResults[1] = TPermissionStatus.Granted) then
    BiometricAuth1.Authenticate;
  //...
end;
//...
procedure TForm1.Button1Click(Sender: TObject);
begin
  PermissionsService.RequestPermissions( { }
    PermissionBiometric,                 { }
    BiometricPermissionRequestResult,    { }
    DisplayRationale);
end;
// ...
procedure TForm1.BiometricAuth1AuthenticateFail(Sender: TObject; const FailReason: TBiometricFailReason; const ResultMessage: string);
begin
  TDialogService.ShowMessage('Failed!');
end;

procedure TForm1.BiometricAuth1AuthenticateSuccess(Sender: TObject);
begin
  TDialogService.ShowMessage('Successed!');
end;

 

Edited by programmerdelphi2k

Share this post


Link to post
2 hours ago, programmerdelphi2k said:

@stacker_liew

 

you need this to "work":  tested in Android 11 (API 30)... (using default targetSdkVersion = 32 by Delphi)


PermissionBiometric: TArray<string>;
//...
OnCreate Form:
--------------
PermissionBiometric := ['android.permission.USE_BIOMETRIC']; // , 'android.permission.USE_FINGERPRINT'];  // mandatory
BiometricAuth1.PromptDescription := 'my description'; // mandatory
BiometricAuth1.PromptTitle       := 'my title'; // mandatory
BiometricAuth1.BiometricStrengths := [ TBiometricStrength.DeviceCredential  { ,  others... }]; // mandatory
//...
procedure TForm1.BiometricPermissionRequestResult(Sender: TObject; const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray);
begin
  // 2 permissions involved: USE_BIOMETRIC + USE_FINGERPRINT
  if (Length(AGrantResults) = 1 {2}) and (AGrantResults[0] = TPermissionStatus.Granted) then // and (AGrantResults[1] = TPermissionStatus.Granted) then
    BiometricAuth1.Authenticate;
  //...
end;
//...
procedure TForm1.Button1Click(Sender: TObject);
begin
  PermissionsService.RequestPermissions( { }
    PermissionBiometric,                 { }
    BiometricPermissionRequestResult,    { }
    DisplayRationale);
end;
// ...
procedure TForm1.BiometricAuth1AuthenticateFail(Sender: TObject; const FailReason: TBiometricFailReason; const ResultMessage: string);
begin
  TDialogService.ShowMessage('Failed!');
end;

procedure TForm1.BiometricAuth1AuthenticateSuccess(Sender: TObject);
begin
  TDialogService.ShowMessage('Successed!');
end;

 

I followed your instruction, still won't work. Here is the source.

 

Edited by stacker_liew
Upgrade new file

Share this post


Link to post
3 hours ago, programmerdelphi2k said:

you need this to "work"

Incorrect. USE_BIOMETRIC needs to be included in the permissions, but only dangerous permissions need to be explicitly requested at runtime.

7 hours ago, stacker_liew said:

This is the new one without third party components.

You're also missing the Use Biometric permission in the Permissions section of Project Options. Sorry, I should have checked for that earlier.

  • Thanks 1

Share this post


Link to post
7 minutes ago, stacker_liew said:

, it skip the Request Permission section.

better read more about it  https://developer.android.com/training/sign-in/biometric-auth

 

Quote

Declare the types of authentication that your app supports

To define the types of authentication that your app supports, use the BiometricManager.Authenticators interface. The system lets you declare the following types of authentication:

BIOMETRIC_STRONG

Authentication using a Class 3 biometric, as defined on the Android compatibility definition page.

BIOMETRIC_WEAK

Authentication using a Class 2 biometric, as defined on the Android compatibility definition page.

DEVICE_CREDENTIAL

Authentication using a screen lock credential – the user's PIN, pattern, or password.

To begin using an authenticator, the user needs to create a PIN, pattern, or password. If the user doesn't already have one, the biometric enrollment flow prompts them to create one.

To define the types of biometric authentication that your app accepts, pass an authentication type or a bitwise combination of types into the setAllowedAuthenticators() method. The following code snippet shows how to support authentication using either a Class 3 biometric or a screen lock credential.

 

Edited by programmerdelphi2k

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×