Coder Social home page Coder Social logo

hamzeh-alchami / xamarin-fingerprint Goto Github PK

View Code? Open in Web Editor NEW

This project forked from smstuebe/xamarin-fingerprint

0.0 2.0 0.0 2.72 MB

Xamarin and MvvMCross plugin for authenticate a user via fingerprint sensor

License: Apache License 2.0

Batchfile 0.13% F# 5.59% Pascal 0.86% C# 84.55% Java 8.88%

xamarin-fingerprint's Introduction

Fingerprint plugin for Xamarin

Xamarin and MvvMCross plugin for accessing the fingerprint sensor.

Type Stable Pre release
vanilla NuGet NuGet
MvvmCross NuGet NuGet

Changelog

Support

Platform Version
Xamarin.Android 4.4
Xamarin.iOS 8.0
Windows UWP 10

Usage

API

The API is defined by the IFingerprint interface:

/// <summary>
/// Checks the availability of fingerprint authentication.
/// Checks are performed in this order:
/// 1. API supports accessing the fingerprint sensor
/// 2. Permission for accessint the fingerprint sensor granted
/// 3. Device has sensor
/// 4. Fingerprint has been enrolled
/// <see cref="FingerprintAvailability.Unknown"/> will be returned if the check failed 
/// with some other platform specific reason.
/// </summary>
Task<FingerprintAvailability> GetAvailabilityAsync();

/// <summary>
/// Checks if <see cref="GetAvailabilityAsync"/> returns <see cref="FingerprintAvailability.Available"/>.
/// </summary>
/// <returns><c>true</c> if Available, else <c>false</c></returns>
Task<bool> IsAvailableAsync();

/// <summary>
/// Requests the authentication.
/// </summary>
/// <param name="reason">Reason for the fingerprint authentication request. Displayed to the user.</param>
/// <param name="cancellationToken">Token used to cancel the operation.</param>
/// <returns>Authentication result</returns>
Task<FingerprintAuthenticationResult> AuthenticateAsync(string reason, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Requests the authentication.
/// </summary>
/// <param name="authRequestConfig">Configuration of the dialog that is displayed to the user.</param>
/// <param name="cancellationToken">Token used to cancel the operation.</param>
/// <returns>Authentication result</returns>
Task<FingerprintAuthenticationResult> AuthenticateAsync(AuthenticationRequestConfiguration authRequestConfig, CancellationToken cancellationToken = default(CancellationToken));

The returned FingerprintAuthenticationResult contains information about the authentication.

/// <summary>
/// Indicatates whether the authentication was successful or not.
/// </summary>
public bool Authenticated { get { return Status == FingerprintAuthenticationResultStatus.Succeeded; } }

/// <summary>
/// Detailed information of the authentication.
/// </summary>
public FingerprintAuthenticationResultStatus Status { get; set; }

/// <summary>
/// Reason for the unsucessful authentication.
/// </summary>
public string ErrorMessage { get; set; }

Example

vanilla

var result = await CrossFingerprint.Current.AuthenticateAsync("Prove you have fingers!");
if (result.Authenticated)
{
    // do secret stuff :)
}
else
{
    // not allowed to do secret stuff :(
}

using MvvMCross

var fpService = Mvx.Resolve<IFingerprint>(); // or use dependency injection and inject IFingerprint

var result = await fpService.AuthenticateAsync("Prove you have mvx fingers!");
if (result.Authenticated)
{
    // do secret stuff :)
}
else
{
    // not allowed to do secret stuff :(
}

iOS

Limitations

You can't create a custom dialog. The standard iOS Dialog will be shown.

iOS 9+ only
  • cancelable programmatically with passed CancellationToken
  • custom fallback button title
iOS 10+ only
  • custom cancel button title

Android

Setup

Request the permission in AndroidManifest.xml

The first line is for the standard Android API and the second for Samsung devices using the Pass API.

<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />

Set the resolver of the current Activity

Skip this, if you use the MvvMCross Plugin or don't use the dialog.

We need the current activity to display the dialog. You can use the Current Activity Plugin from James Montemagno or implement your own functionality to retrieve the current activity. See Sample App for details.

CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity);

Configuration

If you don't like the default dialog, you can easily customize it. You have to inherit from FingerprintDialogFragment e.g. like:

public class MyCustomDialogFragment : FingerprintDialogFragment
{
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        var view = base.OnCreateView(inflater, container, savedInstanceState);
        view.Background = new ColorDrawable(Color.Magenta); // make it fancyyyy :D
        return view;
    }
}

And somewhere in your code set your custom dialog fragment:

CrossFingerprint.SetDialogFragmentType<MyCustomDialogFragment>();

Testing on Simulators

iOS

Controlling the sensor on the iOS Simulator

With the Hardware menu you can

  • Toggle the enrollment status
  • Trigger valid ( M) and invalid ( N) fingerprint sensor events

Android

  • start the emulator (Android >= 6.0)
  • open the settings app
  • go to Security > Fingerprint, then follow the enrollment instructions
  • when it asks for touch
  • open command prompt
  • telnet 127.0.0.1 <emulator-id> (adb devices prints "emulator-<emulator-id>")
  • finger touch 1
  • finger touch 1

Sending fingerprint sensor events for testing the plugin can be done with the telnet commands, too.

Note for Windows users: You have to enable telnet: Programs and Features > Add Windows Feature > Telnet Client

Contribution

+

xamarin-fingerprint's People

Contributors

smstuebe avatar nielscup avatar

Watchers

James Cloos avatar Hamzeh Alchami avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.