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


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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s