Skip to content

Commit

Permalink
fix(auth): use auth flow type correctly from amplifyconfiguraiton.json
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh62 committed Dec 4, 2024
1 parent dfb56cf commit 61fb32d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
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

0 comments on commit 61fb32d

Please sign in to comment.