public FingerprintDialog(DialogConfiguration dialogConfiguration, FingerprintManagerCompat.AuthenticationCallback authenticationCallBack, Android.Support.V4.OS.CancellationSignal fingerprintCancellationSignal)
 {
     _dialogConfiguration           = dialogConfiguration;
     _authenticationCallBack        = authenticationCallBack;
     _fingerprintCancellationSignal = fingerprintCancellationSignal;
     ((AuthenticationCallBack)_authenticationCallBack).SetFingerprintDialog(this);
 }
Esempio n. 2
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            var dialogConfig = new Plugin.XF.TouchID.DialogConfiguration(dialogTitle: "Sign In",                           //Display in Android only
                                                                         dialogDescritpion: "Detect you biometic to auth", //Display on Android and iOS(TouchID)
                                                                         successAction: () =>
            {
                //Will fired when authentication success
                Device.BeginInvokeOnMainThread(() =>
                {
                    DisplayAlert("Congratulation", "You pass the authentication", "OK");
                });
            },
                                                                         alterAuthButtonText: "Use PIN", //Display in Android only
                                                                         fingerprintDialogConfiguration: new Plugin.XF.TouchID.FingerprintDialogConfiguration
            {
                //For Android 6-8 only
                FingerprintHintString          = "Touch Sensor",
                FingerprintNotRecoginzedString = "Not regonized"
            },
                                                                         failedAction: () =>
            {
                //For Android 6-8 only
                Device.BeginInvokeOnMainThread(() =>
                {
                    DisplayAlert("Alert", "Too many unsuccessful attempt, please try again later", "OK");
                });
            });

            await Plugin.XF.TouchID.TouchID.Authenticate(dialogConfig);
        }
Esempio n. 3
0
        public static async System.Threading.Tasks.Task Authenticate(DialogConfiguration dialogConfiguration)
        {
            _context = new LAContext();
            _context.InvokeOnMainThread(async() =>
            {
                var result    = await _context.EvaluatePolicyAsync(LAPolicy.DeviceOwnerAuthentication, Configuration.DefaultFailAttemptNumberExceededMsg);
                bool success  = result.Item1;
                NSError error = result.Item2;
                if (success)
                {
                    dialogConfiguration.SuccessAction?.Invoke();
                }
                else
                {
                    if (error.Code == -2)
                    {
                        //user cancel
                        return;
                    }
                    else if (error.Code == -1)
                    {
                        //too many failed attempt
                        dialogConfiguration.FailedAction?.Invoke();
                    }
                }
            });
            //NSError AuthError;

            //if (_context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError))
            //{
            //    Tuple<bool, NSError> result = await _context.EvaluatePolicyAsync(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, dialogConfiguration.DialogDescription);
            //    bool success = result.Item1;
            //    NSError error = result.Item2;
            //    if (result.Item1 == true)
            //        dialogConfiguration.SuccessAction?.Invoke();
            //    else
            //    {
            //        if (error.Code == -2)
            //        {
            //            //User cancel
            //            return;
            //        }else if(error.Code == -1)
            //        {

            //        }

            //        //if (error.LocalizedDescription == "Fallback authentication mechanism selected.")
            //        //{
            //        //    var s = error.Code;
            //        //    result = await _context.EvaluatePolicyAsync(LAPolicy.DeviceOwnerAuthentication, descrptionMessage);
            //        //    if (result.Item1)
            //        //        successAction?.Invoke();
            //        //}
            //    }
            //}
            //else
            //{

            //    _context.InvokeOnMainThread(async () =>
            //    {
            //        var result = await _context.EvaluatePolicyAsync(LAPolicy.DeviceOwnerAuthentication, Configuration.DefaultFailAttemptNumberExceededMsg);
            //        if (result.Item1)
            //            dialogConfiguration.SuccessAction?.Invoke();
            //    });


            //}
        }
