Skip to main content

Quick start

This guide walks you through a complete face verification: your backend issues a token, the app captures the user's face with passive liveness, MobbID compares it with the user's enrolment and your backend confirms the result.

#StepCall
1Obtain a tokenIn your backend
2InitialisedoInitSDK()
3Prepare the captureMIDFaceViewBuilderMIDFaceSDKBuilder
4Verify the facefaceSDK.start()
5Confirm the resultIn your backend
Before you begin
  • The SDK is installed and the usage descriptions are declared.
  • The user is enrolled. See Enrolment.

1. Obtain a token from your backend​

The SDK authenticates with a temporary authToken, so the API key never reaches the device. Your backend requests the token with the application ID and the SDK role API key, and returns it to the app:

Backend
curl 'https://{SERVER-URL}/api/v7/authorization' \
--header 'applicationId: YOUR_APPLICATION_ID' \
--header 'apiKey: YOUR_SDK_API_KEY'

The token is valid for 30 minutes. See Credentials for the difference between the SDK and API roles.

2. Initialise the SDK​

Initialise the SDK before calling any other method. serverUrl is the full URL of your MobbID server, including the API version.

MIDSDK.shared.doInitSDK(applicationId: "YOUR_APPLICATION_ID",
authToken: authToken, // issued by your backend
serverUrl: "https://{SERVER-URL}/api/v7")

3. Prepare the capture​

Create MIDFaceView, which hosts the camera preview and displays the guidance messages, add it to your view hierarchy and build the face engine (MIDFaceSDK) attached to it, with passive liveness:

let viewBuilder = MIDFaceViewBuilder()
viewBuilder.set(frame: view.bounds)
let faceView = try viewBuilder.build()
view.addSubview(faceView)

let sdkBuilder = MIDFaceSDKBuilder()
sdkBuilder.targetView(faceView)
sdkBuilder.addFeedbackListener(faceView)
sdkBuilder.addLivenessListener(faceView)
sdkBuilder.livenessDetectionMode(.headPassiveImage)
let faceSDK = sdkBuilder.build()

4. Verify the face​

Start a verification for the user. The SDK captures the face, checks liveness and notifies the outcome to your listener:

faceSDK.start(recognitionMode: .verification,
parameters: MIDVerificationParameters(userId: "user-0001"),
operationListener: self)

extension LoginViewController: MIDVerificationListener {
func onVerificationFinished(result: MIDVerificationListenerResult, data: MIDVerificationData?, errorOccurred: MIDError?) {
guard result != .error else { return showError(errorOccurred) }
// Update the UI and send the operation ID to your backend
}
}

5. Confirm the result in your backend​

The listener lets you update the UI, but the access decision must be taken in your backend. Send it the operation identifier included in the result data. Your backend reads the operation with an API role token and grants access only when status is SUCCESS and data.result is true. See Operation result.

Next steps​