Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): use auth flow type correctly from amplifyconfiguration.json #3928

Merged
merged 1 commit into from
Dec 5, 2024
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 @@ -34,6 +34,21 @@ public enum AuthFlowType {
/// - `preferredFirstFactor`: the auth factor type the user should begin signing with if available. If the preferred first factor is not available, the flow would fallback to provide available first factors.
case userAuth(preferredFirstFactor: AuthFactorType?)

internal init?(rawValue: String) {
switch rawValue {
case "CUSTOM_AUTH":
self = .customWithSRP
case "USER_SRP_AUTH":
self = .userSRP
case "USER_PASSWORD_AUTH":
self = .userPassword
case "USER_AUTH":
self = .userAuth
default:
return nil
}
}

var rawValue: String {
switch self {
case .custom, .customWithSRP, .customWithoutSRP:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ struct ConfigurationHelper {

// parse `authFlowType`
var authFlowType: AuthFlowType

// If Migration path is enabled, auth flow type should always be set to USER_PASSWORD_AUTH
if case .boolean(let isMigrationEnabled) = cognitoUserPoolJSON.value(at: "MigrationEnabled"),
isMigrationEnabled == true {
authFlowType = .userPassword
} else if let authJson = config.value(at: "Auth.Default"),
case .string(let authFlowTypeJSON) = authJson.value(at: "authenticationFlowType"),
authFlowTypeJSON == "CUSTOM_AUTH" {
authFlowType = .customWithSRP
case .string(let authFlowTypeConfigValue) = authJson.value(at: "authenticationFlowType"),
let authFlowTypeFromConfig = AuthFlowType(rawValue: authFlowTypeConfigValue) {
authFlowType = authFlowTypeFromConfig
} else {
// if the auth flow type is not found from config, default to SRP
authFlowType = .userSRP
}

Expand Down
Loading