Skip to content

Commit a2dfdf0

Browse files
authored
fix(auth): use auth flow type correctly from amplifyconfiguraiton.json (#3928)
1 parent 82b1ca0 commit a2dfdf0

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Models/AuthFlowType.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ public enum AuthFlowType {
3434
/// - `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.
3535
case userAuth(preferredFirstFactor: AuthFactorType?)
3636

37+
internal init?(rawValue: String) {
38+
switch rawValue {
39+
case "CUSTOM_AUTH":
40+
self = .customWithSRP
41+
case "USER_SRP_AUTH":
42+
self = .userSRP
43+
case "USER_PASSWORD_AUTH":
44+
self = .userPassword
45+
case "USER_AUTH":
46+
self = .userAuth
47+
default:
48+
return nil
49+
}
50+
}
51+
3752
var rawValue: String {
3853
switch self {
3954
case .custom, .customWithSRP, .customWithoutSRP:

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Helpers/ConfigurationHelper.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@ struct ConfigurationHelper {
4747

4848
// parse `authFlowType`
4949
var authFlowType: AuthFlowType
50+
51+
// If Migration path is enabled, auth flow type should always be set to USER_PASSWORD_AUTH
5052
if case .boolean(let isMigrationEnabled) = cognitoUserPoolJSON.value(at: "MigrationEnabled"),
5153
isMigrationEnabled == true {
5254
authFlowType = .userPassword
5355
} else if let authJson = config.value(at: "Auth.Default"),
54-
case .string(let authFlowTypeJSON) = authJson.value(at: "authenticationFlowType"),
55-
authFlowTypeJSON == "CUSTOM_AUTH" {
56-
authFlowType = .customWithSRP
56+
case .string(let authFlowTypeConfigValue) = authJson.value(at: "authenticationFlowType"),
57+
let authFlowTypeFromConfig = AuthFlowType(rawValue: authFlowTypeConfigValue) {
58+
authFlowType = authFlowTypeFromConfig
5759
} else {
60+
// if the auth flow type is not found from config, default to SRP
5861
authFlowType = .userSRP
5962
}
6063

0 commit comments

Comments
 (0)