Skip to content

Commit 0aed399

Browse files
Update snippets for restore credentials (#795)
* Update snippets for restore credentials Minor update to: 1. shift out initialization of credentialManager 2. clarify what the `createRestoreRequest` object contains 3. Clean up comments * Update RestoreCredentialsFunctions.kt
1 parent cde2f39 commit 0aed399

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

identity/credentialmanager/src/main/java/com/example/identity/credentialmanager/RestoreCredentialsFunctions.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ class RestoreCredentialsFunctions(
3232
createRestoreRequest: CreateRestoreCredentialRequest
3333
) {
3434
// [START android_identity_restore_cred_create]
35-
val credentialManager = CredentialManager.create(context)
36-
37-
// On a successful authentication create a Restore Key
38-
// Pass in the context and CreateRestoreCredentialRequest object
35+
// createRestoreRequest contains the details sent by the server
3936
val response = credentialManager.createCredential(context, createRestoreRequest)
4037
// [END android_identity_restore_cred_create]
4138
}
@@ -44,16 +41,13 @@ class RestoreCredentialsFunctions(
4441
fetchAuthenticationJson: () -> String,
4542
) {
4643
// [START android_identity_restore_cred_get]
47-
// Fetch the Authentication JSON from server
44+
// Fetch the options required to get the restore key
4845
val authenticationJson = fetchAuthenticationJson()
4946

5047
// Create the GetRestoreCredentialRequest object
5148
val options = GetRestoreCredentialOption(authenticationJson)
5249
val getRequest = GetCredentialRequest(listOf(options))
5350

54-
// The restore key can be fetched in two scenarios to
55-
// 1. On the first launch of app on the device, fetch the Restore Key
56-
// 2. In the onRestore callback (if the app implements the Backup Agent)
5751
val response = credentialManager.getCredential(context, getRequest)
5852
// [END android_identity_restore_cred_get]
5953
}
@@ -63,7 +57,7 @@ class RestoreCredentialsFunctions(
6357
// Create a ClearCredentialStateRequest object
6458
val clearRequest = ClearCredentialStateRequest(TYPE_CLEAR_RESTORE_CREDENTIAL)
6559

66-
// On user log-out, clear the restore key
60+
// When the user logs out, delete the restore key
6761
val response = credentialManager.clearCredentialState(clearRequest)
6862
// [END android_identity_restore_cred_delete]
6963
}

0 commit comments

Comments
 (0)