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.
| # | Step | Call |
|---|---|---|
| 1 | Obtain a token | In your backend |
| 2 | Initialise | doInitSDK() |
| 3 | Prepare the capture | MIDFaceViewBuilderMIDFaceSDKBuilder |
| 4 | Verify the face | faceSDK.start() |
| 5 | Confirm the result | In your backend |
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:
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.
- Swift
- Objective-C
MIDSDK.shared.doInitSDK(applicationId: "YOUR_APPLICATION_ID",
authToken: authToken, // issued by your backend
serverUrl: "https://{SERVER-URL}/api/v7")
[CMIDSDK.mIDSDK doInitSDKApplicationId:@"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:
- Swift
- Objective-C
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()
MIDFaceViewBuilder *viewBuilder = [[MIDFaceViewBuilder alloc] init];
[viewBuilder setFrame:self.view.bounds];
NSError *error;
MIDFaceView *faceView = [viewBuilder buildAndReturnError:&error];
[self.view addSubview:faceView];
MIDFaceSDK *faceSDK = [[[[[[[MIDFaceSDKBuilder alloc] init]
targetView:faceView]
addFeedbackListener:faceView]
addLivenessListener:faceView]
livenessDetectionMode:MIDFaceLivenessDetectionMode.headPassiveImage]
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:
- Swift
- Objective-C
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
}
}
[faceSDK startRecognitionMode:CMIDRecognitionMode.verification
parameters:[[CMIDVerificationParameters alloc] initWithUserId:@"user-0001"]
operationListener:self];
// CMIDVerificationListener
- (void)onVerificationFinishedResult:(CMIDVerificationListenerResult *)result
data:(CMIDVerificationData * _Nullable)data
errorOccurred:(CMIDError * _Nullable)errorOccurred {
if (result == CMIDVerificationListenerResult.error) {
[self showError:errorOccurred];
return;
}
// 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.