@@ -57,6 +57,12 @@ void main() {
57
57
58
58
await signOutUser (assertComplete: true );
59
59
60
+ // Verify we can sign in with EMAIL MFA as the preferred method and forego selection.
61
+
62
+ final otpResult2 = await getOtpCode (
63
+ env.getLoginAttribute (username),
64
+ );
65
+
60
66
final resignInRes = await Amplify .Auth .signIn (
61
67
username: username,
62
68
password: password,
@@ -68,10 +74,6 @@ void main() {
68
74
.has ((d) => d.deliveryMedium, 'deliveryMedium' )
69
75
.equals (DeliveryMedium .email);
70
76
71
- final otpResult2 = await getOtpCode (
72
- env.getLoginAttribute (username),
73
- );
74
-
75
77
final confirmRes = await Amplify .Auth .confirmSignIn (
76
78
confirmationValue: await otpResult2.code,
77
79
);
@@ -83,6 +85,8 @@ void main() {
83
85
final password = generatePassword ();
84
86
final phoneNumber = generatePhoneNumber ();
85
87
88
+ final mfaCode = await getOtpCode (UserAttribute .phone (phoneNumber));
89
+
86
90
// Verify we can set EMAIL as preferred and forego selection.
87
91
await adminCreateUser (
88
92
username,
@@ -95,22 +99,19 @@ void main() {
95
99
},
96
100
);
97
101
98
- {
99
- final mfaCode = await getOtpCode (UserAttribute .phone (phoneNumber));
100
- final signInRes = await Amplify .Auth .signIn (
101
- username: username,
102
- password: password,
103
- );
104
- check (
105
- signInRes.nextStep.signInStep,
106
- because: 'MFA is required so Cognito automatically enables SMS MFA' ,
107
- ).equals (AuthSignInStep .confirmSignInWithSmsMfaCode);
102
+ final signInRes = await Amplify .Auth .signIn (
103
+ username: username,
104
+ password: password,
105
+ );
106
+ check (
107
+ signInRes.nextStep.signInStep,
108
+ because: 'MFA is required so Cognito automatically enables SMS MFA' ,
109
+ ).equals (AuthSignInStep .confirmSignInWithSmsMfaCode);
108
110
109
- final confirmRes = await Amplify .Auth .confirmSignIn (
110
- confirmationValue: await mfaCode.code,
111
- );
112
- check (confirmRes.nextStep.signInStep).equals (AuthSignInStep .done);
113
- }
111
+ final confirmRes = await Amplify .Auth .confirmSignIn (
112
+ confirmationValue: await mfaCode.code,
113
+ );
114
+ check (confirmRes.nextStep.signInStep).equals (AuthSignInStep .done);
114
115
115
116
check (
116
117
await cognitoPlugin.fetchMfaPreference (),
@@ -136,6 +137,9 @@ void main() {
136
137
await signOutUser (assertComplete: true );
137
138
138
139
{
140
+ final otpResult = await getOtpCode (
141
+ env.getLoginAttribute (username),
142
+ );
139
143
final resignInRes = await Amplify .Auth .signIn (
140
144
username: username,
141
145
password: password,
@@ -149,10 +153,6 @@ void main() {
149
153
.has ((d) => d.deliveryMedium, 'deliveryMedium' )
150
154
.equals (DeliveryMedium .email);
151
155
152
- final otpResult = await getOtpCode (
153
- env.getLoginAttribute (username),
154
- );
155
-
156
156
final confirmRes = await Amplify .Auth .confirmSignIn (
157
157
confirmationValue: await otpResult.code,
158
158
);
@@ -166,43 +166,6 @@ void main() {
166
166
),
167
167
);
168
168
169
- // Verify we can switch to SMS as preferred.
170
-
171
- await cognitoPlugin.updateMfaPreference (
172
- sms: MfaPreference .preferred,
173
- );
174
- check (await cognitoPlugin.fetchMfaPreference ()).equals (
175
- const UserMfaPreference (
176
- enabled: {MfaType .sms, MfaType .email},
177
- preferred: MfaType .sms,
178
- ),
179
- );
180
-
181
- {
182
- await signOutUser (assertComplete: true );
183
-
184
- final mfaCode = await getOtpCode (UserAttribute .phone (phoneNumber));
185
- final signInRes = await Amplify .Auth .signIn (
186
- username: username,
187
- password: password,
188
- );
189
- check (
190
- signInRes.nextStep.signInStep,
191
- because: 'Preference is SMS MFA now' ,
192
- ).equals (AuthSignInStep .confirmSignInWithSmsMfaCode);
193
- check (signInRes.nextStep.codeDeliveryDetails).isNotNull ()
194
- ..has ((d) => d.deliveryMedium, 'deliveryMedium' )
195
- .equals (DeliveryMedium .sms)
196
- ..has ((d) => d.destination, 'destination' )
197
- .isNotNull ()
198
- .startsWith ('+' );
199
-
200
- final confirmRes = await Amplify .Auth .confirmSignIn (
201
- confirmationValue: await mfaCode.code,
202
- );
203
- check (confirmRes.nextStep.signInStep).equals (AuthSignInStep .done);
204
- }
205
-
206
169
// Verify marking enabled does not change preference.
207
170
await cognitoPlugin.updateMfaPreference (
208
171
sms: MfaPreference .enabled,
@@ -214,7 +177,7 @@ void main() {
214
177
).equals (
215
178
const UserMfaPreference (
216
179
enabled: {MfaType .sms, MfaType .email},
217
- preferred: MfaType .sms ,
180
+ preferred: MfaType .email ,
218
181
),
219
182
);
220
183
@@ -246,6 +209,8 @@ void main() {
246
209
final password = generatePassword ();
247
210
final phoneNumber = generatePhoneNumber ();
248
211
212
+ final mfaCode = await getOtpCode (UserAttribute .phone (phoneNumber));
213
+
249
214
// Create a user with an unverified phone number.
250
215
await adminCreateUser (
251
216
username,
@@ -258,22 +223,19 @@ void main() {
258
223
},
259
224
);
260
225
261
- {
262
- final mfaCode = await getOtpCode (UserAttribute .phone (phoneNumber));
263
- final signInRes = await Amplify .Auth .signIn (
264
- username: username,
265
- password: password,
266
- );
267
- check (
268
- signInRes.nextStep.signInStep,
269
- because: 'MFA is required so Cognito automatically enables SMS MFA' ,
270
- ).equals (AuthSignInStep .confirmSignInWithSmsMfaCode);
226
+ final signInRes = await Amplify .Auth .signIn (
227
+ username: username,
228
+ password: password,
229
+ );
230
+ check (
231
+ signInRes.nextStep.signInStep,
232
+ because: 'MFA is required so Cognito automatically enables SMS MFA' ,
233
+ ).equals (AuthSignInStep .confirmSignInWithSmsMfaCode);
271
234
272
- final confirmRes = await Amplify .Auth .confirmSignIn (
273
- confirmationValue: await mfaCode.code,
274
- );
275
- check (confirmRes.nextStep.signInStep).equals (AuthSignInStep .done);
276
- }
235
+ final confirmRes = await Amplify .Auth .confirmSignIn (
236
+ confirmationValue: await mfaCode.code,
237
+ );
238
+ check (confirmRes.nextStep.signInStep).equals (AuthSignInStep .done);
277
239
278
240
check (
279
241
await cognitoPlugin.fetchMfaPreference (),
@@ -287,17 +249,6 @@ void main() {
287
249
288
250
// Verify we can set SMS as preferred and forego selection.
289
251
290
- await cognitoPlugin.updateMfaPreference (
291
- sms: MfaPreference .preferred,
292
- email: MfaPreference .enabled,
293
- );
294
- check (await cognitoPlugin.fetchMfaPreference ()).equals (
295
- const UserMfaPreference (
296
- enabled: {MfaType .sms, MfaType .email},
297
- preferred: MfaType .sms,
298
- ),
299
- );
300
-
301
252
{
302
253
await signOutUser (assertComplete: true );
303
254
@@ -338,6 +289,10 @@ void main() {
338
289
{
339
290
await signOutUser (assertComplete: true );
340
291
292
+ final otpResult = await getOtpCode (
293
+ env.getLoginAttribute (username),
294
+ );
295
+
341
296
final signInRes = await Amplify .Auth .signIn (
342
297
username: username,
343
298
password: password,
@@ -351,10 +306,6 @@ void main() {
351
306
.has ((d) => d.deliveryMedium, 'deliveryMedium' )
352
307
.equals (DeliveryMedium .email);
353
308
354
- final otpResult = await getOtpCode (
355
- env.getLoginAttribute (username),
356
- );
357
-
358
309
final confirmRes = await Amplify .Auth .confirmSignIn (
359
310
confirmationValue: await otpResult.code,
360
311
);
0 commit comments