5️⃣ Backup

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 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 backup
                val backup: KeylessBackup? = authResult.value.backup
            }
            is Keyless.KeylessResult.Failure -> Log.d("KeylessSDK ", "Authentication failure - error code ${result.error.code}")
        }
    }
)

Restore the user account by providing backupData and backupKey to the withBackup method:

val configuration = EnrollmentConfiguration.builder
  .withBackup(
    backupKey = backupKey,
    backupData = backupData
  )
  .build()


Keyless.enroll(
  enrollmentConfiguration = configuration,
  onCompletion = { result ->
    when (result) {
      is Keyless.KeylessResult.Success -> Log.d("KeylessSDK ", "Enroll success - userId ${result.value.keylessId}")
      is Keyless.KeylessResult.Failure -> Log.d("KeylessSDK ", "Enroll failure - error code ${result.error.code}")
    }
  })

Last updated