verifyFace function
Implementation
Future<Either<VerificationFailure, Map<String, dynamic>>> verifyFace({
required String? faceImage,
required String verificationSessionId,
required String apiKey,
required String accessToken,
}) async {
try {
final String timeStamp = getCurrentDateTimeInISO8601();
var requestBody = await FaceVerificationDto().toJson(
faceImage,
verificationSessionId,
timeStamp,
);
var tempBody = {
'faceImage_base64': faceImage,
'documentIdentificationId': verificationSessionId,
'timestamp': timeStamp
};
final signature = createJWT(tempBody, jwtSecret);
headers.addAll({"x-api-key": apiKey});
headers.addAll({"x-signature": signature});
headers.addAll({"x-timestamp": timeStamp});
headers.addAll({"Authorization": "Bearer $accessToken"});
final http.Response response = await http.post(
Uri.parse('${apiBaseUrl}face-authentication'),
headers: headers,
body: jsonEncode(requestBody),
);
var result = jsonDecode(response.body);
if (kDebugMode) {
print(result);
}
if (result['success'] == true && result.containsKey('score')) {
return right(
{
"faceMatch": result['score'],
"frontImage": result['outputs']['frontImage'],
"backImage": result['outputs']['backImage'],
"sideImage": result['outputs']['sideImage'],
"faceImage": result['outputs']['faceImage'],
},
);
}
return left(const VerificationFailure.faceNotMatch());
} catch (e) {
if (kDebugMode) {
print(e);
}
return left(VerificationFailure.serverError(e.toString()));
}
}