Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ struct AWSCognitoAuthCredentialStore {
let oldUserPoolConfiguration = oldAuthConfigData.getUserPoolConfiguration()
let oldIdentityPoolConfiguration = oldAuthConfigData.getIdentityPoolConfiguration()
let newIdentityConfigData = currentAuthConfig.getIdentityPoolConfiguration()
let newUserPoolConfiguration = currentAuthConfig.getUserPoolConfiguration()

/// Only migrate if
/// Migrate if
/// - Old User Pool Config didn't exist
/// - New Identity Config Data exists
/// - Old Identity Pool Config == New Identity Pool Config
Expand All @@ -95,6 +96,19 @@ struct AWSCognitoAuthCredentialStore {
if let oldCognitoCredentialsData = try? keychain._getData(oldNameSpace) {
try? keychain._set(oldCognitoCredentialsData, key: newNameSpace)
}
/// Migrate if
/// - Old config and new config are different
/// - Old Userpool Existed
/// - Old and new user pool namespacing is the same
} else if oldAuthConfigData != currentAuthConfig &&
oldUserPoolConfiguration != nil &&
UserPoolConfigurationData.isNamespacingEqual(
lhs: oldUserPoolConfiguration,
rhs: newUserPoolConfiguration) {
// 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 &&
oldNameSpace != newNameSpace {
// Clear the old credentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ struct UserPoolConfigurationData: Equatable {
func getIdentityProviderName() -> String {
return "cognito-idp.\(region).amazonaws.com/\(poolId)"
}

static func isNamespacingEqual(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably good to have a test for this method

lhs: UserPoolConfigurationData?,
rhs: UserPoolConfigurationData?) -> Bool {
return lhs?.poolId == rhs?.poolId
&& lhs?.clientId == rhs?.clientId
&& lhs?.region == rhs?.region
}
}

extension UserPoolConfigurationData: Codable { }
Expand Down
Loading