Esempio n. 4
0
        public static async System.Threading.Tasks.Task Authenticate(DialogConfiguration dialogConfiguration)
        {
            //Android 10+ Q SdkInt 29+
            if ((int)Build.VERSION.SdkInt >= 29)
            {
                CancellationSignal BiometricCancellationSignal = new CancellationSignal();
                //Android 10
                BiometricCancellationSignal = new CancellationSignal();
                BiometricPrompt biometricPrompt;
                if (dialogConfiguration.IsUseAlternativeAuthentication)
                {
                    //Allow using PIN / Passcode as alternative, will disable crypto in authentication
                    biometricPrompt = new BiometricPrompt
                                      .Builder(Configuration.CurrentActivity)
                                      .SetTitle(dialogConfiguration.DialogTitle)
                                      .SetDescription(dialogConfiguration.DialogDescription)
                                      .SetDeviceCredentialAllowed(true)
                                      .Build();
                }
                else
                {
                    biometricPrompt = new BiometricPrompt
                                      .Builder(Configuration.CurrentActivity)
                                      .SetTitle(dialogConfiguration.DialogTitle)
                                      .SetDescription(dialogConfiguration.DialogDescription)
                                      .SetNegativeButton(dialogConfiguration.AlternativeActionMessage, Configuration.CurrentActivity.MainExecutor, new NegativeButtonOnClickListener(() =>
                    {
                        BiometricCancellationSignal.Cancel();
                        dialogConfiguration.AlternativeAction?.Invoke();
                    }))
                                      .Build();
                }
                BiometricPrompt.AuthenticationCallback authenticationCallback = new BiometricAuthenticationCallback();
                AuthenticationResult = null;
                AuthenticationResult = (arg) =>
                {
                    string result = arg;
                    if (arg == SystemMessages.Success)
                    {
                        BiometricCancellationSignal.Cancel();
                        dialogConfiguration.SuccessAction?.Invoke();
                    }
                    else if (arg == SystemMessages.Error)
                    {
                        BiometricCancellationSignal.Cancel();
                        dialogConfiguration.FailedAction?.Invoke();
                    }
                };
                if (dialogConfiguration.IsUseAlternativeAuthentication)
                {
                    //Secret key is not allowed to use when SetDeviceCredentialAllowed is true
                    biometricPrompt.Authenticate(BiometricCancellationSignal, Configuration.CurrentActivity.MainExecutor, authenticationCallback);
                }
                else
                {
                    if (Configuration.IsUseSecretKey)
                    {
                        CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();
                        biometricPrompt.Authenticate(cryptoHelper.BuildBiometricPromptCryptoObject(), BiometricCancellationSignal, Configuration.CurrentActivity.MainExecutor, authenticationCallback);
                    }
                    else
                    {
                        biometricPrompt.Authenticate(BiometricCancellationSignal, Configuration.CurrentActivity.MainExecutor, authenticationCallback);
                    }
                }
            }
            //Android 9+ P SdkInt 28
            else if ((int)Build.VERSION.SdkInt >= 28)
            {
                //Android 9
                try
                {
                    CancellationSignal BiometricCancellationSignal = new CancellationSignal();
                    BiometricPrompt    biometricPrompt;
                    biometricPrompt = new BiometricPrompt
                                      .Builder(Configuration.CurrentActivity)
                                      .SetTitle(dialogConfiguration.DialogTitle)
                                      .SetDescription(dialogConfiguration.DialogDescription)
                                      .SetNegativeButton(dialogConfiguration.AlternativeActionMessage, Configuration.CurrentActivity.MainExecutor, new NegativeButtonOnClickListener(() =>
                    {
                        BiometricCancellationSignal.Cancel();
                        dialogConfiguration.AlternativeAction?.Invoke();
                    }))
                                      .Build();

                    BiometricCancellationSignal = new CancellationSignal();

                    BiometricPrompt.AuthenticationCallback authenticationCallback = new BiometricAuthenticationCallback();
                    AuthenticationResult = null;
                    AuthenticationResult = (arg) =>
                    {
                        string result = arg;
                        if (arg == SystemMessages.Success)
                        {
                            BiometricCancellationSignal.Cancel();
                            dialogConfiguration.SuccessAction?.Invoke();
                        }
                        else if (arg == SystemMessages.Error)
                        {
                            BiometricCancellationSignal.Cancel();
                            dialogConfiguration.FailedAction?.Invoke();
                        }
                    };
                    if (Configuration.IsUseSecretKey)
                    {
                        CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();
                        biometricPrompt.Authenticate(cryptoHelper.BuildBiometricPromptCryptoObject(), BiometricCancellationSignal, Configuration.CurrentActivity.MainExecutor, authenticationCallback);
                    }
                    else
                    {
                        biometricPrompt.Authenticate(BiometricCancellationSignal, Configuration.CurrentActivity.MainExecutor, authenticationCallback);
                    }
                }
                catch (Exception ex)
                {
                    Configuration.CurrentActivity.RunOnUiThread(() =>
                    {
                        Toast.MakeText(Configuration.CurrentActivity, $"Throw exception : {ex.Message}", ToastLength.Long).Show();
                    });
                }
            }
            //Android 6+ to 8.x SdkInt 23
            else if ((int)Build.VERSION.SdkInt >= 23)
            {
                //Android 6+ to 8.x
                FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat.From(Configuration.CurrentActivity);
                const int          flags        = 0; /* always zero (0) */
                CryptoObjectHelper cryptoHelper = new CryptoObjectHelper();
                // Using the Support Library classes for maximum reach
                FingerprintManagerCompat fingerPrintManager = FingerprintManagerCompat.From(Configuration.CurrentActivity);
                // AuthCallbacks is a C# class defined elsewhere in code.

                Android.Support.V4.OS.CancellationSignal        FingerprintCancellationSignal = new Android.Support.V4.OS.CancellationSignal();
                FingerprintManagerCompat.AuthenticationCallback authenticationCallback        = new AuthenticationCallBack();

                Android.Support.V4.App.FragmentTransaction transcation = ((FragmentActivity)Configuration.CurrentActivity).SupportFragmentManager.BeginTransaction();
                FingerprintDialog fingerprintDialog = new FingerprintDialog(dialogConfiguration, authenticationCallback, FingerprintCancellationSignal);
                fingerprintDialog.Show(transcation, "Dialog Fragment");

                AuthenticationResult = null;
                AuthenticationResult = (arg) =>
                {
                    string result = arg;
                    if (arg == SystemMessages.Success)
                    {
                        FingerprintCancellationSignal.Cancel();
                        dialogConfiguration.SuccessAction?.Invoke();
                    }
                    else if (arg == SystemMessages.Error)
                    {
                        FingerprintCancellationSignal.Cancel();
                        dialogConfiguration.FailedAction?.Invoke();
                    }
                };
                try
                {
                    fingerprintManager.Authenticate(cryptoHelper.BuildFingerprintManagerCompatCryptoObject(), flags, FingerprintCancellationSignal, authenticationCallback, null);
                }
                catch (Exception ex)
                {
                    Toast.MakeText(Configuration.CurrentActivity, $"Throw exception : {ex.Message}", ToastLength.Long);
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Call for the authentication
 /// </summary>
 /// <param name="dialogConfiguration">Configuration of the dialog</param>
 public static async System.Threading.Tasks.Task Authenticate(DialogConfiguration dialogConfiguration)
 {
     throw new NotImplementedException();
 }