Generating temporary state via the Mobile SDK
This page explains how to create a temporary state during a Keyless Enrollment or Authentication, which can then be leveraged for binding a user on a new device.
What is the temporary state?
The Keyless temporary state (referred to as the client state in other contexts) contains all the necessary information to restore an account. It can be created during enrollment and authentication
The temporay state internals are not important but you can expect a string similar to the following that you should pass as-is to recover the account:
"{\"artifact\":{\"family\":\"davideface_lite\",\"version\":\"1.2.0\",\"target\":\"mobile_sdk\",\"liveness\":\"liveness\"},\"core-client-state\":\"BASE_64_STATE\"}"Note that when generating the temporary state within your client app using the Keyless Mobile SDK a maximum of 50 temporary states are allowed to be generated. This ensures that the experience remains performant.
Obtain the temporary state
Use the shouldRetrieveTemporaryState parameter of the BiomEnrollConfig or BiomAuthConfig depending if you want to retrieve the temporary state during enrollment or authencation flows.
Dunring the enrollment flow:
val enrollConfig = BiomEnrollConfig(shouldRetrieveTemporaryState = true)
Keyless.enroll(
configuration = enrollConfig,
onCompletion = { result ->
when (result) {
is Keyless.KeylessResult.Success -> {
val temporaryState = result.value.temporaryState
// store the temporary state on your backend to recover the account in the future
}
is Keyless.KeylessResult.Failure -> Log.d("KeylessSDK ", "error code ${result.error.code}")
}
}
)
During the authentication flow:
val authConfig = BiomAuthConfig(shouldRetrieveTemporaryState = true)
Keyless.authenticate(
configuration = authConfig,
onCompletion = { result ->
when (result) {
is Keyless.KeylessResult.Success -> {
val temporaryState = result.value.temporaryState
// store the temporary state on your backend to recover the account in the future
}
is Keyless.KeylessResult.Failure -> Log.d("KeylessSDK ", "error code ${result.error.code}")
}
}
)During the enrollment flow:
let enrollConfig = BiomEnrollConfig(shouldRetrieveTemporaryState: true)
Keyless.enroll(
configuration: enrollConfig,
onCompletion: { result in
switch result {
case .success(let enrollSuccess):
let temporaryState = enrollSuccess.temporaryState
// store the temporary state on your backend to recover the account in the future
case .failure(let error):
print("error code: \(error.code)
}
})During the authentication flow:
let authConfig = BiomAuthConfig(shouldRetrieveTemporaryState: true)
Keyless.authenticate(
configuration: authConfig,
onCompletion: { result in
switch result {
case .success(let authSuccess):
let temporaryState = authSuccess.temporaryState
// store the temporary state on your backend to recover the account in the future
case .failure(let error):
print("error code: \(error.code)
}
})During the enrollment flow:
import 'package:keyless_flutter_sdk/keyless.dart';
import 'package:keyless_flutter_sdk/models/configurations/enrollment_configuration.dart';
final enrollConfig = BiomEnrollConfig(shouldRetrieveTemporaryState: true);
try {
final result = await Keyless.instance.enroll(enrollConfig);
if (result.temporaryState != null) {
// store the temporary state on your backend to recover the account in the future
print("Temporary state retrieved: ${result.temporaryState}");
}
} catch (error) {
print("Enrollment failed: $error");
}During the authentication flow:
import 'package:keyless_flutter_sdk/keyless.dart';
import 'package:keyless_flutter_sdk/models/configurations/authentication_configuration.dart';
final authConfig = BiomAuthConfig(shouldRetrieveTemporaryState: true);
try {
final result = await Keyless.instance.authenticate(authConfig);
if (result.temporaryState != null) {
// store the temporary state on your backend to recover the account in the future
print("Temporary state retrieved: ${result.temporaryState}");
}
} catch (error) {
print("Authentication failed: $error");
}Last updated
Was this helpful?