@@ -23,6 +23,7 @@ struct ConfigurationHelper {
23
23
return nil
24
24
}
25
25
26
+ // parse `pinpointId`
26
27
var pinpointId : String ?
27
28
if case . string( let pinpointIdFromConfig) = cognitoUserPoolJSON. value ( at: " PinpointAppId " ) {
28
29
pinpointId = pinpointIdFromConfig
@@ -44,6 +45,7 @@ struct ConfigurationHelper {
44
45
return nil
45
46
} ( )
46
47
48
+ // parse `authFlowType`
47
49
var authFlowType : AuthFlowType
48
50
if case . boolean( let isMigrationEnabled) = cognitoUserPoolJSON. value ( at: " MigrationEnabled " ) ,
49
51
isMigrationEnabled == true {
@@ -56,22 +58,97 @@ struct ConfigurationHelper {
56
58
authFlowType = . userSRP
57
59
}
58
60
61
+ // parse `clientSecret`
59
62
var clientSecret : String ?
60
63
if case . string( let clientSecretFromConfig) = cognitoUserPoolJSON. value ( at: " AppClientSecret " ) {
61
64
clientSecret = clientSecretFromConfig
62
65
}
63
66
67
+ // parse `hostedUIConfig`
64
68
let hostedUIConfig = parseHostedConfiguration (
65
69
configuration: config. value ( at: " Auth.Default.OAuth " ) )
66
70
71
+ // parse `passwordProtectionSettings`
72
+ let cognitoConfiguration = config. value ( at: " Auth.Default " )
73
+ var passwordProtectionSettings : PasswordProtectionSettings ?
74
+ if case . object( let passwordSettings) = cognitoConfiguration? . value ( at: " passwordProtectionSettings " ) {
75
+
76
+ // parse `minLength`
77
+ var minLength : Int ?
78
+ if case . number( let value) = passwordSettings [ " passwordPolicyMinLength " ] {
79
+ minLength = Int ( value)
80
+ } else if case . string( let value) = passwordSettings [ " passwordPolicyMinLength " ] ,
81
+ let intValue = Int ( value) {
82
+ minLength = intValue
83
+ }
84
+
85
+ // parse `characterPolicy`
86
+ var characterPolicy : [ PasswordCharacterPolicy ] = [ ]
87
+ if case . array( let characters) = passwordSettings [ " passwordPolicyCharacters " ] {
88
+ characterPolicy = characters. compactMap { value in
89
+ guard case . string( let string) = value else {
90
+ return nil
91
+ }
92
+
93
+ return . init( rawValue: string)
94
+ }
95
+ }
96
+
97
+ passwordProtectionSettings = PasswordProtectionSettings (
98
+ minLength: minLength,
99
+ characterPolicy: characterPolicy
100
+ )
101
+ }
102
+
103
+ // parse `usernameAttributes`
104
+ var usernameAttributes : [ UsernameAttribute ] = [ ]
105
+ if case . array( let attributes) = cognitoConfiguration ? [ " usernameAttributes " ] {
106
+ usernameAttributes = attributes. compactMap { value in
107
+ guard case . string( let string) = value else {
108
+ return nil
109
+ }
110
+
111
+ return . init( rawValue: string)
112
+ }
113
+ }
114
+
115
+ // parse `signUpAttributes`
116
+ var signUpAttributes : [ SignUpAttributeType ] = [ ]
117
+ if case . array( let attributes) = cognitoConfiguration ? [ " signupAttributes " ] {
118
+ signUpAttributes = attributes. compactMap { value in
119
+ guard case . string( let string) = value else {
120
+ return nil
121
+ }
122
+
123
+ return . init( rawValue: string)
124
+ }
125
+ }
126
+
127
+ // parse `verificationMechanisms`
128
+ var verificationMechanisms : [ VerificationMechanism ] = [ ]
129
+ if case . array( let attributes) = cognitoConfiguration ? [ " verificationMechanisms " ] {
130
+ verificationMechanisms = attributes. compactMap { value in
131
+ guard case . string( let string) = value else {
132
+ return nil
133
+ }
134
+
135
+ return . init( rawValue: string)
136
+ }
137
+ }
138
+
67
139
return UserPoolConfigurationData ( poolId: poolId,
68
140
clientId: appClientId,
69
141
region: region,
70
142
endpoint: endpoint,
71
143
clientSecret: clientSecret,
72
144
pinpointAppId: pinpointId,
73
145
authFlowType: authFlowType,
74
- hostedUIConfig: hostedUIConfig)
146
+ hostedUIConfig: hostedUIConfig,
147
+ passwordProtectionSettings: passwordProtectionSettings,
148
+ usernameAttributes: usernameAttributes,
149
+ signUpAttributes: signUpAttributes,
150
+ verificationMechanisms: verificationMechanisms)
151
+
75
152
}
76
153
77
154
static func parseHostedConfiguration( configuration: JSONValue ? ) -> HostedUIConfigurationData ? {
0 commit comments