UNPKG

69.2 kBJavaScriptView Raw
1/*!
2 * Copyright 2016 Amazon.com,
3 * Inc. or its affiliates. All Rights Reserved.
4 *
5 * Licensed under the Amazon Software License (the "License").
6 * You may not use this file except in compliance with the
7 * License. A copy of the License is located at
8 *
9 * http://aws.amazon.com/asl/
10 *
11 * or in the "license" file accompanying this file. This file is
12 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13 * CONDITIONS OF ANY KIND, express or implied. See the License
14 * for the specific language governing permissions and
15 * limitations under the License.
16 */
17import { Buffer } from 'buffer';
18import CryptoJS from 'crypto-js/core';
19import TypedArrays from 'crypto-js/lib-typedarrays'; // necessary for crypto js
20
21import Base64 from 'crypto-js/enc-base64';
22import HmacSHA256 from 'crypto-js/hmac-sha256';
23import BigInteger from './BigInteger';
24import AuthenticationHelper from './AuthenticationHelper';
25import CognitoAccessToken from './CognitoAccessToken';
26import CognitoIdToken from './CognitoIdToken';
27import CognitoRefreshToken from './CognitoRefreshToken';
28import CognitoUserSession from './CognitoUserSession';
29import DateHelper from './DateHelper';
30import CognitoUserAttribute from './CognitoUserAttribute';
31import StorageHelper from './StorageHelper';
32/**
33 * @callback nodeCallback
34 * @template T result
35 * @param {*} err The operation failure reason, or null.
36 * @param {T} result The operation result.
37 */
38
39/**
40 * @callback onFailure
41 * @param {*} err Failure reason.
42 */
43
44/**
45 * @callback onSuccess
46 * @template T result
47 * @param {T} result The operation result.
48 */
49
50/**
51 * @callback mfaRequired
52 * @param {*} details MFA challenge details.
53 */
54
55/**
56 * @callback customChallenge
57 * @param {*} details Custom challenge details.
58 */
59
60/**
61 * @callback inputVerificationCode
62 * @param {*} data Server response.
63 */
64
65/**
66 * @callback authSuccess
67 * @param {CognitoUserSession} session The new session.
68 * @param {bool=} userConfirmationNecessary User must be confirmed.
69 */
70
71var isBrowser = typeof navigator !== 'undefined';
72var userAgent = isBrowser ? navigator.userAgent : 'nodejs';
73/** @class */
74
75var CognitoUser = /*#__PURE__*/function () {
76 /**
77 * Constructs a new CognitoUser object
78 * @param {object} data Creation options
79 * @param {string} data.Username The user's username.
80 * @param {CognitoUserPool} data.Pool Pool containing the user.
81 * @param {object} data.Storage Optional storage object.
82 */
83 function CognitoUser(data) {
84 if (data == null || data.Username == null || data.Pool == null) {
85 throw new Error('Username and Pool information are required.');
86 }
87
88 this.username = data.Username || '';
89 this.pool = data.Pool;
90 this.Session = null;
91 this.client = data.Pool.client;
92 this.signInUserSession = null;
93 this.authenticationFlowType = 'USER_SRP_AUTH';
94 this.storage = data.Storage || new StorageHelper().getStorage();
95 this.keyPrefix = "CognitoIdentityServiceProvider." + this.pool.getClientId();
96 this.userDataKey = this.keyPrefix + "." + this.username + ".userData";
97 }
98 /**
99 * Sets the session for this user
100 * @param {CognitoUserSession} signInUserSession the session
101 * @returns {void}
102 */
103
104
105 var _proto = CognitoUser.prototype;
106
107 _proto.setSignInUserSession = function setSignInUserSession(signInUserSession) {
108 this.clearCachedUserData();
109 this.signInUserSession = signInUserSession;
110 this.cacheTokens();
111 }
112 /**
113 * @returns {CognitoUserSession} the current session for this user
114 */
115 ;
116
117 _proto.getSignInUserSession = function getSignInUserSession() {
118 return this.signInUserSession;
119 }
120 /**
121 * @returns {string} the user's username
122 */
123 ;
124
125 _proto.getUsername = function getUsername() {
126 return this.username;
127 }
128 /**
129 * @returns {String} the authentication flow type
130 */
131 ;
132
133 _proto.getAuthenticationFlowType = function getAuthenticationFlowType() {
134 return this.authenticationFlowType;
135 }
136 /**
137 * sets authentication flow type
138 * @param {string} authenticationFlowType New value.
139 * @returns {void}
140 */
141 ;
142
143 _proto.setAuthenticationFlowType = function setAuthenticationFlowType(authenticationFlowType) {
144 this.authenticationFlowType = authenticationFlowType;
145 }
146 /**
147 * This is used for authenticating the user through the custom authentication flow.
148 * @param {AuthenticationDetails} authDetails Contains the authentication data
149 * @param {object} callback Result callback map.
150 * @param {onFailure} callback.onFailure Called on any error.
151 * @param {customChallenge} callback.customChallenge Custom challenge
152 * response required to continue.
153 * @param {authSuccess} callback.onSuccess Called on success with the new session.
154 * @returns {void}
155 */
156 ;
157
158 _proto.initiateAuth = function initiateAuth(authDetails, callback) {
159 var _this = this;
160
161 var authParameters = authDetails.getAuthParameters();
162 authParameters.USERNAME = this.username;
163 var clientMetaData = Object.keys(authDetails.getValidationData()).length !== 0 ? authDetails.getValidationData() : authDetails.getClientMetadata();
164 var jsonReq = {
165 AuthFlow: 'CUSTOM_AUTH',
166 ClientId: this.pool.getClientId(),
167 AuthParameters: authParameters,
168 ClientMetadata: clientMetaData
169 };
170
171 if (this.getUserContextData()) {
172 jsonReq.UserContextData = this.getUserContextData();
173 }
174
175 this.client.request('InitiateAuth', jsonReq, function (err, data) {
176 if (err) {
177 return callback.onFailure(err);
178 }
179
180 var challengeName = data.ChallengeName;
181 var challengeParameters = data.ChallengeParameters;
182
183 if (challengeName === 'CUSTOM_CHALLENGE') {
184 _this.Session = data.Session;
185 return callback.customChallenge(challengeParameters);
186 }
187
188 _this.signInUserSession = _this.getCognitoUserSession(data.AuthenticationResult);
189
190 _this.cacheTokens();
191
192 return callback.onSuccess(_this.signInUserSession);
193 });
194 }
195 /**
196 * This is used for authenticating the user.
197 * stuff
198 * @param {AuthenticationDetails} authDetails Contains the authentication data
199 * @param {object} callback Result callback map.
200 * @param {onFailure} callback.onFailure Called on any error.
201 * @param {newPasswordRequired} callback.newPasswordRequired new
202 * password and any required attributes are required to continue
203 * @param {mfaRequired} callback.mfaRequired MFA code
204 * required to continue.
205 * @param {customChallenge} callback.customChallenge Custom challenge
206 * response required to continue.
207 * @param {authSuccess} callback.onSuccess Called on success with the new session.
208 * @returns {void}
209 */
210 ;
211
212 _proto.authenticateUser = function authenticateUser(authDetails, callback) {
213 if (this.authenticationFlowType === 'USER_PASSWORD_AUTH') {
214 return this.authenticateUserPlainUsernamePassword(authDetails, callback);
215 } else if (this.authenticationFlowType === 'USER_SRP_AUTH' || this.authenticationFlowType === 'CUSTOM_AUTH') {
216 return this.authenticateUserDefaultAuth(authDetails, callback);
217 }
218
219 return callback.onFailure(new Error('Authentication flow type is invalid.'));
220 }
221 /**
222 * PRIVATE ONLY: This is an internal only method and should not
223 * be directly called by the consumers.
224 * It calls the AuthenticationHelper for SRP related
225 * stuff
226 * @param {AuthenticationDetails} authDetails Contains the authentication data
227 * @param {object} callback Result callback map.
228 * @param {onFailure} callback.onFailure Called on any error.
229 * @param {newPasswordRequired} callback.newPasswordRequired new
230 * password and any required attributes are required to continue
231 * @param {mfaRequired} callback.mfaRequired MFA code
232 * required to continue.
233 * @param {customChallenge} callback.customChallenge Custom challenge
234 * response required to continue.
235 * @param {authSuccess} callback.onSuccess Called on success with the new session.
236 * @returns {void}
237 */
238 ;
239
240 _proto.authenticateUserDefaultAuth = function authenticateUserDefaultAuth(authDetails, callback) {
241 var _this2 = this;
242
243 var authenticationHelper = new AuthenticationHelper(this.pool.getUserPoolId().split('_')[1]);
244 var dateHelper = new DateHelper();
245 var serverBValue;
246 var salt;
247 var authParameters = {};
248
249 if (this.deviceKey != null) {
250 authParameters.DEVICE_KEY = this.deviceKey;
251 }
252
253 authParameters.USERNAME = this.username;
254 authenticationHelper.getLargeAValue(function (errOnAValue, aValue) {
255 // getLargeAValue callback start
256 if (errOnAValue) {
257 callback.onFailure(errOnAValue);
258 }
259
260 authParameters.SRP_A = aValue.toString(16);
261
262 if (_this2.authenticationFlowType === 'CUSTOM_AUTH') {
263 authParameters.CHALLENGE_NAME = 'SRP_A';
264 }
265
266 var clientMetaData = Object.keys(authDetails.getValidationData()).length !== 0 ? authDetails.getValidationData() : authDetails.getClientMetadata();
267 var jsonReq = {
268 AuthFlow: _this2.authenticationFlowType,
269 ClientId: _this2.pool.getClientId(),
270 AuthParameters: authParameters,
271 ClientMetadata: clientMetaData
272 };
273
274 if (_this2.getUserContextData(_this2.username)) {
275 jsonReq.UserContextData = _this2.getUserContextData(_this2.username);
276 }
277
278 _this2.client.request('InitiateAuth', jsonReq, function (err, data) {
279 if (err) {
280 return callback.onFailure(err);
281 }
282
283 var challengeParameters = data.ChallengeParameters;
284 _this2.username = challengeParameters.USER_ID_FOR_SRP;
285 serverBValue = new BigInteger(challengeParameters.SRP_B, 16);
286 salt = new BigInteger(challengeParameters.SALT, 16);
287
288 _this2.getCachedDeviceKeyAndPassword();
289
290 authenticationHelper.getPasswordAuthenticationKey(_this2.username, authDetails.getPassword(), serverBValue, salt, function (errOnHkdf, hkdf) {
291 // getPasswordAuthenticationKey callback start
292 if (errOnHkdf) {
293 callback.onFailure(errOnHkdf);
294 }
295
296 var dateNow = dateHelper.getNowString();
297 var message = CryptoJS.lib.WordArray.create(Buffer.concat([Buffer.from(_this2.pool.getUserPoolId().split('_')[1], 'utf8'), Buffer.from(_this2.username, 'utf8'), Buffer.from(challengeParameters.SECRET_BLOCK, 'base64'), Buffer.from(dateNow, 'utf8')]));
298 var key = CryptoJS.lib.WordArray.create(hkdf);
299 var signatureString = Base64.stringify(HmacSHA256(message, key));
300 var challengeResponses = {};
301 challengeResponses.USERNAME = _this2.username;
302 challengeResponses.PASSWORD_CLAIM_SECRET_BLOCK = challengeParameters.SECRET_BLOCK;
303 challengeResponses.TIMESTAMP = dateNow;
304 challengeResponses.PASSWORD_CLAIM_SIGNATURE = signatureString;
305
306 if (_this2.deviceKey != null) {
307 challengeResponses.DEVICE_KEY = _this2.deviceKey;
308 }
309
310 var respondToAuthChallenge = function respondToAuthChallenge(challenge, challengeCallback) {
311 return _this2.client.request('RespondToAuthChallenge', challenge, function (errChallenge, dataChallenge) {
312 if (errChallenge && errChallenge.code === 'ResourceNotFoundException' && errChallenge.message.toLowerCase().indexOf('device') !== -1) {
313 challengeResponses.DEVICE_KEY = null;
314 _this2.deviceKey = null;
315 _this2.randomPassword = null;
316 _this2.deviceGroupKey = null;
317
318 _this2.clearCachedDeviceKeyAndPassword();
319
320 return respondToAuthChallenge(challenge, challengeCallback);
321 }
322
323 return challengeCallback(errChallenge, dataChallenge);
324 });
325 };
326
327 var jsonReqResp = {
328 ChallengeName: 'PASSWORD_VERIFIER',
329 ClientId: _this2.pool.getClientId(),
330 ChallengeResponses: challengeResponses,
331 Session: data.Session,
332 ClientMetadata: clientMetaData
333 };
334
335 if (_this2.getUserContextData()) {
336 jsonReqResp.UserContextData = _this2.getUserContextData();
337 }
338
339 respondToAuthChallenge(jsonReqResp, function (errAuthenticate, dataAuthenticate) {
340 if (errAuthenticate) {
341 return callback.onFailure(errAuthenticate);
342 }
343
344 return _this2.authenticateUserInternal(dataAuthenticate, authenticationHelper, callback);
345 });
346 return undefined; // getPasswordAuthenticationKey callback end
347 });
348 return undefined;
349 }); // getLargeAValue callback end
350
351 });
352 }
353 /**
354 * PRIVATE ONLY: This is an internal only method and should not
355 * be directly called by the consumers.
356 * @param {AuthenticationDetails} authDetails Contains the authentication data.
357 * @param {object} callback Result callback map.
358 * @param {onFailure} callback.onFailure Called on any error.
359 * @param {mfaRequired} callback.mfaRequired MFA code
360 * required to continue.
361 * @param {authSuccess} callback.onSuccess Called on success with the new session.
362 * @returns {void}
363 */
364 ;
365
366 _proto.authenticateUserPlainUsernamePassword = function authenticateUserPlainUsernamePassword(authDetails, callback) {
367 var _this3 = this;
368
369 var authParameters = {};
370 authParameters.USERNAME = this.username;
371 authParameters.PASSWORD = authDetails.getPassword();
372
373 if (!authParameters.PASSWORD) {
374 callback.onFailure(new Error('PASSWORD parameter is required'));
375 return;
376 }
377
378 var authenticationHelper = new AuthenticationHelper(this.pool.getUserPoolId().split('_')[1]);
379 this.getCachedDeviceKeyAndPassword();
380
381 if (this.deviceKey != null) {
382 authParameters.DEVICE_KEY = this.deviceKey;
383 }
384
385 var clientMetaData = Object.keys(authDetails.getValidationData()).length !== 0 ? authDetails.getValidationData() : authDetails.getClientMetadata();
386 var jsonReq = {
387 AuthFlow: 'USER_PASSWORD_AUTH',
388 ClientId: this.pool.getClientId(),
389 AuthParameters: authParameters,
390 ClientMetadata: clientMetaData
391 };
392
393 if (this.getUserContextData(this.username)) {
394 jsonReq.UserContextData = this.getUserContextData(this.username);
395 } // USER_PASSWORD_AUTH happens in a single round-trip: client sends userName and password,
396 // Cognito UserPools verifies password and returns tokens.
397
398
399 this.client.request('InitiateAuth', jsonReq, function (err, authResult) {
400 if (err) {
401 return callback.onFailure(err);
402 }
403
404 return _this3.authenticateUserInternal(authResult, authenticationHelper, callback);
405 });
406 }
407 /**
408 * PRIVATE ONLY: This is an internal only method and should not
409 * be directly called by the consumers.
410 * @param {object} dataAuthenticate authentication data
411 * @param {object} authenticationHelper helper created
412 * @param {callback} callback passed on from caller
413 * @returns {void}
414 */
415 ;
416
417 _proto.authenticateUserInternal = function authenticateUserInternal(dataAuthenticate, authenticationHelper, callback) {
418 var _this4 = this;
419
420 var challengeName = dataAuthenticate.ChallengeName;
421 var challengeParameters = dataAuthenticate.ChallengeParameters;
422
423 if (challengeName === 'SMS_MFA') {
424 this.Session = dataAuthenticate.Session;
425 return callback.mfaRequired(challengeName, challengeParameters);
426 }
427
428 if (challengeName === 'SELECT_MFA_TYPE') {
429 this.Session = dataAuthenticate.Session;
430 return callback.selectMFAType(challengeName, challengeParameters);
431 }
432
433 if (challengeName === 'MFA_SETUP') {
434 this.Session = dataAuthenticate.Session;
435 return callback.mfaSetup(challengeName, challengeParameters);
436 }
437
438 if (challengeName === 'SOFTWARE_TOKEN_MFA') {
439 this.Session = dataAuthenticate.Session;
440 return callback.totpRequired(challengeName, challengeParameters);
441 }
442
443 if (challengeName === 'CUSTOM_CHALLENGE') {
444 this.Session = dataAuthenticate.Session;
445 return callback.customChallenge(challengeParameters);
446 }
447
448 if (challengeName === 'NEW_PASSWORD_REQUIRED') {
449 this.Session = dataAuthenticate.Session;
450 var userAttributes = null;
451 var rawRequiredAttributes = null;
452 var requiredAttributes = [];
453 var userAttributesPrefix = authenticationHelper.getNewPasswordRequiredChallengeUserAttributePrefix();
454
455 if (challengeParameters) {
456 userAttributes = JSON.parse(dataAuthenticate.ChallengeParameters.userAttributes);
457 rawRequiredAttributes = JSON.parse(dataAuthenticate.ChallengeParameters.requiredAttributes);
458 }
459
460 if (rawRequiredAttributes) {
461 for (var i = 0; i < rawRequiredAttributes.length; i++) {
462 requiredAttributes[i] = rawRequiredAttributes[i].substr(userAttributesPrefix.length);
463 }
464 }
465
466 return callback.newPasswordRequired(userAttributes, requiredAttributes);
467 }
468
469 if (challengeName === 'DEVICE_SRP_AUTH') {
470 this.getDeviceResponse(callback);
471 return undefined;
472 }
473
474 this.signInUserSession = this.getCognitoUserSession(dataAuthenticate.AuthenticationResult);
475 this.challengeName = challengeName;
476 this.cacheTokens();
477 var newDeviceMetadata = dataAuthenticate.AuthenticationResult.NewDeviceMetadata;
478
479 if (newDeviceMetadata == null) {
480 return callback.onSuccess(this.signInUserSession);
481 }
482
483 authenticationHelper.generateHashDevice(dataAuthenticate.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey, dataAuthenticate.AuthenticationResult.NewDeviceMetadata.DeviceKey, function (errGenHash) {
484 if (errGenHash) {
485 return callback.onFailure(errGenHash);
486 }
487
488 var deviceSecretVerifierConfig = {
489 Salt: Buffer.from(authenticationHelper.getSaltDevices(), 'hex').toString('base64'),
490 PasswordVerifier: Buffer.from(authenticationHelper.getVerifierDevices(), 'hex').toString('base64')
491 };
492 _this4.verifierDevices = deviceSecretVerifierConfig.PasswordVerifier;
493 _this4.deviceGroupKey = newDeviceMetadata.DeviceGroupKey;
494 _this4.randomPassword = authenticationHelper.getRandomPassword();
495
496 _this4.client.request('ConfirmDevice', {
497 DeviceKey: newDeviceMetadata.DeviceKey,
498 AccessToken: _this4.signInUserSession.getAccessToken().getJwtToken(),
499 DeviceSecretVerifierConfig: deviceSecretVerifierConfig,
500 DeviceName: userAgent
501 }, function (errConfirm, dataConfirm) {
502 if (errConfirm) {
503 return callback.onFailure(errConfirm);
504 }
505
506 _this4.deviceKey = dataAuthenticate.AuthenticationResult.NewDeviceMetadata.DeviceKey;
507
508 _this4.cacheDeviceKeyAndPassword();
509
510 if (dataConfirm.UserConfirmationNecessary === true) {
511 return callback.onSuccess(_this4.signInUserSession, dataConfirm.UserConfirmationNecessary);
512 }
513
514 return callback.onSuccess(_this4.signInUserSession);
515 });
516
517 return undefined;
518 });
519 return undefined;
520 }
521 /**
522 * This method is user to complete the NEW_PASSWORD_REQUIRED challenge.
523 * Pass the new password with any new user attributes to be updated.
524 * User attribute keys must be of format userAttributes.<attribute_name>.
525 * @param {string} newPassword new password for this user
526 * @param {object} requiredAttributeData map with values for all required attributes
527 * @param {object} callback Result callback map.
528 * @param {onFailure} callback.onFailure Called on any error.
529 * @param {mfaRequired} callback.mfaRequired MFA code required to continue.
530 * @param {customChallenge} callback.customChallenge Custom challenge
531 * response required to continue.
532 * @param {authSuccess} callback.onSuccess Called on success with the new session.
533 * @param {ClientMetadata} clientMetadata object which is passed from client to Cognito Lambda trigger
534 * @returns {void}
535 */
536 ;
537
538 _proto.completeNewPasswordChallenge = function completeNewPasswordChallenge(newPassword, requiredAttributeData, callback, clientMetadata) {
539 var _this5 = this;
540
541 if (!newPassword) {
542 return callback.onFailure(new Error('New password is required.'));
543 }
544
545 var authenticationHelper = new AuthenticationHelper(this.pool.getUserPoolId().split('_')[1]);
546 var userAttributesPrefix = authenticationHelper.getNewPasswordRequiredChallengeUserAttributePrefix();
547 var finalUserAttributes = {};
548
549 if (requiredAttributeData) {
550 Object.keys(requiredAttributeData).forEach(function (key) {
551 finalUserAttributes[userAttributesPrefix + key] = requiredAttributeData[key];
552 });
553 }
554
555 finalUserAttributes.NEW_PASSWORD = newPassword;
556 finalUserAttributes.USERNAME = this.username;
557 var jsonReq = {
558 ChallengeName: 'NEW_PASSWORD_REQUIRED',
559 ClientId: this.pool.getClientId(),
560 ChallengeResponses: finalUserAttributes,
561 Session: this.Session,
562 ClientMetadata: clientMetadata
563 };
564
565 if (this.getUserContextData()) {
566 jsonReq.UserContextData = this.getUserContextData();
567 }
568
569 this.client.request('RespondToAuthChallenge', jsonReq, function (errAuthenticate, dataAuthenticate) {
570 if (errAuthenticate) {
571 return callback.onFailure(errAuthenticate);
572 }
573
574 return _this5.authenticateUserInternal(dataAuthenticate, authenticationHelper, callback);
575 });
576 return undefined;
577 }
578 /**
579 * This is used to get a session using device authentication. It is called at the end of user
580 * authentication
581 *
582 * @param {object} callback Result callback map.
583 * @param {onFailure} callback.onFailure Called on any error.
584 * @param {authSuccess} callback.onSuccess Called on success with the new session.
585 * @param {ClientMetadata} clientMetadata object which is passed from client to Cognito Lambda trigger
586 * @returns {void}
587 * @private
588 */
589 ;
590
591 _proto.getDeviceResponse = function getDeviceResponse(callback, clientMetadata) {
592 var _this6 = this;
593
594 var authenticationHelper = new AuthenticationHelper(this.deviceGroupKey);
595 var dateHelper = new DateHelper();
596 var authParameters = {};
597 authParameters.USERNAME = this.username;
598 authParameters.DEVICE_KEY = this.deviceKey;
599 authenticationHelper.getLargeAValue(function (errAValue, aValue) {
600 // getLargeAValue callback start
601 if (errAValue) {
602 callback.onFailure(errAValue);
603 }
604
605 authParameters.SRP_A = aValue.toString(16);
606 var jsonReq = {
607 ChallengeName: 'DEVICE_SRP_AUTH',
608 ClientId: _this6.pool.getClientId(),
609 ChallengeResponses: authParameters,
610 ClientMetadata: clientMetadata
611 };
612
613 if (_this6.getUserContextData()) {
614 jsonReq.UserContextData = _this6.getUserContextData();
615 }
616
617 _this6.client.request('RespondToAuthChallenge', jsonReq, function (err, data) {
618 if (err) {
619 return callback.onFailure(err);
620 }
621
622 var challengeParameters = data.ChallengeParameters;
623 var serverBValue = new BigInteger(challengeParameters.SRP_B, 16);
624 var salt = new BigInteger(challengeParameters.SALT, 16);
625 authenticationHelper.getPasswordAuthenticationKey(_this6.deviceKey, _this6.randomPassword, serverBValue, salt, function (errHkdf, hkdf) {
626 // getPasswordAuthenticationKey callback start
627 if (errHkdf) {
628 return callback.onFailure(errHkdf);
629 }
630
631 var dateNow = dateHelper.getNowString();
632 var message = CryptoJS.lib.WordArray.create(Buffer.concat([Buffer.from(_this6.deviceGroupKey, 'utf8'), Buffer.from(_this6.deviceKey, 'utf8'), Buffer.from(challengeParameters.SECRET_BLOCK, 'base64'), Buffer.from(dateNow, 'utf8')]));
633 var key = CryptoJS.lib.WordArray.create(hkdf);
634 var signatureString = Base64.stringify(HmacSHA256(message, key));
635 var challengeResponses = {};
636 challengeResponses.USERNAME = _this6.username;
637 challengeResponses.PASSWORD_CLAIM_SECRET_BLOCK = challengeParameters.SECRET_BLOCK;
638 challengeResponses.TIMESTAMP = dateNow;
639 challengeResponses.PASSWORD_CLAIM_SIGNATURE = signatureString;
640 challengeResponses.DEVICE_KEY = _this6.deviceKey;
641 var jsonReqResp = {
642 ChallengeName: 'DEVICE_PASSWORD_VERIFIER',
643 ClientId: _this6.pool.getClientId(),
644 ChallengeResponses: challengeResponses,
645 Session: data.Session
646 };
647
648 if (_this6.getUserContextData()) {
649 jsonReqResp.UserContextData = _this6.getUserContextData();
650 }
651
652 _this6.client.request('RespondToAuthChallenge', jsonReqResp, function (errAuthenticate, dataAuthenticate) {
653 if (errAuthenticate) {
654 return callback.onFailure(errAuthenticate);
655 }
656
657 _this6.signInUserSession = _this6.getCognitoUserSession(dataAuthenticate.AuthenticationResult);
658
659 _this6.cacheTokens();
660
661 return callback.onSuccess(_this6.signInUserSession);
662 });
663
664 return undefined; // getPasswordAuthenticationKey callback end
665 });
666 return undefined;
667 }); // getLargeAValue callback end
668
669 });
670 }
671 /**
672 * This is used for a certain user to confirm the registration by using a confirmation code
673 * @param {string} confirmationCode Code entered by user.
674 * @param {bool} forceAliasCreation Allow migrating from an existing email / phone number.
675 * @param {nodeCallback<string>} callback Called on success or error.
676 * @param {ClientMetadata} clientMetadata object which is passed from client to Cognito Lambda trigger
677 * @returns {void}
678 */
679 ;
680
681 _proto.confirmRegistration = function confirmRegistration(confirmationCode, forceAliasCreation, callback, clientMetadata) {
682 var jsonReq = {
683 ClientId: this.pool.getClientId(),
684 ConfirmationCode: confirmationCode,
685 Username: this.username,
686 ForceAliasCreation: forceAliasCreation,
687 ClientMetadata: clientMetadata
688 };
689
690 if (this.getUserContextData()) {
691 jsonReq.UserContextData = this.getUserContextData();
692 }
693
694 this.client.request('ConfirmSignUp', jsonReq, function (err) {
695 if (err) {
696 return callback(err, null);
697 }
698
699 return callback(null, 'SUCCESS');
700 });
701 }
702 /**
703 * This is used by the user once he has the responses to a custom challenge
704 * @param {string} answerChallenge The custom challenge answer.
705 * @param {object} callback Result callback map.
706 * @param {onFailure} callback.onFailure Called on any error.
707 * @param {customChallenge} callback.customChallenge
708 * Custom challenge response required to continue.
709 * @param {authSuccess} callback.onSuccess Called on success with the new session.
710 * @param {ClientMetadata} clientMetadata object which is passed from client to Cognito Lambda trigger
711 * @returns {void}
712 */
713 ;
714
715 _proto.sendCustomChallengeAnswer = function sendCustomChallengeAnswer(answerChallenge, callback, clientMetadata) {
716 var _this7 = this;
717
718 var challengeResponses = {};
719 challengeResponses.USERNAME = this.username;
720 challengeResponses.ANSWER = answerChallenge;
721 var authenticationHelper = new AuthenticationHelper(this.pool.getUserPoolId().split('_')[1]);
722 this.getCachedDeviceKeyAndPassword();
723
724 if (this.deviceKey != null) {
725 challengeResponses.DEVICE_KEY = this.deviceKey;
726 }
727
728 var jsonReq = {
729 ChallengeName: 'CUSTOM_CHALLENGE',
730 ChallengeResponses: challengeResponses,
731 ClientId: this.pool.getClientId(),
732 Session: this.Session,
733 ClientMetadata: clientMetadata
734 };
735
736 if (this.getUserContextData()) {
737 jsonReq.UserContextData = this.getUserContextData();
738 }
739
740 this.client.request('RespondToAuthChallenge', jsonReq, function (err, data) {
741 if (err) {
742 return callback.onFailure(err);
743 }
744
745 return _this7.authenticateUserInternal(data, authenticationHelper, callback);
746 });
747 }
748 /**
749 * This is used by the user once he has an MFA code
750 * @param {string} confirmationCode The MFA code entered by the user.
751 * @param {object} callback Result callback map.
752 * @param {string} mfaType The mfa we are replying to.
753 * @param {onFailure} callback.onFailure Called on any error.
754 * @param {authSuccess} callback.onSuccess Called on success with the new session.
755 * @param {ClientMetadata} clientMetadata object which is passed from client to Cognito Lambda trigger
756 * @returns {void}
757 */
758 ;
759
760 _proto.sendMFACode = function sendMFACode(confirmationCode, callback, mfaType, clientMetadata) {
761 var _this8 = this;
762
763 var challengeResponses = {};
764 challengeResponses.USERNAME = this.username;
765 challengeResponses.SMS_MFA_CODE = confirmationCode;
766 var mfaTypeSelection = mfaType || 'SMS_MFA';
767
768 if (mfaTypeSelection === 'SOFTWARE_TOKEN_MFA') {
769 challengeResponses.SOFTWARE_TOKEN_MFA_CODE = confirmationCode;
770 }
771
772 if (this.deviceKey != null) {
773 challengeResponses.DEVICE_KEY = this.deviceKey;
774 }
775
776 var jsonReq = {
777 ChallengeName: mfaTypeSelection,
778 ChallengeResponses: challengeResponses,
779 ClientId: this.pool.getClientId(),
780 Session: this.Session,
781 ClientMetadata: clientMetadata
782 };
783
784 if (this.getUserContextData()) {
785 jsonReq.UserContextData = this.getUserContextData();
786 }
787
788 this.client.request('RespondToAuthChallenge', jsonReq, function (err, dataAuthenticate) {
789 if (err) {
790 return callback.onFailure(err);
791 }
792
793 var challengeName = dataAuthenticate.ChallengeName;
794
795 if (challengeName === 'DEVICE_SRP_AUTH') {
796 _this8.getDeviceResponse(callback);
797
798 return undefined;
799 }
800
801 _this8.signInUserSession = _this8.getCognitoUserSession(dataAuthenticate.AuthenticationResult);
802
803 _this8.cacheTokens();
804
805 if (dataAuthenticate.AuthenticationResult.NewDeviceMetadata == null) {
806 return callback.onSuccess(_this8.signInUserSession);
807 }
808
809 var authenticationHelper = new AuthenticationHelper(_this8.pool.getUserPoolId().split('_')[1]);
810 authenticationHelper.generateHashDevice(dataAuthenticate.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey, dataAuthenticate.AuthenticationResult.NewDeviceMetadata.DeviceKey, function (errGenHash) {
811 if (errGenHash) {
812 return callback.onFailure(errGenHash);
813 }
814
815 var deviceSecretVerifierConfig = {
816 Salt: Buffer.from(authenticationHelper.getSaltDevices(), 'hex').toString('base64'),
817 PasswordVerifier: Buffer.from(authenticationHelper.getVerifierDevices(), 'hex').toString('base64')
818 };
819 _this8.verifierDevices = deviceSecretVerifierConfig.PasswordVerifier;
820 _this8.deviceGroupKey = dataAuthenticate.AuthenticationResult.NewDeviceMetadata.DeviceGroupKey;
821 _this8.randomPassword = authenticationHelper.getRandomPassword();
822
823 _this8.client.request('ConfirmDevice', {
824 DeviceKey: dataAuthenticate.AuthenticationResult.NewDeviceMetadata.DeviceKey,
825 AccessToken: _this8.signInUserSession.getAccessToken().getJwtToken(),
826 DeviceSecretVerifierConfig: deviceSecretVerifierConfig,
827 DeviceName: userAgent
828 }, function (errConfirm, dataConfirm) {
829 if (errConfirm) {
830 return callback.onFailure(errConfirm);
831 }
832
833 _this8.deviceKey = dataAuthenticate.AuthenticationResult.NewDeviceMetadata.DeviceKey;
834
835 _this8.cacheDeviceKeyAndPassword();
836
837 if (dataConfirm.UserConfirmationNecessary === true) {
838 return callback.onSuccess(_this8.signInUserSession, dataConfirm.UserConfirmationNecessary);
839 }
840
841 return callback.onSuccess(_this8.signInUserSession);
842 });
843
844 return undefined;
845 });
846 return undefined;
847 });
848 }
849 /**
850 * This is used by an authenticated user to change the current password
851 * @param {string} oldUserPassword The current password.
852 * @param {string} newUserPassword The requested new password.
853 * @param {nodeCallback<string>} callback Called on success or error.
854 * @param {ClientMetadata} clientMetadata object which is passed from client to Cognito Lambda trigger
855 * @returns {void}
856 */
857 ;
858
859 _proto.changePassword = function changePassword(oldUserPassword, newUserPassword, callback, clientMetadata) {
860 if (!(this.signInUserSession != null && this.signInUserSession.isValid())) {
861 return callback(new Error('User is not authenticated'), null);
862 }
863
864 this.client.request('ChangePassword', {
865 PreviousPassword: oldUserPassword,
866 ProposedPassword: newUserPassword,
867 AccessToken: this.signInUserSession.getAccessToken().getJwtToken(),
868 ClientMetadata: clientMetadata
869 }, function (err) {
870 if (err) {
871 return callback(err, null);
872 }
873
874 return callback(null, 'SUCCESS');
875 });
876 return undefined;
877 }
878 /**
879 * This is used by an authenticated user to enable MFA for itself
880 * @deprecated
881 * @param {nodeCallback<string>} callback Called on success or error.
882 * @returns {void}
883 */
884 ;
885
886 _proto.enableMFA = function enableMFA(callback) {
887 if (this.signInUserSession == null || !this.signInUserSession.isValid()) {
888 return callback(new Error('User is not authenticated'), null);
889 }
890
891 var mfaOptions = [];
892 var mfaEnabled = {
893 DeliveryMedium: 'SMS',
894 AttributeName: 'phone_number'
895 };
896 mfaOptions.push(mfaEnabled);
897 this.client.request('SetUserSettings', {
898 MFAOptions: mfaOptions,
899 AccessToken: this.signInUserSession.getAccessToken().getJwtToken()
900 }, function (err) {
901 if (err) {
902 return callback(err, null);
903 }
904
905 return callback(null, 'SUCCESS');
906 });
907 return undefined;
908 }
909 /**
910 * This is used by an authenticated user to enable MFA for itself
911 * @param {IMfaSettings} smsMfaSettings the sms mfa settings
912 * @param {IMFASettings} softwareTokenMfaSettings the software token mfa settings
913 * @param {nodeCallback<string>} callback Called on success or error.
914 * @returns {void}
915 */
916 ;
917
918 _proto.setUserMfaPreference = function setUserMfaPreference(smsMfaSettings, softwareTokenMfaSettings, callback) {
919 if (this.signInUserSession == null || !this.signInUserSession.isValid()) {
920 return callback(new Error('User is not authenticated'), null);
921 }
922
923 this.client.request('SetUserMFAPreference', {
924 SMSMfaSettings: smsMfaSettings,
925 SoftwareTokenMfaSettings: softwareTokenMfaSettings,
926 AccessToken: this.signInUserSession.getAccessToken().getJwtToken()
927 }, function (err) {
928 if (err) {
929 return callback(err, null);
930 }
931
932 return callback(null, 'SUCCESS');
933 });
934 return undefined;
935 }
936 /**
937 * This is used by an authenticated user to disable MFA for itself
938 * @deprecated
939 * @param {nodeCallback<string>} callback Called on success or error.
940 * @returns {void}
941 */
942 ;
943
944 _proto.disableMFA = function disableMFA(callback) {
945 if (this.signInUserSession == null || !this.signInUserSession.isValid()) {
946 return callback(new Error('User is not authenticated'), null);
947 }
948
949 var mfaOptions = [];
950 this.client.request('SetUserSettings', {
951 MFAOptions: mfaOptions,
952 AccessToken: this.signInUserSession.getAccessToken().getJwtToken()
953 }, function (err) {
954 if (err) {
955 return callback(err, null);
956 }
957
958 return callback(null, 'SUCCESS');
959 });
960 return undefined;
961 }
962 /**
963 * This is used by an authenticated user to delete itself
964 * @param {nodeCallback<string>} callback Called on success or error.
965 * @param {ClientMetadata} clientMetadata object which is passed from client to Cognito Lambda trigger
966 * @returns {void}
967 */
968 ;
969
970 _proto.deleteUser = function deleteUser(callback, clientMetadata) {
971 var _this9 = this;
972
973 if (this.signInUserSession == null || !this.signInUserSession.isValid()) {
974 return callback(new Error('User is not authenticated'), null);
975 }
976
977 this.client.request('DeleteUser', {
978 AccessToken: this.signInUserSession.getAccessToken().getJwtToken(),
979 ClientMetadata: clientMetadata
980 }, function (err) {
981 if (err) {
982 return callback(err, null);
983 }
984
985 _this9.clearCachedUser();
986
987 return callback(null, 'SUCCESS');
988 });
989 return undefined;
990 }
991 /**
992 * @typedef {CognitoUserAttribute | { Name:string, Value:string }} AttributeArg
993 */
994
995 /**
996 * This is used by an authenticated user to change a list of attributes
997 * @param {AttributeArg[]} attributes A list of the new user attributes.
998 * @param {nodeCallback<string>} callback Called on success or error.
999 * @param {ClientMetadata} clientMetadata object which is passed from client to Cognito Lambda trigger
1000 * @returns {void}
1001 */
1002 ;
1003
1004 _proto.updateAttributes = function updateAttributes(attributes, callback, clientMetadata) {
1005 var _this10 = this;
1006
1007 if (this.signInUserSession == null || !this.signInUserSession.isValid()) {
1008 return callback(new Error('User is not authenticated'), null);
1009 }
1010
1011 this.client.request('UpdateUserAttributes', {
1012 AccessToken: this.signInUserSession.getAccessToken().getJwtToken(),
1013 UserAttributes: attributes,
1014 ClientMetadata: clientMetadata
1015 }, function (err) {
1016 if (err) {
1017 return callback(err, null);
1018 } // update cached user
1019
1020
1021 return _this10.getUserData(function () {
1022 return callback(null, 'SUCCESS');
1023 }, {
1024 bypassCache: true
1025 });
1026 });
1027 return undefined;
1028 }
1029 /**
1030 * This is used by an authenticated user to get a list of attributes
1031 * @param {nodeCallback<CognitoUserAttribute[]>} callback Called on success or error.
1032 * @returns {void}
1033 */
1034 ;
1035
1036 _proto.getUserAttributes = function getUserAttributes(callback) {
1037 if (!(this.signInUserSession != null && this.signInUserSession.isValid())) {
1038 return callback(new Error('User is not authenticated'), null);
1039 }
1040
1041 this.client.request('GetUser', {
1042 AccessToken: this.signInUserSession.getAccessToken().getJwtToken()
1043 }, function (err, userData) {
1044 if (err) {
1045 return callback(err, null);
1046 }
1047
1048 var attributeList = [];
1049
1050 for (var i = 0; i < userData.UserAttributes.length; i++) {
1051 var attribute = {
1052 Name: userData.UserAttributes[i].Name,
1053 Value: userData.UserAttributes[i].Value
1054 };
1055 var userAttribute = new CognitoUserAttribute(attribute);
1056 attributeList.push(userAttribute);
1057 }
1058
1059 return callback(null, attributeList);
1060 });
1061 return undefined;
1062 }
1063 /**
1064 * This is used by an authenticated user to get the MFAOptions
1065 * @param {nodeCallback<MFAOptions>} callback Called on success or error.
1066 * @returns {void}
1067 */
1068 ;
1069
1070 _proto.getMFAOptions = function getMFAOptions(callback) {
1071 if (!(this.signInUserSession != null && this.signInUserSession.isValid())) {
1072 return callback(new Error('User is not authenticated'), null);
1073 }
1074
1075 this.client.request('GetUser', {
1076 AccessToken: this.signInUserSession.getAccessToken().getJwtToken()
1077 }, function (err, userData) {
1078 if (err) {
1079 return callback(err, null);
1080 }
1081
1082 return callback(null, userData.MFAOptions);
1083 });
1084 return undefined;
1085 }
1086 /**
1087 * PRIVATE ONLY: This is an internal only method and should not
1088 * be directly called by the consumers.
1089 */
1090 ;
1091
1092 _proto.createGetUserRequest = function createGetUserRequest() {
1093 return this.client.promisifyRequest('GetUser', {
1094 AccessToken: this.signInUserSession.getAccessToken().getJwtToken()
1095 });
1096 }
1097 /**
1098 * PRIVATE ONLY: This is an internal only method and should not
1099 * be directly called by the consumers.
1100 */
1101 ;
1102
1103 _proto.refreshSessionIfPossible = function refreshSessionIfPossible(options) {
1104 var _this11 = this;
1105
1106 if (options === void 0) {
1107 options = {};
1108 }
1109
1110 // best effort, if not possible
1111 return new Promise(function (resolve) {
1112 var refresh = _this11.signInUserSession.getRefreshToken();
1113
1114 if (refresh && refresh.getToken()) {
1115 _this11.refreshSession(refresh, resolve, options.clientMetadata);
1116 } else {
1117 resolve();
1118 }
1119 });
1120 }
1121 /**
1122 * @typedef {Object} GetUserDataOptions
1123 * @property {boolean} bypassCache - force getting data from Cognito service
1124 * @property {Record<string, string>} clientMetadata - clientMetadata for getSession
1125 */
1126
1127 /**
1128 * This is used by an authenticated users to get the userData
1129 * @param {nodeCallback<UserData>} callback Called on success or error.
1130 * @param {GetUserDataOptions} params
1131 * @returns {void}
1132 */
1133 ;
1134
1135 _proto.getUserData = function getUserData(callback, params) {
1136 var _this12 = this;
1137
1138 if (!(this.signInUserSession != null && this.signInUserSession.isValid())) {
1139 this.clearCachedUserData();
1140 return callback(new Error('User is not authenticated'), null);
1141 }
1142
1143 var userData = this.getUserDataFromCache();
1144
1145 if (!userData) {
1146 this.fetchUserData().then(function (data) {
1147 callback(null, data);
1148 })["catch"](callback);
1149 return;
1150 }
1151
1152 if (this.isFetchUserDataAndTokenRequired(params)) {
1153 this.fetchUserData().then(function (data) {
1154 return _this12.refreshSessionIfPossible(params).then(function () {
1155 return data;
1156 });
1157 }).then(function (data) {
1158 return callback(null, data);
1159 })["catch"](callback);
1160 return;
1161 }
1162
1163 try {
1164 callback(null, JSON.parse(userData));
1165 return;
1166 } catch (err) {
1167 this.clearCachedUserData();
1168 callback(err, null);
1169 return;
1170 }
1171 }
1172 /**
1173 *
1174 * PRIVATE ONLY: This is an internal only method and should not
1175 * be directly called by the consumers.
1176 */
1177 ;
1178
1179 _proto.getUserDataFromCache = function getUserDataFromCache() {
1180 var userData = this.storage.getItem(this.userDataKey);
1181 return userData;
1182 }
1183 /**
1184 *
1185 * PRIVATE ONLY: This is an internal only method and should not
1186 * be directly called by the consumers.
1187 */
1188 ;
1189
1190 _proto.isFetchUserDataAndTokenRequired = function isFetchUserDataAndTokenRequired(params) {
1191 var _ref = params || {},
1192 _ref$bypassCache = _ref.bypassCache,
1193 bypassCache = _ref$bypassCache === void 0 ? false : _ref$bypassCache;
1194
1195 return bypassCache;
1196 }
1197 /**
1198 *
1199 * PRIVATE ONLY: This is an internal only method and should not
1200 * be directly called by the consumers.
1201 */
1202 ;
1203
1204 _proto.fetchUserData = function fetchUserData() {
1205 var _this13 = this;
1206
1207 return this.createGetUserRequest().then(function (data) {
1208 _this13.cacheUserData(data);
1209
1210 return data;
1211 });
1212 }
1213 /**
1214 * This is used by an authenticated user to delete a list of attributes
1215 * @param {string[]} attributeList Names of the attributes to delete.
1216 * @param {nodeCallback<string>} callback Called on success or error.
1217 * @returns {void}
1218 */
1219 ;
1220
1221 _proto.deleteAttributes = function deleteAttributes(attributeList, callback) {
1222 if (!(this.signInUserSession != null && this.signInUserSession.isValid())) {
1223 return callback(new Error('User is not authenticated'), null);
1224 }
1225
1226 this.client.request('DeleteUserAttributes', {
1227 UserAttributeNames: attributeList,
1228 AccessToken: this.signInUserSession.getAccessToken().getJwtToken()
1229 }, function (err) {
1230 if (err) {
1231 return callback(err, null);
1232 }
1233
1234 return callback(null, 'SUCCESS');
1235 });
1236 return undefined;
1237 }
1238 /**
1239 * This is used by a user to resend a confirmation code
1240 * @param {nodeCallback<string>} callback Called on success or error.
1241 * @param {ClientMetadata} clientMetadata object which is passed from client to Cognito Lambda trigger
1242 * @returns {void}
1243 */
1244 ;
1245
1246 _proto.resendConfirmationCode = function resendConfirmationCode(callback, clientMetadata) {
1247 var jsonReq = {
1248 ClientId: this.pool.getClientId(),
1249 Username: this.username,
1250 ClientMetadata: clientMetadata
1251 };
1252 this.client.request('ResendConfirmationCode', jsonReq, function (err, result) {
1253 if (err) {
1254 return callback(err, null);
1255 }
1256
1257 return callback(null, result);
1258 });
1259 }
1260 /**
1261 * @typedef {Object} GetSessionOptions
1262 * @property {Record<string, string>} clientMetadata - clientMetadata for getSession
1263 */
1264
1265 /**
1266 * This is used to get a session, either from the session object
1267 * or from the local storage, or by using a refresh token
1268 *
1269 * @param {nodeCallback<CognitoUserSession>} callback Called on success or error.
1270 * @param {GetSessionOptions} options
1271 * @returns {void}
1272 */
1273 ;
1274
1275 _proto.getSession = function getSession(callback, options) {
1276 if (this.username == null) {
1277 return callback(new Error('Username is null. Cannot retrieve a new session'), null);
1278 }
1279
1280 if (this.signInUserSession != null && this.signInUserSession.isValid()) {
1281 return callback(null, this.signInUserSession);
1282 }
1283
1284 var keyPrefix = "CognitoIdentityServiceProvider." + this.pool.getClientId() + "." + this.username;
1285 var idTokenKey = keyPrefix + ".idToken";
1286 var accessTokenKey = keyPrefix + ".accessToken";
1287 var refreshTokenKey = keyPrefix + ".refreshToken";
1288 var clockDriftKey = keyPrefix + ".clockDrift";
1289
1290 if (this.storage.getItem(idTokenKey)) {
1291 var idToken = new CognitoIdToken({
1292 IdToken: this.storage.getItem(idTokenKey)
1293 });
1294 var accessToken = new CognitoAccessToken({
1295 AccessToken: this.storage.getItem(accessTokenKey)
1296 });
1297 var refreshToken = new CognitoRefreshToken({
1298 RefreshToken: this.storage.getItem(refreshTokenKey)
1299 });
1300 var clockDrift = parseInt(this.storage.getItem(clockDriftKey), 0) || 0;
1301 var sessionData = {
1302 IdToken: idToken,
1303 AccessToken: accessToken,
1304 RefreshToken: refreshToken,
1305 ClockDrift: clockDrift
1306 };
1307 var cachedSession = new CognitoUserSession(sessionData);
1308
1309 if (cachedSession.isValid()) {
1310 this.signInUserSession = cachedSession;
1311 return callback(null, this.signInUserSession);
1312 }
1313
1314 if (!refreshToken.getToken()) {
1315 return callback(new Error('Cannot retrieve a new session. Please authenticate.'), null);
1316 }
1317
1318 this.refreshSession(refreshToken, callback, options.clientMetadata);
1319 } else {
1320 callback(new Error('Local storage is missing an ID Token, Please authenticate'), null);
1321 }
1322
1323 return undefined;
1324 }
1325 /**
1326 * This uses the refreshToken to retrieve a new session
1327 * @param {CognitoRefreshToken} refreshToken A previous session's refresh token.
1328 * @param {nodeCallback<CognitoUserSession>} callback Called on success or error.
1329 * @param {ClientMetadata} clientMetadata object which is passed from client to Cognito Lambda trigger
1330 * @returns {void}
1331 */
1332 ;
1333
1334 _proto.refreshSession = function refreshSession(refreshToken, callback, clientMetadata) {
1335 var _this14 = this;
1336
1337 var wrappedCallback = this.pool.wrapRefreshSessionCallback ? this.pool.wrapRefreshSessionCallback(callback) : callback;
1338 var authParameters = {};
1339 authParameters.REFRESH_TOKEN = refreshToken.getToken();
1340 var keyPrefix = "CognitoIdentityServiceProvider." + this.pool.getClientId();
1341 var lastUserKey = keyPrefix + ".LastAuthUser";
1342
1343 if (this.storage.getItem(lastUserKey)) {
1344 this.username = this.storage.getItem(lastUserKey);
1345 var deviceKeyKey = keyPrefix + "." + this.username + ".deviceKey";
1346 this.deviceKey = this.storage.getItem(deviceKeyKey);
1347 authParameters.DEVICE_KEY = this.deviceKey;
1348 }
1349
1350 var jsonReq = {
1351 ClientId: this.pool.getClientId(),
1352 AuthFlow: 'REFRESH_TOKEN_AUTH',
1353 AuthParameters: authParameters,
1354 ClientMetadata: clientMetadata
1355 };
1356
1357 if (this.getUserContextData()) {
1358 jsonReq.UserContextData = this.getUserContextData();
1359 }
1360
1361 this.client.request('InitiateAuth', jsonReq, function (err, authResult) {
1362 if (err) {
1363 if (err.code === 'NotAuthorizedException') {
1364 _this14.clearCachedUser();
1365 }
1366
1367 return wrappedCallback(err, null);
1368 }
1369
1370 if (authResult) {
1371 var authenticationResult = authResult.AuthenticationResult;
1372
1373 if (!Object.prototype.hasOwnProperty.call(authenticationResult, 'RefreshToken')) {
1374 authenticationResult.RefreshToken = refreshToken.getToken();
1375 }
1376
1377 _this14.signInUserSession = _this14.getCognitoUserSession(authenticationResult);
1378
1379 _this14.cacheTokens();
1380
1381 return wrappedCallback(null, _this14.signInUserSession);
1382 }
1383
1384 return undefined;
1385 });
1386 }
1387 /**
1388 * This is used to save the session tokens to local storage
1389 * @returns {void}
1390 */
1391 ;
1392
1393 _proto.cacheTokens = function cacheTokens() {
1394 var keyPrefix = "CognitoIdentityServiceProvider." + this.pool.getClientId();
1395 var idTokenKey = keyPrefix + "." + this.username + ".idToken";
1396 var accessTokenKey = keyPrefix + "." + this.username + ".accessToken";
1397 var refreshTokenKey = keyPrefix + "." + this.username + ".refreshToken";
1398 var clockDriftKey = keyPrefix + "." + this.username + ".clockDrift";
1399 var lastUserKey = keyPrefix + ".LastAuthUser";
1400 this.storage.setItem(idTokenKey, this.signInUserSession.getIdToken().getJwtToken());
1401 this.storage.setItem(accessTokenKey, this.signInUserSession.getAccessToken().getJwtToken());
1402 this.storage.setItem(refreshTokenKey, this.signInUserSession.getRefreshToken().getToken());
1403 this.storage.setItem(clockDriftKey, "" + this.signInUserSession.getClockDrift());
1404 this.storage.setItem(lastUserKey, this.username);
1405 }
1406 /**
1407 * This is to cache user data
1408 */
1409 ;
1410
1411 _proto.cacheUserData = function cacheUserData(userData) {
1412 this.storage.setItem(this.userDataKey, JSON.stringify(userData));
1413 }
1414 /**
1415 * This is to remove cached user data
1416 */
1417 ;
1418
1419 _proto.clearCachedUserData = function clearCachedUserData() {
1420 this.storage.removeItem(this.userDataKey);
1421 };
1422
1423 _proto.clearCachedUser = function clearCachedUser() {
1424 this.clearCachedTokens();
1425 this.clearCachedUserData();
1426 }
1427 /**
1428 * This is used to cache the device key and device group and device password
1429 * @returns {void}
1430 */
1431 ;
1432
1433 _proto.cacheDeviceKeyAndPassword = function cacheDeviceKeyAndPassword() {
1434 var keyPrefix = "CognitoIdentityServiceProvider." + this.pool.getClientId() + "." + this.username;
1435 var deviceKeyKey = keyPrefix + ".deviceKey";
1436 var randomPasswordKey = keyPrefix + ".randomPasswordKey";
1437 var deviceGroupKeyKey = keyPrefix + ".deviceGroupKey";
1438 this.storage.setItem(deviceKeyKey, this.deviceKey);
1439 this.storage.setItem(randomPasswordKey, this.randomPassword);
1440 this.storage.setItem(deviceGroupKeyKey, this.deviceGroupKey);
1441 }
1442 /**
1443 * This is used to get current device key and device group and device password
1444 * @returns {void}
1445 */
1446 ;
1447
1448 _proto.getCachedDeviceKeyAndPassword = function getCachedDeviceKeyAndPassword() {
1449 var keyPrefix = "CognitoIdentityServiceProvider." + this.pool.getClientId() + "." + this.username;
1450 var deviceKeyKey = keyPrefix + ".deviceKey";
1451 var randomPasswordKey = keyPrefix + ".randomPasswordKey";
1452 var deviceGroupKeyKey = keyPrefix + ".deviceGroupKey";
1453
1454 if (this.storage.getItem(deviceKeyKey)) {
1455 this.deviceKey = this.storage.getItem(deviceKeyKey);
1456 this.randomPassword = this.storage.getItem(randomPasswordKey);
1457 this.deviceGroupKey = this.storage.getItem(deviceGroupKeyKey);
1458 }
1459 }
1460 /**
1461 * This is used to clear the device key info from local storage
1462 * @returns {void}
1463 */
1464 ;
1465
1466 _proto.clearCachedDeviceKeyAndPassword = function clearCachedDeviceKeyAndPassword() {
1467 var keyPrefix = "CognitoIdentityServiceProvider." + this.pool.getClientId() + "." + this.username;
1468 var deviceKeyKey = keyPrefix + ".deviceKey";
1469 var randomPasswordKey = keyPrefix + ".randomPasswordKey";
1470 var deviceGroupKeyKey = keyPrefix + ".deviceGroupKey";
1471 this.storage.removeItem(deviceKeyKey);
1472 this.storage.removeItem(randomPasswordKey);
1473 this.storage.removeItem(deviceGroupKeyKey);
1474 }
1475 /**
1476 * This is used to clear the session tokens from local storage
1477 * @returns {void}
1478 */
1479 ;
1480
1481 _proto.clearCachedTokens = function clearCachedTokens() {
1482 var keyPrefix = "CognitoIdentityServiceProvider." + this.pool.getClientId();
1483 var idTokenKey = keyPrefix + "." + this.username + ".idToken";
1484 var accessTokenKey = keyPrefix + "." + this.username + ".accessToken";
1485 var refreshTokenKey = keyPrefix + "." + this.username + ".refreshToken";
1486 var lastUserKey = keyPrefix + ".LastAuthUser";
1487 var clockDriftKey = keyPrefix + "." + this.username + ".clockDrift";
1488 this.storage.removeItem(idTokenKey);
1489 this.storage.removeItem(accessTokenKey);
1490 this.storage.removeItem(refreshTokenKey);
1491 this.storage.removeItem(lastUserKey);
1492 this.storage.removeItem(clockDriftKey);
1493 }
1494 /**
1495 * This is used to build a user session from tokens retrieved in the authentication result
1496 * @param {object} authResult Successful auth response from server.
1497 * @returns {CognitoUserSession} The new user session.
1498 * @private
1499 */
1500 ;
1501
1502 _proto.getCognitoUserSession = function getCognitoUserSession(authResult) {
1503 var idToken = new CognitoIdToken(authResult);
1504 var accessToken = new CognitoAccessToken(authResult);
1505 var refreshToken = new CognitoRefreshToken(authResult);
1506 var sessionData = {
1507 IdToken: idToken,
1508 AccessToken: accessToken,
1509 RefreshToken: refreshToken
1510 };
1511 return new CognitoUserSession(sessionData);
1512 }
1513 /**
1514 * This is used to initiate a forgot password request
1515 * @param {object} callback Result callback map.
1516 * @param {onFailure} callback.onFailure Called on any error.
1517 * @param {inputVerificationCode?} callback.inputVerificationCode
1518 * Optional callback raised instead of onSuccess with response data.
1519 * @param {onSuccess} callback.onSuccess Called on success.
1520 * @param {ClientMetadata} clientMetadata object which is passed from client to Cognito Lambda trigger
1521 * @returns {void}
1522 */
1523 ;
1524
1525 _proto.forgotPassword = function forgotPassword(callback, clientMetadata) {
1526 var jsonReq = {
1527 ClientId: this.pool.getClientId(),
1528 Username: this.username,
1529 ClientMetadata: clientMetadata
1530 };
1531
1532 if (this.getUserContextData()) {
1533 jsonReq.UserContextData = this.getUserContextData();
1534 }
1535
1536 this.client.request('ForgotPassword', jsonReq, function (err, data) {
1537 if (err) {
1538 return callback.onFailure(err);
1539 }
1540
1541 if (typeof callback.inputVerificationCode === 'function') {
1542 return callback.inputVerificationCode(data);
1543 }
1544
1545 return callback.onSuccess(data);
1546 });
1547 }
1548 /**
1549 * This is used to confirm a new password using a confirmationCode
1550 * @param {string} confirmationCode Code entered by user.
1551 * @param {string} newPassword Confirm new password.
1552 * @param {object} callback Result callback map.
1553 * @param {onFailure} callback.onFailure Called on any error.
1554 * @param {onSuccess<void>} callback.onSuccess Called on success.
1555 * @param {ClientMetadata} clientMetadata object which is passed from client to Cognito Lambda trigger
1556 * @returns {void}
1557 */
1558 ;
1559
1560 _proto.confirmPassword = function confirmPassword(confirmationCode, newPassword, callback, clientMetadata) {
1561 var jsonReq = {
1562 ClientId: this.pool.getClientId(),
1563 Username: this.username,
1564 ConfirmationCode: confirmationCode,
1565 Password: newPassword,
1566 ClientMetadata: clientMetadata
1567 };
1568
1569 if (this.getUserContextData()) {
1570 jsonReq.UserContextData = this.getUserContextData();
1571 }
1572
1573 this.client.request('ConfirmForgotPassword', jsonReq, function (err) {
1574 if (err) {
1575 return callback.onFailure(err);
1576 }
1577
1578 return callback.onSuccess();
1579 });
1580 }
1581 /**
1582 * This is used to initiate an attribute confirmation request
1583 * @param {string} attributeName User attribute that needs confirmation.
1584 * @param {object} callback Result callback map.
1585 * @param {onFailure} callback.onFailure Called on any error.
1586 * @param {inputVerificationCode} callback.inputVerificationCode Called on success.
1587 * @param {ClientMetadata} clientMetadata object which is passed from client to Cognito Lambda trigger
1588 * @returns {void}
1589 */
1590 ;
1591
1592 _proto.getAttributeVerificationCode = function getAttributeVerificationCode(attributeName, callback, clientMetadata) {
1593 if (this.signInUserSession == null || !this.signInUserSession.isValid()) {
1594 return callback.onFailure(new Error('User is not authenticated'));
1595 }
1596
1597 this.client.request('GetUserAttributeVerificationCode', {
1598 AttributeName: attributeName,
1599 AccessToken: this.signInUserSession.getAccessToken().getJwtToken(),
1600 ClientMetadata: clientMetadata
1601 }, function (err, data) {
1602 if (err) {
1603 return callback.onFailure(err);
1604 }
1605
1606 if (typeof callback.inputVerificationCode === 'function') {
1607 return callback.inputVerificationCode(data);
1608 }
1609
1610 return callback.onSuccess();
1611 });
1612 return undefined;
1613 }
1614 /**
1615 * This is used to confirm an attribute using a confirmation code
1616 * @param {string} attributeName Attribute being confirmed.
1617 * @param {string} confirmationCode Code entered by user.
1618 * @param {object} callback Result callback map.
1619 * @param {onFailure} callback.onFailure Called on any error.
1620 * @param {onSuccess<string>} callback.onSuccess Called on success.
1621 * @returns {void}
1622 */
1623 ;
1624
1625 _proto.verifyAttribute = function verifyAttribute(attributeName, confirmationCode, callback) {
1626 if (this.signInUserSession == null || !this.signInUserSession.isValid()) {
1627 return callback.onFailure(new Error('User is not authenticated'));
1628 }
1629
1630 this.client.request('VerifyUserAttribute', {
1631 AttributeName: attributeName,
1632 Code: confirmationCode,
1633 AccessToken: this.signInUserSession.getAccessToken().getJwtToken()
1634 }, function (err) {
1635 if (err) {
1636 return callback.onFailure(err);
1637 }
1638
1639 return callback.onSuccess('SUCCESS');
1640 });
1641 return undefined;
1642 }
1643 /**
1644 * This is used to get the device information using the current device key
1645 * @param {object} callback Result callback map.
1646 * @param {onFailure} callback.onFailure Called on any error.
1647 * @param {onSuccess<*>} callback.onSuccess Called on success with device data.
1648 * @returns {void}
1649 */
1650 ;
1651
1652 _proto.getDevice = function getDevice(callback) {
1653 if (this.signInUserSession == null || !this.signInUserSession.isValid()) {
1654 return callback.onFailure(new Error('User is not authenticated'));
1655 }
1656
1657 this.client.request('GetDevice', {
1658 AccessToken: this.signInUserSession.getAccessToken().getJwtToken(),
1659 DeviceKey: this.deviceKey
1660 }, function (err, data) {
1661 if (err) {
1662 return callback.onFailure(err);
1663 }
1664
1665 return callback.onSuccess(data);
1666 });
1667 return undefined;
1668 }
1669 /**
1670 * This is used to forget a specific device
1671 * @param {string} deviceKey Device key.
1672 * @param {object} callback Result callback map.
1673 * @param {onFailure} callback.onFailure Called on any error.
1674 * @param {onSuccess<string>} callback.onSuccess Called on success.
1675 * @returns {void}
1676 */
1677 ;
1678
1679 _proto.forgetSpecificDevice = function forgetSpecificDevice(deviceKey, callback) {
1680 if (this.signInUserSession == null || !this.signInUserSession.isValid()) {
1681 return callback.onFailure(new Error('User is not authenticated'));
1682 }
1683
1684 this.client.request('ForgetDevice', {
1685 AccessToken: this.signInUserSession.getAccessToken().getJwtToken(),
1686 DeviceKey: deviceKey
1687 }, function (err) {
1688 if (err) {
1689 return callback.onFailure(err);
1690 }
1691
1692 return callback.onSuccess('SUCCESS');
1693 });
1694 return undefined;
1695 }
1696 /**
1697 * This is used to forget the current device
1698 * @param {object} callback Result callback map.
1699 * @param {onFailure} callback.onFailure Called on any error.
1700 * @param {onSuccess<string>} callback.onSuccess Called on success.
1701 * @returns {void}
1702 */
1703 ;
1704
1705 _proto.forgetDevice = function forgetDevice(callback) {
1706 var _this15 = this;
1707
1708 this.forgetSpecificDevice(this.deviceKey, {
1709 onFailure: callback.onFailure,
1710 onSuccess: function onSuccess(result) {
1711 _this15.deviceKey = null;
1712 _this15.deviceGroupKey = null;
1713 _this15.randomPassword = null;
1714
1715 _this15.clearCachedDeviceKeyAndPassword();
1716
1717 return callback.onSuccess(result);
1718 }
1719 });
1720 }
1721 /**
1722 * This is used to set the device status as remembered
1723 * @param {object} callback Result callback map.
1724 * @param {onFailure} callback.onFailure Called on any error.
1725 * @param {onSuccess<string>} callback.onSuccess Called on success.
1726 * @returns {void}
1727 */
1728 ;
1729
1730 _proto.setDeviceStatusRemembered = function setDeviceStatusRemembered(callback) {
1731 if (this.signInUserSession == null || !this.signInUserSession.isValid()) {
1732 return callback.onFailure(new Error('User is not authenticated'));
1733 }
1734
1735 this.client.request('UpdateDeviceStatus', {
1736 AccessToken: this.signInUserSession.getAccessToken().getJwtToken(),
1737 DeviceKey: this.deviceKey,
1738 DeviceRememberedStatus: 'remembered'
1739 }, function (err) {
1740 if (err) {
1741 return callback.onFailure(err);
1742 }
1743
1744 return callback.onSuccess('SUCCESS');
1745 });
1746 return undefined;
1747 }
1748 /**
1749 * This is used to set the device status as not remembered
1750 * @param {object} callback Result callback map.
1751 * @param {onFailure} callback.onFailure Called on any error.
1752 * @param {onSuccess<string>} callback.onSuccess Called on success.
1753 * @returns {void}
1754 */
1755 ;
1756
1757 _proto.setDeviceStatusNotRemembered = function setDeviceStatusNotRemembered(callback) {
1758 if (this.signInUserSession == null || !this.signInUserSession.isValid()) {
1759 return callback.onFailure(new Error('User is not authenticated'));
1760 }
1761
1762 this.client.request('UpdateDeviceStatus', {
1763 AccessToken: this.signInUserSession.getAccessToken().getJwtToken(),
1764 DeviceKey: this.deviceKey,
1765 DeviceRememberedStatus: 'not_remembered'
1766 }, function (err) {
1767 if (err) {
1768 return callback.onFailure(err);
1769 }
1770
1771 return callback.onSuccess('SUCCESS');
1772 });
1773 return undefined;
1774 }
1775 /**
1776 * This is used to list all devices for a user
1777 *
1778 * @param {int} limit the number of devices returned in a call
1779 * @param {string | null} paginationToken the pagination token in case any was returned before
1780 * @param {object} callback Result callback map.
1781 * @param {onFailure} callback.onFailure Called on any error.
1782 * @param {onSuccess<*>} callback.onSuccess Called on success with device list.
1783 * @returns {void}
1784 */
1785 ;
1786
1787 _proto.listDevices = function listDevices(limit, paginationToken, callback) {
1788 if (this.signInUserSession == null || !this.signInUserSession.isValid()) {
1789 return callback.onFailure(new Error('User is not authenticated'));
1790 }
1791
1792 var requestParams = {
1793 AccessToken: this.signInUserSession.getAccessToken().getJwtToken(),
1794 Limit: limit
1795 };
1796
1797 if (paginationToken) {
1798 requestParams.PaginationToken = paginationToken;
1799 }
1800
1801 this.client.request('ListDevices', requestParams, function (err, data) {
1802 if (err) {
1803 return callback.onFailure(err);
1804 }
1805
1806 return callback.onSuccess(data);
1807 });
1808 return undefined;
1809 }
1810 /**
1811 * This is used to globally revoke all tokens issued to a user
1812 * @param {object} callback Result callback map.
1813 * @param {onFailure} callback.onFailure Called on any error.
1814 * @param {onSuccess<string>} callback.onSuccess Called on success.
1815 * @returns {void}
1816 */
1817 ;
1818
1819 _proto.globalSignOut = function globalSignOut(callback) {
1820 var _this16 = this;
1821
1822 if (this.signInUserSession == null || !this.signInUserSession.isValid()) {
1823 return callback.onFailure(new Error('User is not authenticated'));
1824 }
1825
1826 this.client.request('GlobalSignOut', {
1827 AccessToken: this.signInUserSession.getAccessToken().getJwtToken()
1828 }, function (err) {
1829 if (err) {
1830 return callback.onFailure(err);
1831 }
1832
1833 _this16.clearCachedUser();
1834
1835 return callback.onSuccess('SUCCESS');
1836 });
1837 return undefined;
1838 }
1839 /**
1840 * This is used for the user to signOut of the application and clear the cached tokens.
1841 * @returns {void}
1842 */
1843 ;
1844
1845 _proto.signOut = function signOut() {
1846 this.signInUserSession = null;
1847 this.clearCachedUser();
1848 }
1849 /**
1850 * This is used by a user trying to select a given MFA
1851 * @param {string} answerChallenge the mfa the user wants
1852 * @param {nodeCallback<string>} callback Called on success or error.
1853 * @returns {void}
1854 */
1855 ;
1856
1857 _proto.sendMFASelectionAnswer = function sendMFASelectionAnswer(answerChallenge, callback) {
1858 var _this17 = this;
1859
1860 var challengeResponses = {};
1861 challengeResponses.USERNAME = this.username;
1862 challengeResponses.ANSWER = answerChallenge;
1863 var jsonReq = {
1864 ChallengeName: 'SELECT_MFA_TYPE',
1865 ChallengeResponses: challengeResponses,
1866 ClientId: this.pool.getClientId(),
1867 Session: this.Session
1868 };
1869
1870 if (this.getUserContextData()) {
1871 jsonReq.UserContextData = this.getUserContextData();
1872 }
1873
1874 this.client.request('RespondToAuthChallenge', jsonReq, function (err, data) {
1875 if (err) {
1876 return callback.onFailure(err);
1877 }
1878
1879 _this17.Session = data.Session;
1880
1881 if (answerChallenge === 'SMS_MFA') {
1882 return callback.mfaRequired(data.ChallengeName, data.ChallengeParameters);
1883 }
1884
1885 if (answerChallenge === 'SOFTWARE_TOKEN_MFA') {
1886 return callback.totpRequired(data.ChallengeName, data.ChallengeParameters);
1887 }
1888
1889 return undefined;
1890 });
1891 }
1892 /**
1893 * This returns the user context data for advanced security feature.
1894 * @returns {void}
1895 */
1896 ;
1897
1898 _proto.getUserContextData = function getUserContextData() {
1899 var pool = this.pool;
1900 return pool.getUserContextData(this.username);
1901 }
1902 /**
1903 * This is used by an authenticated or a user trying to authenticate to associate a TOTP MFA
1904 * @param {nodeCallback<string>} callback Called on success or error.
1905 * @returns {void}
1906 */
1907 ;
1908
1909 _proto.associateSoftwareToken = function associateSoftwareToken(callback) {
1910 var _this18 = this;
1911
1912 if (!(this.signInUserSession != null && this.signInUserSession.isValid())) {
1913 this.client.request('AssociateSoftwareToken', {
1914 Session: this.Session
1915 }, function (err, data) {
1916 if (err) {
1917 return callback.onFailure(err);
1918 }
1919
1920 _this18.Session = data.Session;
1921 return callback.associateSecretCode(data.SecretCode);
1922 });
1923 } else {
1924 this.client.request('AssociateSoftwareToken', {
1925 AccessToken: this.signInUserSession.getAccessToken().getJwtToken()
1926 }, function (err, data) {
1927 if (err) {
1928 return callback.onFailure(err);
1929 }
1930
1931 return callback.associateSecretCode(data.SecretCode);
1932 });
1933 }
1934 }
1935 /**
1936 * This is used by an authenticated or a user trying to authenticate to verify a TOTP MFA
1937 * @param {string} totpCode The MFA code entered by the user.
1938 * @param {string} friendlyDeviceName The device name we are assigning to the device.
1939 * @param {nodeCallback<string>} callback Called on success or error.
1940 * @returns {void}
1941 */
1942 ;
1943
1944 _proto.verifySoftwareToken = function verifySoftwareToken(totpCode, friendlyDeviceName, callback) {
1945 var _this19 = this;
1946
1947 if (!(this.signInUserSession != null && this.signInUserSession.isValid())) {
1948 this.client.request('VerifySoftwareToken', {
1949 Session: this.Session,
1950 UserCode: totpCode,
1951 FriendlyDeviceName: friendlyDeviceName
1952 }, function (err, data) {
1953 if (err) {
1954 return callback.onFailure(err);
1955 }
1956
1957 _this19.Session = data.Session;
1958 var challengeResponses = {};
1959 challengeResponses.USERNAME = _this19.username;
1960 var jsonReq = {
1961 ChallengeName: 'MFA_SETUP',
1962 ClientId: _this19.pool.getClientId(),
1963 ChallengeResponses: challengeResponses,
1964 Session: _this19.Session
1965 };
1966
1967 if (_this19.getUserContextData()) {
1968 jsonReq.UserContextData = _this19.getUserContextData();
1969 }
1970
1971 _this19.client.request('RespondToAuthChallenge', jsonReq, function (errRespond, dataRespond) {
1972 if (errRespond) {
1973 return callback.onFailure(errRespond);
1974 }
1975
1976 _this19.signInUserSession = _this19.getCognitoUserSession(dataRespond.AuthenticationResult);
1977
1978 _this19.cacheTokens();
1979
1980 return callback.onSuccess(_this19.signInUserSession);
1981 });
1982
1983 return undefined;
1984 });
1985 } else {
1986 this.client.request('VerifySoftwareToken', {
1987 AccessToken: this.signInUserSession.getAccessToken().getJwtToken(),
1988 UserCode: totpCode,
1989 FriendlyDeviceName: friendlyDeviceName
1990 }, function (err, data) {
1991 if (err) {
1992 return callback.onFailure(err);
1993 }
1994
1995 return callback.onSuccess(data);
1996 });
1997 }
1998 };
1999
2000 return CognitoUser;
2001}();
2002
2003export { CognitoUser as default };
\No newline at end of file