5️⃣ Backup

Back up your user's data so you can restore their Keyless account when necessary.

Create a backup

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 from a backup

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