diff --git a/packages/auth/amplify_auth_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AmplifyAuthCognitoPlugin.kt b/packages/auth/amplify_auth_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AmplifyAuthCognitoPlugin.kt index f1a9a4d8df0..5a0e5323bc7 100644 --- a/packages/auth/amplify_auth_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AmplifyAuthCognitoPlugin.kt +++ b/packages/auth/amplify_auth_cognito/android/src/main/kotlin/com/amazonaws/amplify/amplify_auth_cognito/AmplifyAuthCognitoPlugin.kt @@ -296,35 +296,55 @@ open class AmplifyAuthCognitoPlugin : * Get Legacy Device Secrets */ override fun fetchLegacyDeviceSecrets(userPoolId: String?, appClientId: String?, callback: (Result) -> 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) { + 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