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 | MIDSDK.initSDK() |
| 3 | Prepare the capture | MIDFaceViewMIDFaceSDKBuilder |
| 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
Call initSDK before any other SDK method. serverUrl is the full URL of your MobbID server, including the API version.
MIDSDK.initSDK(
applicationId = "YOUR_APPLICATION_ID",
authToken = authToken, // issued by your backend
serverUrl = "https://{SERVER-URL}/api/v7",
context = applicationContext,
)
3. Prepare the capture
Add MIDFaceView to your layout. It hosts the camera preview and displays the guidance messages:
<com.mobbeel.mobbid.face.ux.MIDFaceView
android:id="@+id/face_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Once the view is initialised, build the face engine (MIDFaceSDK) attached to it, with passive liveness:
midFaceView.post {
midFaceView.initView {
faceSDK = MIDFaceSDKBuilder().interactiveMode().apply {
defaultCameraMode(MIDFaceCameraMode.FRONT)
targetView(midFaceView.findViewById(com.mobbeel.mobbid.face.ux.R.id.camera_container))
setDetectionBox(midFaceView.detectionBox)
addFeedbackListener(midFaceView)
livenessDetectionMode(MIDFaceLivenessDetectionMode.HEAD_PASSIVE_IMAGE)
addLivenessListener(midFaceView)
}.build()
}
}
4. Verify the face
Start a verification for the user. The SDK captures the face, checks liveness and notifies the outcome to the listener:
faceSDK.start(
recognitionMode = MIDRecognitionMode.VERIFICATION,
parameters = MIDVerificationParameters("user-0001"),
operationListener = object : MIDVerificationListener {
override fun onVerificationFinished(
result: MIDVerificationListener.Result,
data: MIDVerificationData?,
errorOccurred: MIDError?,
) {
// Update the UI and send the operation ID to your backend
}
},
)
Release the engine when the screen is destroyed:
override fun onDestroy() {
super.onDestroy()
faceSDK.release()
}
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:
val operationId: String? = MIDBiometricManager.getCurrentOperationId()
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.