Enrollment

Example for how to enroll a new user.

🔌 Trigger

You are now ready to start the enrollment. Suppose you have an "Enroll" button and a correponding trigger where you invoke the Keyless.enrollCustomToken method.

Depending on your application logic, you can choose to use different custom token. This could be a secret that you have provided to the app from the backend, the the seed of an OTP protocol, or anything else. If you only need to know the result of the authentication (success/failed), you can pass any constant value as the custom token.

fun onClickEnrollButton() {
try {
Keyless.enrollCustomToken("Your custom token")
} catch (e: Exception) {
// Handle exception
}
}

Optionally, start a loading indicator and show the progress by modifying two of the optional KeylessDelegate methods:

KeylessCustomDelegate.kt
// ...
class KeylessDelegateCustom : KeylessDelegate {
// ...
// Optional functions
override fun enrollmentStart() {
// Please make sure to use runOnUiThread() if you need to handle UI changes
Log.i(TAG, "Enrollment started.")
// Here you may want to display a loading indicator.
}
override fun enrollmentProgress(progress: Float) {
// Please make sure to use runOnUiThread() if you need to handle UI changes
Log.i(TAG, "Enrollment progress: $progress.")
// Here you want to update your UI progress.
}
}

😎 Result

When enrollment finishes, the enrollmentFinish method gets called. In case of errors, prompt the user to try again. If the process was successful, stop the loading indicator and navigate to the next screen of your application (e.g. success or main view).

KeylessCustomDelegate.kt
// ...
class KeylessDelegateCustom : KeylessDelegate {
// ...
override fun enrollmentFinish(
keylessID: String?,
enrollmentResponse: String?,
error: KeylessException?
) {
// Please make sure to use runOnUiThread() if you need to handle UI changes
if (error != null) {
Log.e(TAG, "Enrollment failed: " + error.title +
" Message: " + error.message + " Code: " + error.code +
" Cancelled by user: " + error.userCancelled);
// Show error alert
// Revert any changes up to this point
return
}
// Handle successful enrollment
// At this point the sign up process finished successfully
// Let the user know that signing up was successful and navigate to your next screen like the main screen
}
// ...
}

Having Issues?

If you've experienced an error, please make sure that you've completed all the steps within the "Installation" section and correctly configured yourbuild.gradle andapp/build.gradlefile.