Skip to content

Commit

Permalink
chore: implement deleteLegacyDeviceSecrets method
Browse files Browse the repository at this point in the history
  • Loading branch information
khatruong2009 committed Jan 24, 2024
1 parent 38d2081 commit ef5d467
Showing 1 changed file with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,35 +296,55 @@ open class AmplifyAuthCognitoPlugin :
* Get Legacy Device Secrets
*/
override fun fetchLegacyDeviceSecrets(userPoolId: String?, appClientId: String?, callback: (Result<LegacyDeviceDetails>) -> Unit) {
val data = LegacyDeviceDetails.builder()
val data = LegacyDeviceDetails.builder()

if (appClientId != null) {
val lastAuthUser = legacyUserPoolStore["CognitoIdentityProvider.$appClientId.LastAuthUser"]
if (appClientId != null) {
val lastAuthUser = legacyUserPoolStore["CognitoIdentityProvider.$appClientId.LastAuthUser"]

val newLegacyDeviceSecretsStore = new LegacyKeyValueStore(
applicationContext!!,
"CognitoIdentityProviderDeviceCache.$userPoolId.$lastAuthUser"
)
val newLegacyDeviceSecretsStore = new LegacyKeyValueStore(
applicationContext!!,
"CognitoIdentityProviderDeviceCache.$userPoolId.$lastAuthUser"
)

val deviceKey = newLegacyDeviceSecretsStore["DeviceKey"]
val deviceSecret = newLegacyDeviceSecretsStore["DeviceSecret"]
val deviceGroup = newLegacyDeviceSecretsStore["DeviceGroupKey"]

val deviceKey = newLegacyDeviceSecretsStore["DeviceKey"]
val deviceSecret = newLegacyDeviceSecretsStore["DeviceSecret"]
val deviceGroup = newLegacyDeviceSecretsStore["DeviceGroupKey"]
data.apply {
this.deviceKey = deviceKey
this.deviceSecret = deviceSecret
this.deviceGroupKey = deviceGroup
}

}

val asfDeviceId = asfDeviceSecretsStore["CognitoDeviceId"]
data.apply {
this.deviceKey = deviceKey
this.deviceSecret = deviceSecret
this.deviceGroupKey = deviceGroup
this.asfDeviceId = asfDeviceId
}

callback(Result.success(data.build()))
}

val asfDeviceId = asfDeviceSecretsStore["CognitoDeviceId"]
data.apply {
this.asfDeviceId = asfDeviceId
}
/**
* Delete Legacy Device Secrets
*/
override fun deleteLegacyDeviceSecrets(userPoolId: String?, appClientId: String?, callback: (Result<Unit>) -> Unit) {
if (appClientId != null) {
val lastAuthUser = legacyUserPoolStore["CognitoIdentityProvider.$appClientId.LastAuthUser"]

callback(Result.success(data.build()))
}
val LegacyDeviceSecretsStore = new LegacyKeyValueStore(
applicationContext!!,
"CognitoIdentityProviderDeviceCache.$userPoolId.$lastAuthUser"
)

LegacyDeviceSecretsStore.clear()
}

asfDeviceSecretsStore.clear()

callback(Result.success(Unit))
}

/**
* Clears the legacy credentials set by the Android SDK
Expand Down

0 comments on commit ef5d467

Please sign in to comment.