Skip to content

Commit

Permalink
fix(auth): clear credentials values only if namespacing has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh62 committed Aug 21, 2024
1 parent bdfa37a commit eb7e2b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ struct AWSCognitoAuthCredentialStore {
newIdentityConfigData != nil &&
oldIdentityPoolConfiguration == newIdentityConfigData
{

// retrieve data from the old namespace and save with the new namespace
if let oldCognitoCredentialsData = try? keychain._getData(oldNameSpace) {
try? keychain._set(oldCognitoCredentialsData, key: newNameSpace)
}
} else if oldAuthConfigData != currentAuthConfig {
} else if oldAuthConfigData != currentAuthConfig &&
oldNameSpace != newNameSpace {
// Clear the old credentials
try? keychain._remove(oldNameSpace)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,16 @@ class CredentialStoreConfigurationTests: AWSAuthBaseTest {
XCTFail("Unable to save credentials")
}

// When configuration changed
let updatedConfig = AuthConfiguration.userPoolsAndIdentityPools(
UserPoolConfigurationData(poolId: Defaults.userPoolId,
clientId: Defaults.appClientId,
region: Defaults.regionString,
clientSecret: Defaults.appClientSecret,
pinpointAppId: "somethingNew"),
Defaults.makeIdentityConfigData())
// When configuration don't change changed
let newCredentialStore = AWSCognitoAuthCredentialStore(authConfiguration: initialAuthConfig)
let newCredentialStore = AWSCognitoAuthCredentialStore(authConfiguration: updatedConfig)

// Then
guard let credentials = try? newCredentialStore.retrieveCredential(),
Expand Down

0 comments on commit eb7e2b3

Please sign in to comment.