Securing Mac application with Touch ID

This Monday I got a shiny new Macbook Pro with Touchbar. There few things I don’t like about it but one thing I absolutely love is TouchID integration.

I wanted to check how easy it is to integrate with Xamarin.Mac app. Surprisingly, the APIs are exactly same as what are available on iOS, I used the code from Mike James’ blog post about securing iOS apps with TouchID

App
Touchbar

All you need is below code snippet in your Xamarin.Mac app to secure it with all new Thouch ID


LAContextReplyHandler replyHandler;

// ...

void UseTouchID()
{
    var contex = new LAContext();
    NSError authError;
    if (contex.CanEvaluatePolicy (LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out authError))
    {
        replyHandler = new LAContextReplyHandler((success, error) =>
        {
            if (success)
            {
                InvokeOnMainThread(() => ShowMessage());
            }
        });
    }

    contex.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "authenticate", replyHandler);
}

Note that we do need to have a fallback mechanism for legacy Macbook Pros (i.e without Touchbar), you can download complete source code
on Github here https://github.com/prashantvc/SuperSecureApp

Leave a Reply

Your email address will not be published. Required fields are marked *