Backup data is no longer the recommended approach to perform account recovery. The recommended flow is using the temporary state. Follow the guide on account recovery.
Back up your user's data so you can restore their Keyless account when necessary.
Create a backup (not recommended)
Create backups after authentication, and push them into your backup system. Each backup is encrypted with aes-gcm using the backupKey as symmetric key. You need both backupData and backupKey to restore an account with Keyless.
val configuration = AuthenticationConfiguration.builder .retrievingBackup() .build()Keyless.authenticate( authenticationConfiguration = configuration, onCompletion = { authResult ->when (authResult) {is Keyless.KeylessResult.Success -> {// use the backupval backup: KeylessBackup? = authResult.value.backup } is Keyless.KeylessResult.Failure -> Log.d("KeylessSDK ", "Authentication failure - error code ${result.error.code}")
} })
let authenticationConfiguration = Keyless.AuthenticationConfiguration.builder .retrievingBackup() .build()Keyless.authenticate(authenticationConfiguration: authenticationConfiguration) { result inswitch result {case .success(let authenticationSuccess):// Handle your backup system logicprint("Retrieve data for backup successful")print("Backup data: \(authenticationSuccess.backup?.data)")print("Backup key: \(authenticationSuccess.backup?.key)")case .failure(let error):// Handle error and display an error to the user.print("Retrieve data for backup failed with error: \(error.message)") }}
Restore from a backup (not recommended)
Restore the user account by providing backupData and backupKey to the withBackup method:
let enrollmentConfiguration = Keyless.EnrollmentConfiguration.builder .withBackup(Keyless.Backup(data: backupData, key: backupKey)) .build()Keyless.enroll(enrollmentConfiguration: enrollmentConfiguration) { result inswitch result {case .success(let enrollmentSuccess):print("Enrollment from backup finished successfully")case .failure(let error):print("Enrollment from backup finished with error: \(error.message)") }}