Biometric/Pin
Cotter's iOS SDK helps you easily add a Biometric prompt or PIN fallback to your app. This is useful for protecting transactions or sensitive information like medical records.
Overview
Enabling PIN and Biometric using Cotter's Android SDK consists of:
Initializing Cotter
Calling functions to start PIN and Biometric Enrollment
Verify Biometric or PIN before an action
Enabling and disabling Biometric or PIN in Settings
What you're building
Steps
Step 1. Installation
We use Cocoapods as our SDK host. If you're using Cocoapods, add this to your Podfile
Otherwise please open an issue at our Github Issues page.
Then simply run pod install
Step 2. Set allowed Authentication Methods in the Developer Dashboard
You need to set allowed methods for authentication your users. To allow PIN
and BIOMETRIC
, go to https://dev.cotter.app/rules
Remember to select the correct project in the dropdown list
Step 3. Initializing Cotter
You will have to do import Cotter
on the file that will use Cotter. Then do initialization as follows
example:
Step 4. Creating a User
1. Registering a new User
Response:
Example:
2. Get a User
Response:
Example:
Step 5. Enroll PIN or Biometric
For starting authentication flow, you need to have the following:
The
UIViewController
you want to attach Cotter toThe
UIViewController
MUST have aNavigationController
set (i.e.self.navigationController
cannot benil
)
example:
Step 6. Verify PIN and/or Biometrics on an action
The verification flow will automatically prompt for Biometric Verification if the user's device has an enrolled biometric. Otherwise, it will fallback to entering PIN. Starting the verification flow is exactly the same as starting the Enrollment Flow on step 5.
Example:
🎉 You're done!
Additional Notes
The Callbacks
There are 2 types of callback:
1. HTTP Callbacks
HTTP Callbacks are the ones that you pass in to the start flow functions (startEnrollment, startTransaction, startUpdateProfile).
The callback form is as such:
It takes in a token String and an optional Error object. Currently token String is not used in PIN or Biometric authentication. We're working on making the token useable.
Error types
For the FinalAuthCallback function, there are 3 types of CotterError that exist in the SDK. These include:
1. CotterError.biometricEnrollment
This error is produced when you fail to enroll your biometrics during the Enrollment flow in startEnrollment.
2. CotterError.biometricVerification
This error is produced when you fail to verify your biometrics during the Transaction flow in startTransaction.
3. CotterError.keychainError
This error is produced in all flows when the user's device is unable to attain its corresponding public/private keys.
However, you will almost always only encounter CotterError.biometricEnrollment
and CotterError.biometricVerification
errors in the resulting FinalAuthCallback
function.
2. Authentication Callbacks
Authentication Callbacks are the ones that is passed in through the CotterAPIService
. It uses the latest Result enum in Swift 5. The Authentication callback works similarly as the HTTP Callback, it can handle success and error cases as shown on the previous example.
The callback form is as such:
What this definition says is that it takes a Result of a type Value, which Value can be any of the pre defined Cotter classes (such as CotterUser
, CotterEvent
, etc), and returns nothing.
Error types
When using the CotterAPIService
class to call Cotter's API endpoints, there are 5 types of Cotter errors that you might encounter:
1. CotterAPIError.encoding
An 'encoding' error refers to an error encoding the HTTP Request.
2. CotterAPIError.decoding
A 'decoding' error refers to an error decoding the HTTP Response.
3. CotterAPIError.status(code: Int)
A 'status' error refers to the response having an invalid HTTP Status Code - e.g. Status 400 (Bad Request Error)
4. CotterAPIError.server(message: String)
A 'server' error means that our API server has responded to the request with an error message.
5. CotterAPIError.network
A 'network' error means that network conditions are poor, which can be due to bad internet connection.
Last updated