@@ -123,6 +123,42 @@ export default class CognitoUser {
123
123
this . authenticationFlowType = authenticationFlowType ;
124
124
}
125
125
126
+ /**
127
+ * This is used for authenticating the user through the custom authentication flow.
128
+ * @param {AuthenticationDetails } authDetails Contains the authentication data
129
+ * @param {object } callback Result callback map.
130
+ * @param {onFailure } callback.onFailure Called on any error.
131
+ * @param {customChallenge } callback.customChallenge Custom challenge
132
+ * response required to continue.
133
+ * @param {authSuccess } callback.onSuccess Called on success with the new session.
134
+ * @returns {void }
135
+ */
136
+ initiateAuth ( authDetails , callback ) {
137
+ const authParameters = authDetails . getAuthParameters ( ) ;
138
+ authParameters . USERNAME = this . username ;
139
+
140
+ this . client . makeUnauthenticatedRequest ( 'initiateAuth' , {
141
+ AuthFlow : 'CUSTOM_AUTH' ,
142
+ ClientId : this . pool . getClientId ( ) ,
143
+ AuthParameters : authParameters ,
144
+ ClientMetadata : authDetails . getValidationData ( ) ,
145
+ } , ( err , data ) => {
146
+ if ( err ) {
147
+ return callback . onFailure ( err ) ;
148
+ }
149
+ const challengeName = data . ChallengeName ;
150
+ const challengeParameters = data . ChallengeParameters ;
151
+
152
+ if ( challengeName === 'CUSTOM_CHALLENGE' ) {
153
+ this . Session = data . Session ;
154
+ return callback . customChallenge ( challengeParameters ) ;
155
+ }
156
+ this . signInUserSession = this . getCognitoUserSession ( data . AuthenticationResult ) ;
157
+ this . cacheTokens ( ) ;
158
+ return callback . onSuccess ( this . signInUserSession ) ;
159
+ } ) ;
160
+ }
161
+
126
162
/**
127
163
* This is used for authenticating the user. it calls the AuthenticationHelper for SRP related
128
164
* stuff
0 commit comments