Source Code
import UIKit
import CafSmartAuth
class MainViewController: UIViewController {
private var smartAuth: CafSmartAuthSdk?
override func viewDidLoad() {
super.viewDidLoad()
setupCafSmartAuth()
let verifyPolicyButton = UIButton(type: .system)
verifyPolicyButton.setTitle("Verify Policy", for: .normal)
verifyPolicyButton.addTarget(self, action: #selector(verifyPolicy), for: .touchUpInside)
view.addSubview(verifyPolicyButton)
// Layout constraints for button (if needed)
}
private func setupCafSmartAuth() {
smartAuth = CafSmartAuthSdk.CafBuilder(mobileToken: "myMFAToken")
.setStage(.prod)
.setEmailURL(URL(string: "https://myEmailUrl.com")) // Not mandatory
.setPhoneURL(URL(string: "https://myPhoneUrl.com")) // Not mandatory
.setLivenessSettings(
CafFaceLivenessSettings(
faceLivenessToken: "myFaceAuthToken",
useLoadingScreen: false,
filter: .lineDrawing
)
).build()
}
@objc private func verifyPolicy() {
smartAuth?.verifyPolicy(
personID: "userDocument",
policyId: "myPolicyId",
listener: setupListener()
)
}
private func setupListener() -> CafVerifyPolicyListener {
return { result in
switch result {
case .onSuccess(let response):
print("CafVerifyPolicyListener.onSuccess isAuthorized: \(response.isAuthorized)")
print("CafVerifyPolicyListener.onSuccess attestation: \(response.attestation)")
case .onPending(let response):
print("CafVerifyPolicyListener.onPending isAuthorized: \(response.isAuthorized)")
print("CafVerifyPolicyListener.onPending attestation: \(response.attestation)")
case .onError(let error):
print("CafVerifyPolicyListener.onError failure: \(error.localizedDescription)")
case .onCanceled(let error):
print("CafVerifyPolicyListener.onCanceled failure: \(error.localizedDescription)")
case .onLoading(let isLoading):
print("CafVerifyPolicyListener.onLoading isLoading: \(isLoading)")
case .onLoaded(let isLoaded):
print("CafVerifyPolicyListener.onLoaded isLoaded: \(isLoaded)")
}
}
}
}
Last updated