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.
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)") }}
// Create enrollment configuration with backupfinal configuration =BiomAuthConfig(retrieveBackup:true);try {final result =awaitKeyless.instance.authenticate(configuration);print("Backup retrieved successfully");} catch (error) {print("Backup retrieval failed: $error");}
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)") }}
// Create enrollment configuration with backupfinal configuration =BiomEnrollConfig( backup:KeylessBackup( data: backupData, key: backupKey ));try {final result =awaitKeyless.instance.enroll(configuration);print("Enrollment from backup successful");} catch (error) {print("Enrollment from backup failed: $error");}