smstuebe / xamarin-fingerprint

Xamarin and MvvMCross plugin for authenticate a user via fingerprint sensor
Microsoft Public License
490 stars 115 forks source link

Continuous fingerprint scan #90

Closed Naografix closed 2 years ago

Naografix commented 6 years ago

Hello, Not really an issue, but I want to know how can I make a continuous scan with this plugin.

I made this code:

This method is called in my ctor.

private async void TryToConnectWithFinger()
{
    var result = await _fingerprintService.AuthenticateAsync("Connect with TouchID");

    switch (result.Status)
    {
        case FingerprintAuthenticationResultStatus.Succeeded:
            //
            break;
        case FingerprintAuthenticationResultStatus.NotAvailable:
            HaveFingerPrint = false;
            break;
        default:
            DependencyService.Get<IAlertService>().ShortAlert(AppResources.ConnectPage_Alert_FingerUnknown);
            break;
    }
}

This method appear in my FingerprintService

public async Task<FingerprintAuthenticationResult> AuthenticateAsync(string reason, CancellationToken cancellationToken = new CancellationToken())
{
    var isAvailable = await CrossFingerprint.Current.IsAvailableAsync(true);

    var result = new FingerprintAuthenticationResult();

    if (!isAvailable)
    {
        result.Status = FingerprintAuthenticationResultStatus.NotAvailable;
        return result;
    } 

    var dialogConfig = new AuthenticationRequestConfiguration(reason);

    if (Device.RuntimePlatform == Device.Android)
        dialogConfig.UseDialog = false;

    return await CrossFingerprint.Current.AuthenticateAsync(dialogConfig, cancellationToken); 
}

I want to make a continuous scan when my fingerprint is not valid.

Thank for your help

EDIT : With my Mate 8 Huawei and your sample, I can't reach the else of your "result.Authenticated" condition. I think my device block the fingerprint auth when it's not true.

smsissuechecker commented 6 years ago

Hi @Naografix,

I'm the friendly issue checker. It seems like (100.00 %) you haven't used our issue template :cry: I think it is very frustrating for the repository owners, if you ignore them.

If you think it's fine to make an exception, just ignore this message. But if you think it was a mistake to delete the template, please close the issue and create a new one.

Thanks!

smstuebe commented 6 years ago

Sorry I don't get it.

What is a "continuous scan"? Why would you do that?

Naografix commented 6 years ago

@smstuebe I want to be able to rescan my fingerprint when it is not valid. Like a continuous scan.

Because actually, when is not valid, I can't rescan.

Osmosis311 commented 5 years ago

One of my users just asked me for the same thing. Apparently on some apps in Android you don't need to click a button to then be "ready" to scan your fingerprint.

For example, if you have a login screen where the user can either enter their fingerprint or type in their password, if they touch the fingerprint sensor, it would ideally detect it and then go to the relevant code (like an event handler).

smstuebe commented 5 years ago

@Osmosis311 What prevents you from calling AuthenticateAsync without having to click a button?

Osmosis311 commented 5 years ago

Let me give the big picture. So I've got a Xamarin.Forms app and I'm using Prism.

So a user goes to a view, and in the ViewModel constructor, I want to initialize the Fingerprint Reader so that if/when a user were to touch their finger to the sensor, it will fire an event letting me know that they did it/the result.

If they don't touch the fingerprint sensor, they're free to interact with other UI elements on the screen (e.g. a textbox to enter their password manually).

Is that scenario doable?

Thanks!

smstuebe commented 5 years ago

Only on Android if you set UseDialog to false. The Constructor of a ViewModel is a very bad place. The Scanning should not be done continuously... It i meant to be explicit. With Android Pie they started to streamline it. o in future it will not be possible to do it without a dialog. Save your time and implement features instead :P

https://github.com/smstuebe/xamarin-fingerprint/blob/master/src/Plugin.Fingerprint.Abstractions/AuthenticationRequestConfiguration.cs#L28

Osmosis311 commented 5 years ago

Thanks so much! Just want to make sure I understand:

  1. Are you saying that if I wanted to do continuous scanning I can if I turn off the UseDialog?

  2. When you say Android is streamlining things, does that mean in the future all these apps that are apparently doing continuous scanning won’t be able to going forward?

  3. Is there some event that the OS publishes when the fingerprint reader has been activated so the plugin doesn’t need to do continuous scanning, rather it wakes up when the fingerprint reader is in use?

  4. Bottom line, is the best practice the way you suggest to do it, which is a button or some other user action that then activates the fingerprint reader?

Thanks!

On Wed, Oct 10, 2018 at 4:38 PM Sven-Michael Stübe notifications@github.com wrote:

Only on Android if you set UseDialog to false. The Constructor of a ViewModel is a very bad place. The Scanning should not be done continuously... It i meant to be explicit. With Android Pie they started to streamline it. o in future it will not be possible to do it without a dialog. Save your time and implement features instead :P

https://github.com/smstuebe/xamarin-fingerprint/blob/master/src/Plugin.Fingerprint.Abstractions/AuthenticationRequestConfiguration.cs#L28

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/smstuebe/xamarin-fingerprint/issues/90#issuecomment-428722664, or mute the thread https://github.com/notifications/unsubscribe-auth/AAV_MKK05bIj6EmziZh1Q18NYb3v8ngPks5ujlq_gaJpZM4R26VO .

smstuebe commented 5 years ago
  1. Yes, but not 100% guarantied. a) because of vendor implementations b) because of possible time limits for scanning
  2. API is deprecated with Pie
  3. nope
  4. depends on your use case. Some apps do it when getting active. Some on button click.
Osmosis311 commented 5 years ago

Understood. Thanks!