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.
1
fun onClickEnrollButton() {
2
try {
3
Keyless.enrollCustomToken("Your custom token")
4
} catch (e: Exception) {
5
// Handle exception
6
}
7
}
Copied!
Optionally, start a loading indicator and show the progress by modifying two of the optional KeylessDelegate methods:
KeylessCustomDelegate.kt
1
// ...
2
​
3
class KeylessDelegateCustom : KeylessDelegate {
4
​
5
// ...
6
​
7
// Optional functions
8
9
override fun enrollmentStart() {
10
// Please make sure to use runOnUiThread() if you need to handle UI changes
11
Log.i(TAG, "Enrollment started.")
12
13
// Here you may want to display a loading indicator.
14
}
15
​
16
override fun enrollmentProgress(progress: Float) {
17
// Please make sure to use runOnUiThread() if you need to handle UI changes
18
Log.i(TAG, "Enrollment progress: $progress.")
19
20
// Here you want to update your UI progress.
21
}
22
​
23
}
Copied!

​
😎
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
1
// ...
2
​
3
class KeylessDelegateCustom : KeylessDelegate {
4
​
5
// ...
6
7
override fun enrollmentFinish(
8
keylessID: String?,
9
enrollmentResponse: String?,
10
error: KeylessException?
11
) {
12
// Please make sure to use runOnUiThread() if you need to handle UI changes
13
if (error != null) {
14
Log.e(TAG, "Enrollment failed: " + error.title +
15
" Message: " + error.message + " Code: " + error.code +
16
" Cancelled by user: " + error.userCancelled);
17
18
// Show error alert
19
// Revert any changes up to this point
20
21
return
22
}
23
​
24
// Handle successful enrollment
25
// At this point the sign up process finished successfully
26
// Let the user know that signing up was successful and navigate to your next screen like the main screen
27
}
28
29
// ...
30
}
Copied!

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.
Export as PDF
Copy link