Authentication

Example for how to authenticate a user, after they have been enrolled.

β€‹πŸ”Œ Trigger

Similarly to what you have done for enrolllment, you can request user authentication by invoking the Keyless.shared.getCustomAuthenticationToken method:

@IBAction private func authenticateButtonDidTap() {
do {
// Retrieve the custom token you stored previously
try Keyless.shared.getCustomAuthenticationToken()
} catch {
print(error)
// Handle error
}
}

By default, during the authentication users will be able to see their face captured by their device’s front camera. It is possible to disable this behavior by setting the default parameter showUserSilhouette to false.

@IBAction private func authenticateButtonDidTap() {
do {
// Retrieve the custom token you stored previously
try Keyless.shared.getCustomAuthenticationToken(showUserSilhouette: false)
} catch {
print(error)
// Handle error
}
}

Optionally, get notified when the authentication starts by implementing the optional Keyless delegate method:

func authenticationDidStart() {
DispatchQueue.main.async { [weak self] in
// Start loading indicator
}
}

β€‹πŸ˜Ž Result

When authentication finishes, the authenticationDidFinish: token: error: method gets called. Take the token and validate the challenge with it.

Handle any errors and prompt the user to try again if it failed.

If the process was successful, stop the loading indicator and navigate to the next screen of your application (e.g. payment processed and dismiss view controller).:

func authenticationDidFinish(token: String?, error: KeylessError?) {
guard error == nil else {
DispatchQueue.main.async { [weak self] in
// Show error alert
// prompt user to try again
}
return
}
guard let authenticationToken = token else {
DispatchQueue.main.async { [weak self] in
// Failed to retrieve token
// Show error alert
// prompt user to try again
}
return
}
// At this point, authenticationToken = "Your custom token"
// Use the `authenticationToken`
}