コード例 #1
0
    private BiometricPrompt.AuthenticationCallback GetBiometricAuthenticationCallback(Func <Task> action)
    {
        var callback = new BiometricAuthenticationCallback
        {
            Success = (result) =>
            {
                Toast.MakeText(_context, "Authentication succeeded.", ToastLength.Short).Show();
                action();
            },
            Failed = () =>
            {
            },
            Error = (errorCode, errString) =>
            {
            },
        };

        return(callback);
    }
コード例 #2
0
        private void ShowBiometicPrompt(IBioAuthCompleted bioAuthCompleted)
        {
            var activity = (FragmentActivity)CrossCurrentActivity.Current.Activity;
            var executor = ContextCompat.GetMainExecutor(activity);

            var callback = new BiometricAuthenticationCallback
            {
                Success = (AndroidX.Biometric.BiometricPrompt.AuthenticationResult result) => {
                    try
                    {
                        bioAuthCompleted.OnCompleted(BioAuthStatus.SUCCESS);
                    }
                    catch (SignatureException)
                    {
                        throw new RuntimeException();
                    }
                },
                Failed = () => {
                    // TODO: Show error.
                    bioAuthCompleted.OnCompleted(BioAuthStatus.FAILED);
                },
                Help = (BiometricAcquiredStatus helpCode, ICharSequence helpString) => {
                    // TODO: What do we do here?
                }
            };

            //Create prompt info
            var promptInfo = new AndroidX.Biometric.BiometricPrompt.PromptInfo.Builder()
                             .SetTitle("Biometric login for my app")
                             .SetSubtitle("Log in using your biometric credential")
                             .SetNegativeButtonText("Use account password")
                             .Build();

            //Create prompt
            var biometricPrompt = new AndroidX.Biometric.BiometricPrompt(activity, executor, callback);

            //call Authenticate
            biometricPrompt.Authenticate(promptInfo);
        }
コード例 #3
0
        private BiometricPrompt.AuthenticationCallback GetAuthenticationCallback()
        {
            // Callback for biometric authentication result
            var callback = new BiometricAuthenticationCallback
            {
                Success = (BiometricPrompt.AuthenticationResult result) => {
                    var signature = result.CryptoObject.Signature;
                    try
                    {
                        signature.Update(Encoding.ASCII.GetBytes(signatureMessage));
                        var signatureString = Base64.EncodeToString(signature.Sign(), Base64Flags.UrlSafe);
                        // Normally, ToBeSignedMessage and Signature are sent to the server and then verified
                        //  Toast.MakeText (getApplicationContext (), signatureMessage + ":" + signatureString, Toast.LENGTH_SHORT).show ();
                        MessagingCenter.Send <object>("BiometricPrompt", "Success");
                    }
                    catch (SignatureException)
                    {
                        throw new RuntimeException();
                    }
                },
                Failed = () => {
                    MessagingCenter.Send <object>("BiometricPrompt", "Fail");
                    //  Show error.
                },
                Help = (BiometricAcquiredStatus helpCode, ICharSequence helpString) => {
                    //below BiometricAcquiredStatus falls here
                    //BiometricAcquiredStatus.ImagerDirty;
                    //BiometricAcquiredStatus.Insufficient;
                    //BiometricAcquiredStatus.Partial;
                    //BiometricAcquiredStatus.TooFast;
                    //BiometricAcquiredStatus.TooSlow;//
                }
            };

            return(callback);
        }