@@ -28,14 +28,19 @@ class AWSAuthConfirmSignInTask: AuthConfirmSignInTask {
28
28
if let validationError = request. hasError ( ) {
29
29
throw validationError
30
30
}
31
-
32
- let pluginOptions = ( request. options. pluginOptions as? AWSAuthConfirmSignInOptions )
33
-
34
- await taskHelper. didStateMachineConfigured ( )
35
-
36
31
let invalidStateError = AuthError . invalidState (
37
32
" User is not attempting signIn operation " ,
38
33
AuthPluginErrorConstants . invalidStateError, nil )
34
+
35
+ await taskHelper. didStateMachineConfigured ( )
36
+
37
+ if case . configured( let authNState, _) = await authStateMachine. currentState,
38
+ case . signingIn( let signInState) = authNState,
39
+ case . resolvingChallenge( let challengeState, _, _) = signInState,
40
+ case . waitingForAnswer = challengeState {
41
+ await sendConfirmSignInEvent ( )
42
+ }
43
+
39
44
let stateSequences = await authStateMachine. listen ( )
40
45
for await state in stateSequences {
41
46
guard case . configured( let authNState, let authZState) = state else {
@@ -68,19 +73,11 @@ class AWSAuthConfirmSignInTask: AuthConfirmSignInTask {
68
73
} else if case . resolvingChallenge( let challengeState, _, _) = signInState {
69
74
switch challengeState {
70
75
case . waitingForAnswer:
71
- // Convert the attributes to [String: String]
72
- let attributePrefix = AuthPluginConstants . cognitoIdentityUserUserAttributePrefix
73
- let attributes = pluginOptions? . userAttributes? . reduce (
74
- into: [ String: String] ( ) ) {
75
- $0 [ attributePrefix + $1. key. rawValue] = $1. value
76
- } ?? [ : ]
77
- let confirmSignInData = ConfirmSignInEventData (
78
- answer: self . request. challengeResponse,
79
- attributes: attributes,
80
- metadata: pluginOptions? . metadata)
81
- let event = SignInChallengeEvent (
82
- eventType: . verifyChallengeAnswer( confirmSignInData) )
83
- await authStateMachine. send ( event)
76
+ guard let result = try UserPoolSignInHelper . checkNextStep ( signInState) else {
77
+ continue
78
+ }
79
+ return result
80
+
84
81
default :
85
82
continue
86
83
}
@@ -96,4 +93,22 @@ class AWSAuthConfirmSignInTask: AuthConfirmSignInTask {
96
93
throw invalidStateError
97
94
}
98
95
96
+ func sendConfirmSignInEvent( ) async {
97
+ let pluginOptions = ( request. options. pluginOptions as? AWSAuthConfirmSignInOptions )
98
+
99
+ // Convert the attributes to [String: String]
100
+ let attributePrefix = AuthPluginConstants . cognitoIdentityUserUserAttributePrefix
101
+ let attributes = pluginOptions? . userAttributes? . reduce (
102
+ into: [ String: String] ( ) ) {
103
+ $0 [ attributePrefix + $1. key. rawValue] = $1. value
104
+ } ?? [ : ]
105
+ let confirmSignInData = ConfirmSignInEventData (
106
+ answer: self . request. challengeResponse,
107
+ attributes: attributes,
108
+ metadata: pluginOptions? . metadata)
109
+ let event = SignInChallengeEvent (
110
+ eventType: . verifyChallengeAnswer( confirmSignInData) )
111
+ await authStateMachine. send ( event)
112
+ }
113
+
99
114
}
0 commit comments