@aws-amplify/auth 5.6.1 → 5.6.2-unstable.bee9c8e.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,14 +2,15 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { __assign, __awaiter, __generator, __read } from "tslib";
4
4
  import { isUsernamePasswordOpts, isCognitoHostedOpts, isFederatedSignInOptions, isFederatedSignInOptionsCustom, hasCustomState, } from '../types';
5
- import { Amplify, ConsoleLogger as Logger, Credentials, Hub, StorageHelper, Platform, browserOrNode, parseAWSExports, UniversalStorage, urlSafeDecode, } from '@aws-amplify/core';
6
- import { CookieStorage, CognitoUserPool, AuthenticationDetails, CognitoUser, CognitoUserSession, CognitoUserAttribute, CognitoIdToken, CognitoRefreshToken, CognitoAccessToken, } from 'amazon-cognito-identity-js';
7
- import { addAuthCategoryToCognitoUserAgent, addFrameworkToCognitoUserAgent, } from 'amazon-cognito-identity-js/internals';
5
+ import { Amplify, AuthAction, ConsoleLogger as Logger, Credentials, getAmplifyUserAgent, Hub, StorageHelper, Platform, browserOrNode, parseAWSExports, UniversalStorage, urlSafeDecode, } from '@aws-amplify/core';
6
+ import { CookieStorage, AuthenticationDetails, CognitoUserSession, CognitoUserAttribute, CognitoIdToken, CognitoRefreshToken, CognitoAccessToken, } from 'amazon-cognito-identity-js';
7
+ import { addAuthCategoryToCognitoUserAgent, addFrameworkToCognitoUserAgent, InternalCognitoUser, InternalCognitoUserPool, } from 'amazon-cognito-identity-js/internals';
8
8
  import { parse } from 'url';
9
9
  import OAuth from '../OAuth/OAuth';
10
10
  import { default as urlListener } from '../urlListener';
11
11
  import { AuthError, NoUserPoolError } from '../Errors';
12
12
  import { AuthErrorTypes, CognitoHostedUIIdentityProvider, } from '../types/Auth';
13
+ import { getAuthUserAgentDetails, getAuthUserAgentValue } from '../utils';
13
14
  var logger = new Logger('AuthClass');
14
15
  var USER_ADMIN_SCOPE = 'aws.cognito.signin.user.admin';
15
16
  // 10 sec, following this guide https://www.nngroup.com/articles/response-times-3-important-limits/
@@ -118,7 +119,7 @@ var InternalAuthClass = /** @class */ (function () {
118
119
  endpoint: endpoint,
119
120
  };
120
121
  userPoolData.Storage = this._storage;
121
- this.userPool = new CognitoUserPool(userPoolData, this.wrapRefreshSessionCallback);
122
+ this.userPool = new InternalCognitoUserPool(userPoolData, this.wrapRefreshSessionCallback);
122
123
  }
123
124
  this.Credentials.configure({
124
125
  mandatorySignIn: mandatorySignIn,
@@ -158,14 +159,17 @@ var InternalAuthClass = /** @class */ (function () {
158
159
  // Prevents _handleAuthResponse from being called multiple times in Expo
159
160
  // See https://github.com/aws-amplify/amplify-js/issues/4388
160
161
  var usedResponseUrls_1 = {};
161
- urlListener(function (_a) {
162
- var url = _a.url;
163
- if (usedResponseUrls_1[url]) {
164
- return;
165
- }
166
- usedResponseUrls_1[url] = true;
167
- _this._handleAuthResponse(url);
168
- });
162
+ // Only register urlListener once
163
+ if (this.getModuleName() === 'InternalAuth') {
164
+ urlListener(function (_a) {
165
+ var url = _a.url;
166
+ if (usedResponseUrls_1[url]) {
167
+ return;
168
+ }
169
+ usedResponseUrls_1[url] = true;
170
+ _this._handleAuthResponse(url);
171
+ });
172
+ }
169
173
  }
170
174
  dispatchAuthEvent('configured', null, "The Auth category has been configured successfully");
171
175
  if (!this.autoSignInInitiated &&
@@ -250,6 +254,7 @@ var InternalAuthClass = /** @class */ (function () {
250
254
  logger.debug('signUp attrs:', attributes);
251
255
  logger.debug('signUp validation data:', validationData);
252
256
  return new Promise(function (resolve, reject) {
257
+ var userAgentDetails = getAuthUserAgentDetails(AuthAction.SignUp, customUserAgentDetails);
253
258
  _this.userPool.signUp(username, password, attributes, validationData, function (err, data) {
254
259
  if (err) {
255
260
  dispatchAuthEvent('signUp_failure', err, username + " failed to signup");
@@ -258,14 +263,14 @@ var InternalAuthClass = /** @class */ (function () {
258
263
  else {
259
264
  dispatchAuthEvent('signUp', data, username + " has signed up successfully");
260
265
  if (autoSignIn.enabled) {
261
- _this.handleAutoSignIn(username, password, autoSignInValidationData, autoSignInClientMetaData, data);
266
+ _this.handleAutoSignIn(username, password, autoSignInValidationData, autoSignInClientMetaData, data, userAgentDetails);
262
267
  }
263
268
  resolve(data);
264
269
  }
265
- }, clientMetadata);
270
+ }, clientMetadata, getAmplifyUserAgent(userAgentDetails));
266
271
  });
267
272
  };
268
- InternalAuthClass.prototype.handleAutoSignIn = function (username, password, validationData, clientMetadata, data) {
273
+ InternalAuthClass.prototype.handleAutoSignIn = function (username, password, validationData, clientMetadata, data, customUserAgentDetails) {
269
274
  this.autoSignInInitiated = true;
270
275
  var authDetails = new AuthenticationDetails({
271
276
  Username: username,
@@ -274,26 +279,26 @@ var InternalAuthClass = /** @class */ (function () {
274
279
  ClientMetadata: clientMetadata,
275
280
  });
276
281
  if (data.userConfirmed) {
277
- this.signInAfterUserConfirmed(authDetails);
282
+ this.signInAfterUserConfirmed(authDetails, customUserAgentDetails);
278
283
  }
279
284
  else if (this._config.signUpVerificationMethod === 'link') {
280
- this.handleLinkAutoSignIn(authDetails);
285
+ this.handleLinkAutoSignIn(authDetails, customUserAgentDetails);
281
286
  }
282
287
  else {
283
- this.handleCodeAutoSignIn(authDetails);
288
+ this.handleCodeAutoSignIn(authDetails, customUserAgentDetails);
284
289
  }
285
290
  };
286
- InternalAuthClass.prototype.handleCodeAutoSignIn = function (authDetails) {
291
+ InternalAuthClass.prototype.handleCodeAutoSignIn = function (authDetails, customUserAgentDetails) {
287
292
  var _this = this;
288
293
  var listenEvent = function (_a) {
289
294
  var payload = _a.payload;
290
295
  if (payload.event === 'confirmSignUp') {
291
- _this.signInAfterUserConfirmed(authDetails, listenEvent);
296
+ _this.signInAfterUserConfirmed(authDetails, customUserAgentDetails, listenEvent);
292
297
  }
293
298
  };
294
299
  Hub.listen('auth', listenEvent);
295
300
  };
296
- InternalAuthClass.prototype.handleLinkAutoSignIn = function (authDetails) {
301
+ InternalAuthClass.prototype.handleLinkAutoSignIn = function (authDetails, customUserAgentDetails) {
297
302
  var _this = this;
298
303
  this._storage.setItem('amplify-polling-started', 'true');
299
304
  var start = Date.now();
@@ -304,11 +309,11 @@ var InternalAuthClass = /** @class */ (function () {
304
309
  _this._storage.removeItem('amplify-auto-sign-in');
305
310
  }
306
311
  else {
307
- _this.signInAfterUserConfirmed(authDetails, null, autoSignInPollingIntervalId);
312
+ _this.signInAfterUserConfirmed(authDetails, customUserAgentDetails, undefined, autoSignInPollingIntervalId);
308
313
  }
309
314
  }, 5000);
310
315
  };
311
- InternalAuthClass.prototype.signInAfterUserConfirmed = function (authDetails, listenEvent, autoSignInPollingIntervalId) {
316
+ InternalAuthClass.prototype.signInAfterUserConfirmed = function (authDetails, customUserAgentDetails, listenEvent, autoSignInPollingIntervalId) {
312
317
  return __awaiter(this, void 0, void 0, function () {
313
318
  var user, error_1;
314
319
  var _this = this;
@@ -332,7 +337,7 @@ var InternalAuthClass = /** @class */ (function () {
332
337
  }, function (error) {
333
338
  logger.error(error);
334
339
  _this._storage.removeItem('amplify-auto-sign-in');
335
- }))];
340
+ }, customUserAgentDetails), getAmplifyUserAgent(customUserAgentDetails))];
336
341
  case 2:
337
342
  _a.sent();
338
343
  return [3 /*break*/, 4];
@@ -389,7 +394,7 @@ var InternalAuthClass = /** @class */ (function () {
389
394
  }
390
395
  resolve(data);
391
396
  }
392
- }, clientMetadata);
397
+ }, clientMetadata, getAuthUserAgentValue(AuthAction.ConfirmSignUp, customUserAgentDetails));
393
398
  });
394
399
  };
395
400
  InternalAuthClass.prototype.isTrueStorageValue = function (value) {
@@ -420,7 +425,7 @@ var InternalAuthClass = /** @class */ (function () {
420
425
  else {
421
426
  resolve(data);
422
427
  }
423
- }, clientMetadata);
428
+ }, clientMetadata, getAuthUserAgentValue(AuthAction.ResendSignUp, customUserAgentDetails));
424
429
  });
425
430
  };
426
431
  /**
@@ -463,21 +468,22 @@ var InternalAuthClass = /** @class */ (function () {
463
468
  ValidationData: validationData,
464
469
  ClientMetadata: clientMetadata,
465
470
  });
471
+ var userAgentDetails = getAuthUserAgentDetails(AuthAction.SignIn, customUserAgentDetails);
466
472
  if (password) {
467
- return this.signInWithPassword(authDetails);
473
+ return this.signInWithPassword(authDetails, userAgentDetails);
468
474
  }
469
475
  else {
470
- return this.signInWithoutPassword(authDetails);
476
+ return this.signInWithoutPassword(authDetails, userAgentDetails);
471
477
  }
472
478
  };
473
479
  /**
474
480
  * Return an object with the authentication callbacks
475
- * @param {CognitoUser} user - the cognito user object
481
+ * @param {InternalCognitoUser} user - the cognito user object
476
482
  * @param {} resolve - function called when resolving the current step
477
483
  * @param {} reject - function called when rejecting the current step
478
484
  * @return - an object with the callback methods for user authentication
479
485
  */
480
- InternalAuthClass.prototype.authCallbacks = function (user, resolve, reject) {
486
+ InternalAuthClass.prototype.authCallbacks = function (user, resolve, reject, customUserAgentDetails) {
481
487
  var _this = this;
482
488
  var that = this;
483
489
  return {
@@ -506,7 +512,7 @@ var InternalAuthClass = /** @class */ (function () {
506
512
  return [3 /*break*/, 9];
507
513
  case 5:
508
514
  _a.trys.push([5, 7, , 8]);
509
- return [4 /*yield*/, this.currentUserPoolUser()];
515
+ return [4 /*yield*/, this._currentUserPoolUser(undefined, customUserAgentDetails)];
510
516
  case 6:
511
517
  currentUser = _a.sent();
512
518
  that.user = currentUser;
@@ -573,9 +579,10 @@ var InternalAuthClass = /** @class */ (function () {
573
579
  * Sign in with a password
574
580
  * @private
575
581
  * @param {AuthenticationDetails} authDetails - the user sign in data
582
+ * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
576
583
  * @return - A promise resolves the CognitoUser object if success or mfa required
577
584
  */
578
- InternalAuthClass.prototype.signInWithPassword = function (authDetails) {
585
+ InternalAuthClass.prototype.signInWithPassword = function (authDetails, customUserAgentDetails) {
579
586
  var _this = this;
580
587
  if (this.pendingSignIn) {
581
588
  throw new Error('Pending sign-in attempt already in progress');
@@ -588,7 +595,7 @@ var InternalAuthClass = /** @class */ (function () {
588
595
  }, function (error) {
589
596
  _this.pendingSignIn = null;
590
597
  reject(error);
591
- }));
598
+ }, customUserAgentDetails), getAmplifyUserAgent(customUserAgentDetails));
592
599
  });
593
600
  return this.pendingSignIn;
594
601
  };
@@ -596,14 +603,15 @@ var InternalAuthClass = /** @class */ (function () {
596
603
  * Sign in without a password
597
604
  * @private
598
605
  * @param {AuthenticationDetails} authDetails - the user sign in data
599
- * @return - A promise resolves the CognitoUser object if success or mfa required
606
+ * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
607
+ * @return - A promise resolves the InternalCognitoUser object if success or mfa required
600
608
  */
601
- InternalAuthClass.prototype.signInWithoutPassword = function (authDetails) {
609
+ InternalAuthClass.prototype.signInWithoutPassword = function (authDetails, customUserAgentDetails) {
602
610
  var _this = this;
603
611
  var user = this.createCognitoUser(authDetails.getUsername());
604
612
  user.setAuthenticationFlowType('CUSTOM_AUTH');
605
613
  return new Promise(function (resolve, reject) {
606
- user.initiateAuth(authDetails, _this.authCallbacks(user, resolve, reject));
614
+ user.initiateAuth(authDetails, _this.authCallbacks(user, resolve, reject, customUserAgentDetails), getAmplifyUserAgent(customUserAgentDetails));
607
615
  });
608
616
  };
609
617
  /**
@@ -616,8 +624,9 @@ var InternalAuthClass = /** @class */ (function () {
616
624
  * @return - A promise resolves the current preferred mfa option if success
617
625
  */
618
626
  InternalAuthClass.prototype.getMFAOptions = function (user, customUserAgentDetails) {
627
+ var internalUser = user;
619
628
  return new Promise(function (res, rej) {
620
- user.getMFAOptions(function (err, mfaOptions) {
629
+ internalUser.getMFAOptions(function (err, mfaOptions) {
621
630
  if (err) {
622
631
  logger.debug('get MFA Options failed', err);
623
632
  rej(err);
@@ -626,7 +635,7 @@ var InternalAuthClass = /** @class */ (function () {
626
635
  logger.debug('get MFA options success', mfaOptions);
627
636
  res(mfaOptions);
628
637
  return;
629
- });
638
+ }, getAuthUserAgentValue(AuthAction.GetMFAOptions, customUserAgentDetails));
630
639
  });
631
640
  };
632
641
  /**
@@ -637,11 +646,13 @@ var InternalAuthClass = /** @class */ (function () {
637
646
  */
638
647
  InternalAuthClass.prototype.getPreferredMFA = function (user, params, customUserAgentDetails) {
639
648
  var _this = this;
649
+ var internalUser = user;
640
650
  var that = this;
641
651
  return new Promise(function (res, rej) {
642
652
  var clientMetadata = _this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
643
653
  var bypassCache = params ? params.bypassCache : false;
644
- user.getUserData(function (err, data) { return __awaiter(_this, void 0, void 0, function () {
654
+ var userAgentValue = getAuthUserAgentValue(AuthAction.GetPreferredMFA, customUserAgentDetails);
655
+ internalUser.getUserData(function (err, data) { return __awaiter(_this, void 0, void 0, function () {
645
656
  var cleanUpError_1, mfaType;
646
657
  return __generator(this, function (_a) {
647
658
  switch (_a.label) {
@@ -652,7 +663,7 @@ var InternalAuthClass = /** @class */ (function () {
652
663
  _a.label = 1;
653
664
  case 1:
654
665
  _a.trys.push([1, 3, , 4]);
655
- return [4 /*yield*/, this.cleanUpInvalidSession(user)];
666
+ return [4 /*yield*/, this.cleanUpInvalidSession(user, userAgentValue)];
656
667
  case 2:
657
668
  _a.sent();
658
669
  return [3 /*break*/, 4];
@@ -676,7 +687,7 @@ var InternalAuthClass = /** @class */ (function () {
676
687
  return [2 /*return*/];
677
688
  }
678
689
  });
679
- }); }, { bypassCache: bypassCache, clientMetadata: clientMetadata });
690
+ }); }, { bypassCache: bypassCache, clientMetadata: clientMetadata }, userAgentValue);
680
691
  });
681
692
  };
682
693
  InternalAuthClass.prototype._getMfaTypeFromUserData = function (data) {
@@ -712,7 +723,7 @@ var InternalAuthClass = /** @class */ (function () {
712
723
  }
713
724
  return ret;
714
725
  };
715
- InternalAuthClass.prototype._getUserData = function (user, params) {
726
+ InternalAuthClass.prototype._getUserData = function (user, params, userAgentValue) {
716
727
  var _this = this;
717
728
  return new Promise(function (res, rej) {
718
729
  user.getUserData(function (err, data) { return __awaiter(_this, void 0, void 0, function () {
@@ -726,7 +737,7 @@ var InternalAuthClass = /** @class */ (function () {
726
737
  _a.label = 1;
727
738
  case 1:
728
739
  _a.trys.push([1, 3, , 4]);
729
- return [4 /*yield*/, this.cleanUpInvalidSession(user)];
740
+ return [4 /*yield*/, this.cleanUpInvalidSession(user, userAgentValue)];
730
741
  case 2:
731
742
  _a.sent();
732
743
  return [3 /*break*/, 4];
@@ -743,7 +754,7 @@ var InternalAuthClass = /** @class */ (function () {
743
754
  case 6: return [2 /*return*/];
744
755
  }
745
756
  });
746
- }); }, params);
757
+ }); }, params, userAgentValue);
747
758
  });
748
759
  };
749
760
  /**
@@ -755,16 +766,18 @@ var InternalAuthClass = /** @class */ (function () {
755
766
  */
756
767
  InternalAuthClass.prototype.setPreferredMFA = function (user, mfaMethod, customUserAgentDetails) {
757
768
  return __awaiter(this, void 0, void 0, function () {
758
- var clientMetadata, userData, smsMfaSettings, totpMfaSettings, _a, mfaList, currentMFAType, that;
769
+ var internalUser, userAgentValue, clientMetadata, userData, smsMfaSettings, totpMfaSettings, _a, mfaList, currentMFAType, that;
759
770
  var _this = this;
760
771
  return __generator(this, function (_b) {
761
772
  switch (_b.label) {
762
773
  case 0:
774
+ internalUser = user;
775
+ userAgentValue = getAuthUserAgentValue(AuthAction.SetPreferredMFA, customUserAgentDetails);
763
776
  clientMetadata = this._config.clientMetadata;
764
777
  return [4 /*yield*/, this._getUserData(user, {
765
778
  bypassCache: true,
766
779
  clientMetadata: clientMetadata,
767
- })];
780
+ }, userAgentValue)];
768
781
  case 1:
769
782
  userData = _b.sent();
770
783
  smsMfaSettings = null;
@@ -839,7 +852,7 @@ var InternalAuthClass = /** @class */ (function () {
839
852
  case 7:
840
853
  that = this;
841
854
  return [2 /*return*/, new Promise(function (res, rej) {
842
- user.setUserMfaPreference(smsMfaSettings, totpMfaSettings, function (err, result) {
855
+ internalUser.setUserMfaPreference(smsMfaSettings, totpMfaSettings, function (err, result) {
843
856
  if (err) {
844
857
  logger.debug('Set user mfa preference error', err);
845
858
  return rej(err);
@@ -847,7 +860,7 @@ var InternalAuthClass = /** @class */ (function () {
847
860
  logger.debug('Set user mfa success', result);
848
861
  logger.debug('Caching the latest user data into local');
849
862
  // cache the latest result into user data
850
- user.getUserData(function (err, data) { return __awaiter(_this, void 0, void 0, function () {
863
+ internalUser.getUserData(function (err, data) { return __awaiter(_this, void 0, void 0, function () {
851
864
  var cleanUpError_3;
852
865
  return __generator(this, function (_a) {
853
866
  switch (_a.label) {
@@ -858,7 +871,7 @@ var InternalAuthClass = /** @class */ (function () {
858
871
  _a.label = 1;
859
872
  case 1:
860
873
  _a.trys.push([1, 3, , 4]);
861
- return [4 /*yield*/, this.cleanUpInvalidSession(user)];
874
+ return [4 /*yield*/, this.cleanUpInvalidSession(user, userAgentValue)];
862
875
  case 2:
863
876
  _a.sent();
864
877
  return [3 /*break*/, 4];
@@ -873,8 +886,8 @@ var InternalAuthClass = /** @class */ (function () {
873
886
  }); }, {
874
887
  bypassCache: true,
875
888
  clientMetadata: clientMetadata,
876
- });
877
- });
889
+ }, userAgentValue);
890
+ }, userAgentValue);
878
891
  })];
879
892
  }
880
893
  });
@@ -888,8 +901,9 @@ var InternalAuthClass = /** @class */ (function () {
888
901
  * @return - A promise resolves is success
889
902
  */
890
903
  InternalAuthClass.prototype.disableSMS = function (user, customUserAgentDetails) {
904
+ var internalUser = user;
891
905
  return new Promise(function (res, rej) {
892
- user.disableMFA(function (err, data) {
906
+ internalUser.disableMFA(function (err, data) {
893
907
  if (err) {
894
908
  logger.debug('disable mfa failed', err);
895
909
  rej(err);
@@ -898,7 +912,7 @@ var InternalAuthClass = /** @class */ (function () {
898
912
  logger.debug('disable mfa succeed', data);
899
913
  res(data);
900
914
  return;
901
- });
915
+ }, getAuthUserAgentValue(AuthAction.DisableSMS, customUserAgentDetails));
902
916
  });
903
917
  };
904
918
  /**
@@ -909,8 +923,9 @@ var InternalAuthClass = /** @class */ (function () {
909
923
  * @return - A promise resolves is success
910
924
  */
911
925
  InternalAuthClass.prototype.enableSMS = function (user, customUserAgentDetails) {
926
+ var internalUser = user;
912
927
  return new Promise(function (res, rej) {
913
- user.enableMFA(function (err, data) {
928
+ internalUser.enableMFA(function (err, data) {
914
929
  if (err) {
915
930
  logger.debug('enable mfa failed', err);
916
931
  rej(err);
@@ -919,7 +934,7 @@ var InternalAuthClass = /** @class */ (function () {
919
934
  logger.debug('enable mfa succeed', data);
920
935
  res(data);
921
936
  return;
922
- });
937
+ }, getAuthUserAgentValue(AuthAction.EnableSMS, customUserAgentDetails));
923
938
  });
924
939
  };
925
940
  /**
@@ -929,8 +944,9 @@ var InternalAuthClass = /** @class */ (function () {
929
944
  * @return - A promise resolves with the secret code if success
930
945
  */
931
946
  InternalAuthClass.prototype.setupTOTP = function (user, customUserAgentDetails) {
947
+ var internalUser = user;
932
948
  return new Promise(function (res, rej) {
933
- user.associateSoftwareToken({
949
+ internalUser.associateSoftwareToken({
934
950
  onFailure: function (err) {
935
951
  logger.debug('associateSoftwareToken failed', err);
936
952
  rej(err);
@@ -941,7 +957,7 @@ var InternalAuthClass = /** @class */ (function () {
941
957
  res(secretCode);
942
958
  return;
943
959
  },
944
- });
960
+ }, getAuthUserAgentValue(AuthAction.SetupTOTP, customUserAgentDetails));
945
961
  });
946
962
  };
947
963
  /**
@@ -953,13 +969,15 @@ var InternalAuthClass = /** @class */ (function () {
953
969
  */
954
970
  InternalAuthClass.prototype.verifyTotpToken = function (user, challengeAnswer, customUserAgentDetails) {
955
971
  logger.debug('verification totp token', user, challengeAnswer);
972
+ var internalUser = user;
956
973
  var signInUserSession;
957
- if (user && typeof user.getSignInUserSession === 'function') {
974
+ if (internalUser &&
975
+ typeof internalUser.getSignInUserSession === 'function') {
958
976
  signInUserSession = user.getSignInUserSession();
959
977
  }
960
978
  var isLoggedIn = signInUserSession === null || signInUserSession === void 0 ? void 0 : signInUserSession.isValid();
961
979
  return new Promise(function (res, rej) {
962
- user.verifySoftwareToken(challengeAnswer, 'My TOTP device', {
980
+ internalUser.verifySoftwareToken(challengeAnswer, 'My TOTP device', {
963
981
  onFailure: function (err) {
964
982
  logger.debug('verifyTotpToken failed', err);
965
983
  rej(err);
@@ -967,14 +985,14 @@ var InternalAuthClass = /** @class */ (function () {
967
985
  },
968
986
  onSuccess: function (data) {
969
987
  if (!isLoggedIn) {
970
- dispatchAuthEvent('signIn', user, "A user " + user.getUsername() + " has been signed in");
988
+ dispatchAuthEvent('signIn', internalUser, "A user " + internalUser.getUsername() + " has been signed in");
971
989
  }
972
- dispatchAuthEvent('verify', user, "A user " + user.getUsername() + " has been verified");
990
+ dispatchAuthEvent('verify', internalUser, "A user " + internalUser.getUsername() + " has been verified");
973
991
  logger.debug('verifyTotpToken success', data);
974
992
  res(data);
975
993
  return;
976
994
  },
977
- });
995
+ }, getAuthUserAgentValue(AuthAction.VerifyTotpToken, customUserAgentDetails));
978
996
  });
979
997
  };
980
998
  /**
@@ -988,12 +1006,14 @@ var InternalAuthClass = /** @class */ (function () {
988
1006
  InternalAuthClass.prototype.confirmSignIn = function (user, code, mfaType, clientMetadata, customUserAgentDetails) {
989
1007
  var _this = this;
990
1008
  if (clientMetadata === void 0) { clientMetadata = this._config.clientMetadata; }
1009
+ var internalUser = user;
991
1010
  if (!code) {
992
1011
  return this.rejectAuthError(AuthErrorTypes.EmptyCode);
993
1012
  }
994
1013
  var that = this;
1014
+ var userAgentDetails = getAuthUserAgentDetails(AuthAction.ConfirmSignIn, customUserAgentDetails);
995
1015
  return new Promise(function (resolve, reject) {
996
- user.sendMFACode(code, {
1016
+ internalUser.sendMFACode(code, {
997
1017
  onSuccess: function (session) { return __awaiter(_this, void 0, void 0, function () {
998
1018
  var cred, e_3, currentUser, e_4;
999
1019
  return __generator(this, function (_a) {
@@ -1016,22 +1036,24 @@ var InternalAuthClass = /** @class */ (function () {
1016
1036
  logger.debug('cannot get cognito credentials', e_3);
1017
1037
  return [3 /*break*/, 10];
1018
1038
  case 5:
1019
- that.user = user;
1039
+ that.user = internalUser;
1020
1040
  _a.label = 6;
1021
1041
  case 6:
1022
1042
  _a.trys.push([6, 8, , 9]);
1023
- return [4 /*yield*/, this.currentUserPoolUser()];
1043
+ return [4 /*yield*/, this._currentUserPoolUser(undefined, userAgentDetails)];
1024
1044
  case 7:
1025
1045
  currentUser = _a.sent();
1026
- user.attributes = currentUser.attributes;
1046
+ Object.assign(internalUser, {
1047
+ attributes: currentUser.attributes,
1048
+ });
1027
1049
  return [3 /*break*/, 9];
1028
1050
  case 8:
1029
1051
  e_4 = _a.sent();
1030
1052
  logger.debug('cannot get updated Cognito User', e_4);
1031
1053
  return [3 /*break*/, 9];
1032
1054
  case 9:
1033
- dispatchAuthEvent('signIn', user, "A user " + user.getUsername() + " has been signed in");
1034
- resolve(user);
1055
+ dispatchAuthEvent('signIn', internalUser, "A user " + internalUser.getUsername() + " has been signed in");
1056
+ resolve(internalUser);
1035
1057
  return [7 /*endfinally*/];
1036
1058
  case 10: return [2 /*return*/];
1037
1059
  }
@@ -1041,19 +1063,20 @@ var InternalAuthClass = /** @class */ (function () {
1041
1063
  logger.debug('confirm signIn failure', err);
1042
1064
  reject(err);
1043
1065
  },
1044
- }, mfaType, clientMetadata);
1066
+ }, mfaType, clientMetadata, getAmplifyUserAgent(userAgentDetails));
1045
1067
  });
1046
1068
  };
1047
1069
  InternalAuthClass.prototype.completeNewPassword = function (user, password, requiredAttributes, clientMetadata, customUserAgentDetails) {
1048
1070
  var _this = this;
1049
1071
  if (requiredAttributes === void 0) { requiredAttributes = {}; }
1050
1072
  if (clientMetadata === void 0) { clientMetadata = this._config.clientMetadata; }
1073
+ var internalUser = user;
1051
1074
  if (!password) {
1052
1075
  return this.rejectAuthError(AuthErrorTypes.EmptyPassword);
1053
1076
  }
1054
1077
  var that = this;
1055
1078
  return new Promise(function (resolve, reject) {
1056
- user.completeNewPasswordChallenge(password, requiredAttributes, {
1079
+ internalUser.completeNewPasswordChallenge(password, requiredAttributes, {
1057
1080
  onSuccess: function (session) { return __awaiter(_this, void 0, void 0, function () {
1058
1081
  var cred, e_5;
1059
1082
  return __generator(this, function (_a) {
@@ -1076,9 +1099,9 @@ var InternalAuthClass = /** @class */ (function () {
1076
1099
  logger.debug('cannot get cognito credentials', e_5);
1077
1100
  return [3 /*break*/, 6];
1078
1101
  case 5:
1079
- that.user = user;
1080
- dispatchAuthEvent('signIn', user, "A user " + user.getUsername() + " has been signed in");
1081
- resolve(user);
1102
+ that.user = internalUser;
1103
+ dispatchAuthEvent('signIn', internalUser, "A user " + internalUser.getUsername() + " has been signed in");
1104
+ resolve(internalUser);
1082
1105
  return [7 /*endfinally*/];
1083
1106
  case 6: return [2 /*return*/];
1084
1107
  }
@@ -1091,23 +1114,23 @@ var InternalAuthClass = /** @class */ (function () {
1091
1114
  },
1092
1115
  mfaRequired: function (challengeName, challengeParam) {
1093
1116
  logger.debug('signIn MFA required');
1094
- user['challengeName'] = challengeName;
1095
- user['challengeParam'] = challengeParam;
1096
- resolve(user);
1117
+ internalUser['challengeName'] = challengeName;
1118
+ internalUser['challengeParam'] = challengeParam;
1119
+ resolve(internalUser);
1097
1120
  },
1098
1121
  mfaSetup: function (challengeName, challengeParam) {
1099
1122
  logger.debug('signIn mfa setup', challengeName);
1100
- user['challengeName'] = challengeName;
1101
- user['challengeParam'] = challengeParam;
1102
- resolve(user);
1123
+ internalUser['challengeName'] = challengeName;
1124
+ internalUser['challengeParam'] = challengeParam;
1125
+ resolve(internalUser);
1103
1126
  },
1104
1127
  totpRequired: function (challengeName, challengeParam) {
1105
1128
  logger.debug('signIn mfa setup', challengeName);
1106
- user['challengeName'] = challengeName;
1107
- user['challengeParam'] = challengeParam;
1108
- resolve(user);
1129
+ internalUser['challengeName'] = challengeName;
1130
+ internalUser['challengeParam'] = challengeParam;
1131
+ resolve(internalUser);
1109
1132
  },
1110
- }, clientMetadata);
1133
+ }, clientMetadata, getAuthUserAgentValue(AuthAction.CompleteNewPassword, customUserAgentDetails));
1111
1134
  });
1112
1135
  };
1113
1136
  /**
@@ -1116,10 +1139,12 @@ var InternalAuthClass = /** @class */ (function () {
1116
1139
  * @param {String} challengeResponses - The confirmation code
1117
1140
  * @param {ClientMetaData} clientMetadata - optional client metadata defaults to config
1118
1141
  * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
1142
+ *
1119
1143
  */
1120
1144
  InternalAuthClass.prototype.sendCustomChallengeAnswer = function (user, challengeResponses, clientMetadata, customUserAgentDetails) {
1121
1145
  var _this = this;
1122
1146
  if (clientMetadata === void 0) { clientMetadata = this._config.clientMetadata; }
1147
+ var internalUser = user;
1123
1148
  if (!this.userPool) {
1124
1149
  return this.rejectNoUserPool();
1125
1150
  }
@@ -1127,8 +1152,9 @@ var InternalAuthClass = /** @class */ (function () {
1127
1152
  return this.rejectAuthError(AuthErrorTypes.EmptyChallengeResponse);
1128
1153
  }
1129
1154
  var that = this;
1155
+ var userAgentDetails = getAuthUserAgentDetails(AuthAction.SendCustomChallengeAnswer, customUserAgentDetails);
1130
1156
  return new Promise(function (resolve, reject) {
1131
- user.sendCustomChallengeAnswer(challengeResponses, _this.authCallbacks(user, resolve, reject), clientMetadata);
1157
+ internalUser.sendCustomChallengeAnswer(challengeResponses, _this.authCallbacks(internalUser, resolve, reject, userAgentDetails), clientMetadata, getAmplifyUserAgent(userAgentDetails));
1132
1158
  });
1133
1159
  };
1134
1160
  /**
@@ -1139,17 +1165,19 @@ var InternalAuthClass = /** @class */ (function () {
1139
1165
  * @return {Promise}
1140
1166
  **/
1141
1167
  InternalAuthClass.prototype.deleteUserAttributes = function (user, attributeNames, customUserAgentDetails) {
1168
+ var internalUser = user;
1142
1169
  var that = this;
1170
+ var userAgentValue = getAuthUserAgentValue(AuthAction.DeleteUserAttributes, customUserAgentDetails);
1143
1171
  return new Promise(function (resolve, reject) {
1144
- that.userSession(user).then(function (session) {
1145
- user.deleteAttributes(attributeNames, function (err, result) {
1172
+ that._userSession(userAgentValue, internalUser).then(function (session) {
1173
+ internalUser.deleteAttributes(attributeNames, function (err, result) {
1146
1174
  if (err) {
1147
1175
  return reject(err);
1148
1176
  }
1149
1177
  else {
1150
1178
  return resolve(result);
1151
1179
  }
1152
- });
1180
+ }, userAgentValue);
1153
1181
  });
1154
1182
  });
1155
1183
  };
@@ -1179,17 +1207,18 @@ var InternalAuthClass = /** @class */ (function () {
1179
1207
  isSignedInHostedUI = this._oAuthHandler &&
1180
1208
  this._storage.getItem('amplify-signin-with-hostedUI') === 'true';
1181
1209
  return [2 /*return*/, new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
1182
- var user_1;
1210
+ var internalUser_1, userAgentValue_1;
1183
1211
  var _this = this;
1184
1212
  return __generator(this, function (_a) {
1185
1213
  if (this.userPool) {
1186
- user_1 = this.userPool.getCurrentUser();
1187
- if (!user_1) {
1214
+ internalUser_1 = this.userPool.getCurrentUser();
1215
+ if (!internalUser_1) {
1188
1216
  logger.debug('Failed to get user from user pool');
1189
1217
  return [2 /*return*/, rej(new Error('No current user.'))];
1190
1218
  }
1191
1219
  else {
1192
- user_1.getSession(function (err, session) { return __awaiter(_this, void 0, void 0, function () {
1220
+ userAgentValue_1 = getAuthUserAgentValue(AuthAction.DeleteUser, customUserAgentDetails);
1221
+ internalUser_1.getSession(function (err, session) { return __awaiter(_this, void 0, void 0, function () {
1193
1222
  var cleanUpError_4;
1194
1223
  var _this = this;
1195
1224
  return __generator(this, function (_a) {
@@ -1201,7 +1230,7 @@ var InternalAuthClass = /** @class */ (function () {
1201
1230
  _a.label = 1;
1202
1231
  case 1:
1203
1232
  _a.trys.push([1, 3, , 4]);
1204
- return [4 /*yield*/, this.cleanUpInvalidSession(user_1)];
1233
+ return [4 /*yield*/, this.cleanUpInvalidSession(internalUser_1, userAgentValue_1)];
1205
1234
  case 2:
1206
1235
  _a.sent();
1207
1236
  return [3 /*break*/, 4];
@@ -1211,13 +1240,13 @@ var InternalAuthClass = /** @class */ (function () {
1211
1240
  return [2 /*return*/];
1212
1241
  case 4: return [2 /*return*/, rej(err)];
1213
1242
  case 5:
1214
- user_1.deleteUser(function (err, result) {
1243
+ internalUser_1.deleteUser(function (err, result) {
1215
1244
  if (err) {
1216
1245
  rej(err);
1217
1246
  }
1218
1247
  else {
1219
1248
  dispatchAuthEvent('userDeleted', result, 'The authenticated user has been deleted.');
1220
- user_1.signOut();
1249
+ internalUser_1.signOut(undefined, userAgentValue_1);
1221
1250
  _this.user = null;
1222
1251
  try {
1223
1252
  _this.cleanCachedItems(); // clean aws credentials
@@ -1234,7 +1263,7 @@ var InternalAuthClass = /** @class */ (function () {
1234
1263
  res(result);
1235
1264
  }
1236
1265
  }
1237
- });
1266
+ }, undefined, userAgentValue_1);
1238
1267
  _a.label = 6;
1239
1268
  case 6: return [2 /*return*/];
1240
1269
  }
@@ -1264,10 +1293,12 @@ var InternalAuthClass = /** @class */ (function () {
1264
1293
  InternalAuthClass.prototype.updateUserAttributes = function (user, attributes, clientMetadata, customUserAgentDetails) {
1265
1294
  var _this = this;
1266
1295
  if (clientMetadata === void 0) { clientMetadata = this._config.clientMetadata; }
1296
+ var internalUser = user;
1267
1297
  var attributeList = [];
1268
1298
  var that = this;
1299
+ var userAgentValue = getAuthUserAgentValue(AuthAction.UpdateUserAttributes, customUserAgentDetails);
1269
1300
  return new Promise(function (resolve, reject) {
1270
- that.userSession(user).then(function (session) {
1301
+ that._userSession(userAgentValue, internalUser).then(function (session) {
1271
1302
  for (var key in attributes) {
1272
1303
  if (key !== 'sub' && key.indexOf('_verified') < 0) {
1273
1304
  var attr = {
@@ -1277,7 +1308,7 @@ var InternalAuthClass = /** @class */ (function () {
1277
1308
  attributeList.push(attr);
1278
1309
  }
1279
1310
  }
1280
- user.updateAttributes(attributeList, function (err, result, details) {
1311
+ internalUser.updateAttributes(attributeList, function (err, result, details) {
1281
1312
  if (err) {
1282
1313
  dispatchAuthEvent('updateUserAttributes_failure', err, 'Failed to update attributes');
1283
1314
  return reject(err);
@@ -1287,7 +1318,7 @@ var InternalAuthClass = /** @class */ (function () {
1287
1318
  dispatchAuthEvent('updateUserAttributes', attrs, 'Attributes successfully updated');
1288
1319
  return resolve(result);
1289
1320
  }
1290
- }, clientMetadata);
1321
+ }, clientMetadata, userAgentValue);
1291
1322
  });
1292
1323
  });
1293
1324
  };
@@ -1312,23 +1343,28 @@ var InternalAuthClass = /** @class */ (function () {
1312
1343
  * @return - A promise resolves to user attributes if success
1313
1344
  */
1314
1345
  InternalAuthClass.prototype.userAttributes = function (user, customUserAgentDetails) {
1346
+ return this._userAttributes(user, customUserAgentDetails);
1347
+ };
1348
+ InternalAuthClass.prototype._userAttributes = function (user, customUserAgentDetails) {
1315
1349
  var _this = this;
1350
+ var internalUser = user;
1351
+ var userAgentValue = getAuthUserAgentValue(AuthAction.UserAttributes, customUserAgentDetails);
1316
1352
  return new Promise(function (resolve, reject) {
1317
- _this.userSession(user).then(function (session) {
1318
- user.getUserAttributes(function (err, attributes) {
1353
+ _this._userSession(userAgentValue, internalUser).then(function (session) {
1354
+ internalUser.getUserAttributes(function (err, attributes) {
1319
1355
  if (err) {
1320
1356
  reject(err);
1321
1357
  }
1322
1358
  else {
1323
1359
  resolve(attributes);
1324
1360
  }
1325
- });
1361
+ }, userAgentValue);
1326
1362
  });
1327
1363
  });
1328
1364
  };
1329
1365
  InternalAuthClass.prototype.verifiedContact = function (user, customUserAgentDetails) {
1330
1366
  var that = this;
1331
- return this.userAttributes(user).then(function (attributes) {
1367
+ return this._userAttributes(user, getAuthUserAgentDetails(AuthAction.VerifiedContact, customUserAgentDetails)).then(function (attributes) {
1332
1368
  var attrs = that.attributesToObject(attributes);
1333
1369
  var unverified = {};
1334
1370
  var verified = {};
@@ -1393,14 +1429,14 @@ var InternalAuthClass = /** @class */ (function () {
1393
1429
  this.isRefreshTokenExpiredError(err) ||
1394
1430
  this.isPasswordResetRequiredError(err));
1395
1431
  };
1396
- InternalAuthClass.prototype.cleanUpInvalidSession = function (user) {
1432
+ InternalAuthClass.prototype.cleanUpInvalidSession = function (internalUser, userAgentValue) {
1397
1433
  return __awaiter(this, void 0, void 0, function () {
1398
1434
  var e_7;
1399
1435
  var _this = this;
1400
1436
  return __generator(this, function (_a) {
1401
1437
  switch (_a.label) {
1402
1438
  case 0:
1403
- user.signOut();
1439
+ internalUser.signOut(undefined, userAgentValue);
1404
1440
  this.user = null;
1405
1441
  _a.label = 1;
1406
1442
  case 1:
@@ -1434,6 +1470,9 @@ var InternalAuthClass = /** @class */ (function () {
1434
1470
  * @return - A promise resolves to current authenticated CognitoUser if success
1435
1471
  */
1436
1472
  InternalAuthClass.prototype.currentUserPoolUser = function (params, customUserAgentDetails) {
1473
+ return this._currentUserPoolUser(params, customUserAgentDetails);
1474
+ };
1475
+ InternalAuthClass.prototype._currentUserPoolUser = function (params, customUserAgentDetails) {
1437
1476
  var _this = this;
1438
1477
  if (!this.userPool) {
1439
1478
  return this.rejectNoUserPool();
@@ -1441,7 +1480,7 @@ var InternalAuthClass = /** @class */ (function () {
1441
1480
  return new Promise(function (res, rej) {
1442
1481
  _this._storageSync
1443
1482
  .then(function () { return __awaiter(_this, void 0, void 0, function () {
1444
- var user, session, bypassCache, clientMetadata, _a, scope, err_1;
1483
+ var internalUser, userAgentValue_2, session, bypassCache, clientMetadata, _a, scope, err_1;
1445
1484
  var _this = this;
1446
1485
  return __generator(this, function (_b) {
1447
1486
  switch (_b.label) {
@@ -1471,8 +1510,8 @@ var InternalAuthClass = /** @class */ (function () {
1471
1510
  _b.sent();
1472
1511
  _b.label = 2;
1473
1512
  case 2:
1474
- user = this.userPool.getCurrentUser();
1475
- if (!user) {
1513
+ internalUser = this.userPool.getCurrentUser();
1514
+ if (!internalUser) {
1476
1515
  logger.debug('Failed to get user from user pool');
1477
1516
  rej('No current user');
1478
1517
  return [2 /*return*/];
@@ -1480,7 +1519,8 @@ var InternalAuthClass = /** @class */ (function () {
1480
1519
  _b.label = 3;
1481
1520
  case 3:
1482
1521
  _b.trys.push([3, 7, , 8]);
1483
- return [4 /*yield*/, this._userSession(user)];
1522
+ userAgentValue_2 = getAuthUserAgentValue(AuthAction.CurrentUserPoolUser, customUserAgentDetails);
1523
+ return [4 /*yield*/, this._userSession(userAgentValue_2, internalUser)];
1484
1524
  case 4:
1485
1525
  session = _b.sent();
1486
1526
  bypassCache = params ? params.bypassCache : false;
@@ -1493,7 +1533,7 @@ var InternalAuthClass = /** @class */ (function () {
1493
1533
  clientMetadata = this._config.clientMetadata;
1494
1534
  _a = session.getAccessToken().decodePayload().scope, scope = _a === void 0 ? '' : _a;
1495
1535
  if (scope.split(' ').includes(USER_ADMIN_SCOPE)) {
1496
- user.getUserData(function (err, data) { return __awaiter(_this, void 0, void 0, function () {
1536
+ internalUser.getUserData(function (err, data) { return __awaiter(_this, void 0, void 0, function () {
1497
1537
  var cleanUpError_5, preferredMFA, attributeList, i, attribute, userAttribute, attributes;
1498
1538
  return __generator(this, function (_a) {
1499
1539
  switch (_a.label) {
@@ -1504,7 +1544,7 @@ var InternalAuthClass = /** @class */ (function () {
1504
1544
  _a.label = 1;
1505
1545
  case 1:
1506
1546
  _a.trys.push([1, 3, , 4]);
1507
- return [4 /*yield*/, this.cleanUpInvalidSession(user)];
1547
+ return [4 /*yield*/, this.cleanUpInvalidSession(internalUser, userAgentValue_2)];
1508
1548
  case 2:
1509
1549
  _a.sent();
1510
1550
  return [3 /*break*/, 4];
@@ -1516,7 +1556,7 @@ var InternalAuthClass = /** @class */ (function () {
1516
1556
  rej(err);
1517
1557
  return [3 /*break*/, 6];
1518
1558
  case 5:
1519
- res(user);
1559
+ res(internalUser);
1520
1560
  _a.label = 6;
1521
1561
  case 6: return [2 /*return*/];
1522
1562
  case 7:
@@ -1531,16 +1571,16 @@ var InternalAuthClass = /** @class */ (function () {
1531
1571
  attributeList.push(userAttribute);
1532
1572
  }
1533
1573
  attributes = this.attributesToObject(attributeList);
1534
- Object.assign(user, { attributes: attributes, preferredMFA: preferredMFA });
1535
- return [2 /*return*/, res(user)];
1574
+ Object.assign(internalUser, { attributes: attributes, preferredMFA: preferredMFA });
1575
+ return [2 /*return*/, res(internalUser)];
1536
1576
  }
1537
1577
  });
1538
- }); }, { bypassCache: bypassCache, clientMetadata: clientMetadata });
1578
+ }); }, { bypassCache: bypassCache, clientMetadata: clientMetadata }, userAgentValue_2);
1539
1579
  }
1540
1580
  else {
1541
1581
  logger.debug("Unable to get the user data because the " + USER_ADMIN_SCOPE + " " +
1542
1582
  "is not in the scopes of the access token");
1543
- return [2 /*return*/, res(user)];
1583
+ return [2 /*return*/, res(internalUser)];
1544
1584
  }
1545
1585
  return [3 /*break*/, 8];
1546
1586
  case 7:
@@ -1567,6 +1607,9 @@ var InternalAuthClass = /** @class */ (function () {
1567
1607
  * @return - A promise resolves to current authenticated CognitoUser if success
1568
1608
  */
1569
1609
  InternalAuthClass.prototype.currentAuthenticatedUser = function (params, customUserAgentDetails) {
1610
+ return this._currentAuthenticatedUser(params, customUserAgentDetails);
1611
+ };
1612
+ InternalAuthClass.prototype._currentAuthenticatedUser = function (params, customUserAgentDetails) {
1570
1613
  return __awaiter(this, void 0, void 0, function () {
1571
1614
  var federatedUser, e_8, federatedInfo, user, e_9;
1572
1615
  return __generator(this, function (_a) {
@@ -1605,7 +1648,7 @@ var InternalAuthClass = /** @class */ (function () {
1605
1648
  _a.label = 6;
1606
1649
  case 6:
1607
1650
  _a.trys.push([6, 8, , 9]);
1608
- return [4 /*yield*/, this.currentUserPoolUser(params)];
1651
+ return [4 /*yield*/, this._currentUserPoolUser(params, getAuthUserAgentDetails(AuthAction.CurrentAuthenticatedUser, customUserAgentDetails))];
1609
1652
  case 7:
1610
1653
  user = _a.sent();
1611
1654
  return [3 /*break*/, 9];
@@ -1630,7 +1673,11 @@ var InternalAuthClass = /** @class */ (function () {
1630
1673
  * @return - A promise resolves to session object if success
1631
1674
  */
1632
1675
  InternalAuthClass.prototype.currentSession = function (customUserAgentDetails) {
1676
+ return this._currentSession(customUserAgentDetails);
1677
+ };
1678
+ InternalAuthClass.prototype._currentSession = function (customUserAgentDetails) {
1633
1679
  var that = this;
1680
+ var userAgentDetails = getAuthUserAgentDetails(AuthAction.CurrentSession, customUserAgentDetails);
1634
1681
  logger.debug('Getting current session');
1635
1682
  // Purposely not calling the reject method here because we don't need a console error
1636
1683
  if (!this.userPool) {
@@ -1638,10 +1685,10 @@ var InternalAuthClass = /** @class */ (function () {
1638
1685
  }
1639
1686
  return new Promise(function (res, rej) {
1640
1687
  that
1641
- .currentUserPoolUser()
1688
+ ._currentUserPoolUser(undefined, userAgentDetails)
1642
1689
  .then(function (user) {
1643
1690
  that
1644
- .userSession(user)
1691
+ ._userSession(getAmplifyUserAgent(userAgentDetails), user)
1645
1692
  .then(function (session) {
1646
1693
  res(session);
1647
1694
  return;
@@ -1659,14 +1706,14 @@ var InternalAuthClass = /** @class */ (function () {
1659
1706
  });
1660
1707
  });
1661
1708
  };
1662
- InternalAuthClass.prototype._userSession = function (user) {
1709
+ InternalAuthClass.prototype._userSession = function (userAgentValue, internalUser) {
1663
1710
  return __awaiter(this, void 0, void 0, function () {
1664
1711
  var clientMetadata, userSession;
1665
1712
  var _this = this;
1666
1713
  return __generator(this, function (_a) {
1667
1714
  switch (_a.label) {
1668
1715
  case 0:
1669
- if (!user) {
1716
+ if (!internalUser) {
1670
1717
  logger.debug('the user is null');
1671
1718
  return [2 /*return*/, this.rejectAuthError(AuthErrorTypes.NoUserSession)];
1672
1719
  }
@@ -1675,18 +1722,18 @@ var InternalAuthClass = /** @class */ (function () {
1675
1722
  // This solution assumes users will always call this function with the same CognitoUser instance.
1676
1723
  if (this.inflightSessionPromiseCounter === 0) {
1677
1724
  this.inflightSessionPromise = new Promise(function (res, rej) {
1678
- user.getSession(function (err, session) { return __awaiter(_this, void 0, void 0, function () {
1725
+ internalUser.getSession(function (err, session) { return __awaiter(_this, void 0, void 0, function () {
1679
1726
  var cleanUpError_6;
1680
1727
  return __generator(this, function (_a) {
1681
1728
  switch (_a.label) {
1682
1729
  case 0:
1683
1730
  if (!err) return [3 /*break*/, 5];
1684
- logger.debug('Failed to get the session from user', user);
1731
+ logger.debug('Failed to get the session from user', internalUser);
1685
1732
  if (!this.isSessionInvalid(err)) return [3 /*break*/, 4];
1686
1733
  _a.label = 1;
1687
1734
  case 1:
1688
1735
  _a.trys.push([1, 3, , 4]);
1689
- return [4 /*yield*/, this.cleanUpInvalidSession(user)];
1736
+ return [4 /*yield*/, this.cleanUpInvalidSession(internalUser, userAgentValue)];
1690
1737
  case 2:
1691
1738
  _a.sent();
1692
1739
  return [3 /*break*/, 4];
@@ -1703,7 +1750,7 @@ var InternalAuthClass = /** @class */ (function () {
1703
1750
  return [2 /*return*/];
1704
1751
  }
1705
1752
  });
1706
- }); }, { clientMetadata: clientMetadata });
1753
+ }); }, { clientMetadata: clientMetadata }, userAgentValue);
1707
1754
  });
1708
1755
  }
1709
1756
  this.inflightSessionPromiseCounter++;
@@ -1715,7 +1762,7 @@ var InternalAuthClass = /** @class */ (function () {
1715
1762
  userSession = _a.sent();
1716
1763
  // Set private member. Avoid user.setSignInUserSession() to prevent excessive localstorage refresh.
1717
1764
  // @ts-ignore
1718
- user.signInUserSession = userSession;
1765
+ internalUser.signInUserSession = userSession;
1719
1766
  return [2 /*return*/, userSession];
1720
1767
  case 3:
1721
1768
  this.inflightSessionPromiseCounter--;
@@ -1732,7 +1779,7 @@ var InternalAuthClass = /** @class */ (function () {
1732
1779
  * @return - A promise resolves to the session
1733
1780
  */
1734
1781
  InternalAuthClass.prototype.userSession = function (user, customUserAgentDetails) {
1735
- return this._userSession(user);
1782
+ return this._userSession(getAuthUserAgentValue(AuthAction.UserSession, customUserAgentDetails), user);
1736
1783
  };
1737
1784
  /**
1738
1785
  * Get authenticated credentials of current user.
@@ -1771,7 +1818,7 @@ var InternalAuthClass = /** @class */ (function () {
1771
1818
  return [2 /*return*/, this.Credentials.refreshFederatedToken(federatedInfo)];
1772
1819
  }
1773
1820
  else {
1774
- return [2 /*return*/, this.currentSession()
1821
+ return [2 /*return*/, this._currentSession(getAuthUserAgentDetails(AuthAction.CurrentUserCredentials, customUserAgentDetails))
1775
1822
  .then(function (session) {
1776
1823
  logger.debug('getting session success', session);
1777
1824
  return _this.Credentials.set(session, 'session');
@@ -1794,19 +1841,26 @@ var InternalAuthClass = /** @class */ (function () {
1794
1841
  * Initiate an attribute confirmation request
1795
1842
  * @param {Object} user - The CognitoUser
1796
1843
  * @param {Object} attr - The attributes to be verified
1844
+ * @param {ClientMetaData} clientMetadata - optional client metadata, defaults to config
1845
+ * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
1797
1846
  * @return - A promise resolves to callback data if success
1798
1847
  */
1799
1848
  InternalAuthClass.prototype.verifyUserAttribute = function (user, attr, clientMetadata, customUserAgentDetails) {
1800
1849
  if (clientMetadata === void 0) { clientMetadata = this._config.clientMetadata; }
1850
+ return this._verifyUserAttribute(user, attr, clientMetadata, customUserAgentDetails);
1851
+ };
1852
+ InternalAuthClass.prototype._verifyUserAttribute = function (user, attr, clientMetadata, customUserAgentDetails) {
1853
+ if (clientMetadata === void 0) { clientMetadata = this._config.clientMetadata; }
1854
+ var internalUser = user;
1801
1855
  return new Promise(function (resolve, reject) {
1802
- user.getAttributeVerificationCode(attr, {
1856
+ internalUser.getAttributeVerificationCode(attr, {
1803
1857
  onSuccess: function (success) {
1804
1858
  return resolve(success);
1805
1859
  },
1806
1860
  onFailure: function (err) {
1807
1861
  return reject(err);
1808
1862
  },
1809
- }, clientMetadata);
1863
+ }, clientMetadata, getAuthUserAgentValue(AuthAction.VerifyUserAttribute, customUserAgentDetails));
1810
1864
  });
1811
1865
  };
1812
1866
  /**
@@ -1818,11 +1872,15 @@ var InternalAuthClass = /** @class */ (function () {
1818
1872
  * @return - A promise resolves to callback data if success
1819
1873
  */
1820
1874
  InternalAuthClass.prototype.verifyUserAttributeSubmit = function (user, attr, code, customUserAgentDetails) {
1875
+ return this._verifyUserAttributeSubmit(user, attr, code, customUserAgentDetails);
1876
+ };
1877
+ InternalAuthClass.prototype._verifyUserAttributeSubmit = function (user, attr, code, customUserAgentDetails) {
1821
1878
  if (!code) {
1822
1879
  return this.rejectAuthError(AuthErrorTypes.EmptyCode);
1823
1880
  }
1881
+ var internalUser = user;
1824
1882
  return new Promise(function (resolve, reject) {
1825
- user.verifyAttribute(attr, code, {
1883
+ internalUser.verifyAttribute(attr, code, {
1826
1884
  onSuccess: function (data) {
1827
1885
  resolve(data);
1828
1886
  return;
@@ -1831,14 +1889,17 @@ var InternalAuthClass = /** @class */ (function () {
1831
1889
  reject(err);
1832
1890
  return;
1833
1891
  },
1834
- });
1892
+ }, getAuthUserAgentValue(AuthAction.VerifyUserAttributeSubmit, customUserAgentDetails));
1835
1893
  });
1836
1894
  };
1837
1895
  InternalAuthClass.prototype.verifyCurrentUserAttribute = function (attr, customUserAgentDetails) {
1896
+ var userAgentDetails = getAuthUserAgentDetails(AuthAction.VerifyCurrentUserAttribute, customUserAgentDetails);
1838
1897
  var that = this;
1839
1898
  return that
1840
- .currentUserPoolUser()
1841
- .then(function (user) { return that.verifyUserAttribute(user, attr); });
1899
+ ._currentUserPoolUser(undefined, userAgentDetails)
1900
+ .then(function (user) {
1901
+ return that._verifyUserAttribute(user, attr, undefined, userAgentDetails);
1902
+ });
1842
1903
  };
1843
1904
  /**
1844
1905
  * Confirm current user's attribute using a confirmation code
@@ -1848,12 +1909,15 @@ var InternalAuthClass = /** @class */ (function () {
1848
1909
  * @return - A promise resolves to callback data if success
1849
1910
  */
1850
1911
  InternalAuthClass.prototype.verifyCurrentUserAttributeSubmit = function (attr, code, customUserAgentDetails) {
1912
+ var userAgentDetails = getAuthUserAgentDetails(AuthAction.VerifyCurrentUserAttributeSubmit, customUserAgentDetails);
1851
1913
  var that = this;
1852
1914
  return that
1853
- .currentUserPoolUser()
1854
- .then(function (user) { return that.verifyUserAttributeSubmit(user, attr, code); });
1915
+ ._currentUserPoolUser(undefined, userAgentDetails)
1916
+ .then(function (user) {
1917
+ return that._verifyUserAttributeSubmit(user, attr, code, userAgentDetails);
1918
+ });
1855
1919
  };
1856
- InternalAuthClass.prototype.cognitoIdentitySignOut = function (opts, user) {
1920
+ InternalAuthClass.prototype.cognitoIdentitySignOut = function (opts, internalUser, userAgentValue) {
1857
1921
  return __awaiter(this, void 0, void 0, function () {
1858
1922
  var e_11, isSignedInHostedUI;
1859
1923
  var _this = this;
@@ -1874,11 +1938,11 @@ var InternalAuthClass = /** @class */ (function () {
1874
1938
  this._storage.getItem('amplify-signin-with-hostedUI') === 'true';
1875
1939
  return [2 /*return*/, new Promise(function (res, rej) {
1876
1940
  if (opts && opts.global) {
1877
- logger.debug('user global sign out', user);
1941
+ logger.debug('user global sign out', internalUser);
1878
1942
  // in order to use global signout
1879
1943
  // we must validate the user as an authenticated user by using getSession
1880
1944
  var clientMetadata = _this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
1881
- user.getSession(function (err, result) { return __awaiter(_this, void 0, void 0, function () {
1945
+ internalUser.getSession(function (err, result) { return __awaiter(_this, void 0, void 0, function () {
1882
1946
  var cleanUpError_7;
1883
1947
  var _this = this;
1884
1948
  return __generator(this, function (_a) {
@@ -1890,7 +1954,7 @@ var InternalAuthClass = /** @class */ (function () {
1890
1954
  _a.label = 1;
1891
1955
  case 1:
1892
1956
  _a.trys.push([1, 3, , 4]);
1893
- return [4 /*yield*/, this.cleanUpInvalidSession(user)];
1957
+ return [4 /*yield*/, this.cleanUpInvalidSession(internalUser, userAgentValue)];
1894
1958
  case 2:
1895
1959
  _a.sent();
1896
1960
  return [3 /*break*/, 4];
@@ -1900,7 +1964,7 @@ var InternalAuthClass = /** @class */ (function () {
1900
1964
  return [2 /*return*/];
1901
1965
  case 4: return [2 /*return*/, rej(err)];
1902
1966
  case 5:
1903
- user.globalSignOut({
1967
+ internalUser.globalSignOut({
1904
1968
  onSuccess: function (data) {
1905
1969
  logger.debug('global sign out success');
1906
1970
  if (isSignedInHostedUI) {
@@ -1914,22 +1978,22 @@ var InternalAuthClass = /** @class */ (function () {
1914
1978
  logger.debug('global sign out failed', err);
1915
1979
  return rej(err);
1916
1980
  },
1917
- });
1981
+ }, userAgentValue);
1918
1982
  return [2 /*return*/];
1919
1983
  }
1920
1984
  });
1921
- }); }, { clientMetadata: clientMetadata });
1985
+ }); }, { clientMetadata: clientMetadata }, userAgentValue);
1922
1986
  }
1923
1987
  else {
1924
- logger.debug('user sign out', user);
1925
- user.signOut(function () {
1988
+ logger.debug('user sign out', internalUser);
1989
+ internalUser.signOut(function () {
1926
1990
  if (isSignedInHostedUI) {
1927
1991
  _this.oAuthSignOutRedirect(res, rej);
1928
1992
  }
1929
1993
  else {
1930
1994
  return res();
1931
1995
  }
1932
- });
1996
+ }, userAgentValue);
1933
1997
  }
1934
1998
  })];
1935
1999
  }
@@ -1962,7 +2026,7 @@ var InternalAuthClass = /** @class */ (function () {
1962
2026
  */
1963
2027
  InternalAuthClass.prototype.signOut = function (opts, customUserAgentDetails) {
1964
2028
  return __awaiter(this, void 0, void 0, function () {
1965
- var e_12, user;
2029
+ var e_12, internalUser;
1966
2030
  return __generator(this, function (_a) {
1967
2031
  switch (_a.label) {
1968
2032
  case 0:
@@ -1977,9 +2041,9 @@ var InternalAuthClass = /** @class */ (function () {
1977
2041
  return [3 /*break*/, 3];
1978
2042
  case 3:
1979
2043
  if (!this.userPool) return [3 /*break*/, 7];
1980
- user = this.userPool.getCurrentUser();
1981
- if (!user) return [3 /*break*/, 5];
1982
- return [4 /*yield*/, this.cognitoIdentitySignOut(opts, user)];
2044
+ internalUser = this.userPool.getCurrentUser();
2045
+ if (!internalUser) return [3 /*break*/, 5];
2046
+ return [4 /*yield*/, this.cognitoIdentitySignOut(opts, internalUser, getAuthUserAgentValue(AuthAction.SignOut, customUserAgentDetails))];
1983
2047
  case 4:
1984
2048
  _a.sent();
1985
2049
  return [3 /*break*/, 6];
@@ -2031,9 +2095,11 @@ var InternalAuthClass = /** @class */ (function () {
2031
2095
  InternalAuthClass.prototype.changePassword = function (user, oldPassword, newPassword, clientMetadata, customUserAgentDetails) {
2032
2096
  var _this = this;
2033
2097
  if (clientMetadata === void 0) { clientMetadata = this._config.clientMetadata; }
2098
+ var internalUser = user;
2099
+ var userAgentValue = getAuthUserAgentValue(AuthAction.ChangePassword, customUserAgentDetails);
2034
2100
  return new Promise(function (resolve, reject) {
2035
- _this.userSession(user).then(function (session) {
2036
- user.changePassword(oldPassword, newPassword, function (err, data) {
2101
+ _this._userSession(userAgentValue, internalUser).then(function (session) {
2102
+ internalUser.changePassword(oldPassword, newPassword, function (err, data) {
2037
2103
  if (err) {
2038
2104
  logger.debug('change password failure', err);
2039
2105
  return reject(err);
@@ -2041,7 +2107,7 @@ var InternalAuthClass = /** @class */ (function () {
2041
2107
  else {
2042
2108
  return resolve(data);
2043
2109
  }
2044
- }, clientMetadata);
2110
+ }, clientMetadata, userAgentValue);
2045
2111
  });
2046
2112
  });
2047
2113
  };
@@ -2060,9 +2126,9 @@ var InternalAuthClass = /** @class */ (function () {
2060
2126
  if (!username) {
2061
2127
  return this.rejectAuthError(AuthErrorTypes.EmptyUsername);
2062
2128
  }
2063
- var user = this.createCognitoUser(username);
2129
+ var internalUser = this.createCognitoUser(username);
2064
2130
  return new Promise(function (resolve, reject) {
2065
- user.forgotPassword({
2131
+ internalUser.forgotPassword({
2066
2132
  onSuccess: function () {
2067
2133
  resolve();
2068
2134
  return;
@@ -2074,11 +2140,11 @@ var InternalAuthClass = /** @class */ (function () {
2074
2140
  return;
2075
2141
  },
2076
2142
  inputVerificationCode: function (data) {
2077
- dispatchAuthEvent('forgotPassword', user, username + " has initiated forgot password flow");
2143
+ dispatchAuthEvent('forgotPassword', internalUser, username + " has initiated forgot password flow");
2078
2144
  resolve(data);
2079
2145
  return;
2080
2146
  },
2081
- }, clientMetadata);
2147
+ }, clientMetadata, getAuthUserAgentValue(AuthAction.ForgotPassword, customUserAgentDetails));
2082
2148
  });
2083
2149
  };
2084
2150
  /**
@@ -2104,11 +2170,11 @@ var InternalAuthClass = /** @class */ (function () {
2104
2170
  if (!password) {
2105
2171
  return this.rejectAuthError(AuthErrorTypes.EmptyPassword);
2106
2172
  }
2107
- var user = this.createCognitoUser(username);
2173
+ var internalUser = this.createCognitoUser(username);
2108
2174
  return new Promise(function (resolve, reject) {
2109
- user.confirmPassword(code, password, {
2175
+ internalUser.confirmPassword(code, password, {
2110
2176
  onSuccess: function (success) {
2111
- dispatchAuthEvent('forgotPasswordSubmit', user, username + " forgotPasswordSubmit successful");
2177
+ dispatchAuthEvent('forgotPasswordSubmit', internalUser, username + " forgotPasswordSubmit successful");
2112
2178
  resolve(success);
2113
2179
  return;
2114
2180
  },
@@ -2117,7 +2183,7 @@ var InternalAuthClass = /** @class */ (function () {
2117
2183
  reject(err);
2118
2184
  return;
2119
2185
  },
2120
- }, clientMetadata);
2186
+ }, clientMetadata, getAuthUserAgentValue(AuthAction.ForgotPasswordSubmit, customUserAgentDetails));
2121
2187
  });
2122
2188
  };
2123
2189
  /**
@@ -2128,24 +2194,23 @@ var InternalAuthClass = /** @class */ (function () {
2128
2194
  */
2129
2195
  InternalAuthClass.prototype.currentUserInfo = function (customUserAgentDetails) {
2130
2196
  return __awaiter(this, void 0, void 0, function () {
2131
- var source, user, attributes, userAttrs, credentials, e_13, info, err_2, user;
2197
+ var source, userAgentDetails, internalUser, attributes, userAttrs, credentials, e_13, info, err_2, user;
2132
2198
  return __generator(this, function (_a) {
2133
2199
  switch (_a.label) {
2134
2200
  case 0:
2135
2201
  source = this.Credentials.getCredSource();
2202
+ userAgentDetails = getAuthUserAgentDetails(AuthAction.CurrentUserInfo, customUserAgentDetails);
2136
2203
  if (!(!source || source === 'aws' || source === 'userPool')) return [3 /*break*/, 9];
2137
- return [4 /*yield*/, this.currentUserPoolUser().catch(function (err) {
2138
- return logger.error(err);
2139
- })];
2204
+ return [4 /*yield*/, this._currentUserPoolUser(undefined, userAgentDetails).catch(function (err) { return logger.error(err); })];
2140
2205
  case 1:
2141
- user = _a.sent();
2142
- if (!user) {
2206
+ internalUser = _a.sent();
2207
+ if (!internalUser) {
2143
2208
  return [2 /*return*/, null];
2144
2209
  }
2145
2210
  _a.label = 2;
2146
2211
  case 2:
2147
2212
  _a.trys.push([2, 8, , 9]);
2148
- return [4 /*yield*/, this.userAttributes(user)];
2213
+ return [4 /*yield*/, this._userAttributes(internalUser, userAgentDetails)];
2149
2214
  case 3:
2150
2215
  attributes = _a.sent();
2151
2216
  userAttrs = this.attributesToObject(attributes);
@@ -2164,7 +2229,7 @@ var InternalAuthClass = /** @class */ (function () {
2164
2229
  case 7:
2165
2230
  info = {
2166
2231
  id: credentials ? credentials.identityId : undefined,
2167
- username: user.getUsername(),
2232
+ username: internalUser.getUsername(),
2168
2233
  attributes: userAttrs,
2169
2234
  };
2170
2235
  return [2 /*return*/, info];
@@ -2217,6 +2282,7 @@ var InternalAuthClass = /** @class */ (function () {
2217
2282
  redirect_uri = isCognitoHostedOpts(this._config.oauth)
2218
2283
  ? this._config.oauth.redirectSignIn
2219
2284
  : this._config.oauth.redirectUri;
2285
+ this._storage.setItem('aws-amplify-federatedUserAgent', getAuthUserAgentValue(AuthAction.FederatedSignIn, customUserAgentDetails));
2220
2286
  this._oAuthHandler.oauthSignIn(this._config.oauth.responseType, this._config.oauth.domain, redirect_uri, client_id, provider, customState);
2221
2287
  }
2222
2288
  return [3 /*break*/, 4];
@@ -2234,7 +2300,7 @@ var InternalAuthClass = /** @class */ (function () {
2234
2300
  return [4 /*yield*/, this.Credentials.set({ provider: provider, token: token, identity_id: identity_id, user: user, expires_at: expires_at }, 'federation')];
2235
2301
  case 2:
2236
2302
  credentials = _a.sent();
2237
- return [4 /*yield*/, this.currentAuthenticatedUser()];
2303
+ return [4 /*yield*/, this._currentAuthenticatedUser()];
2238
2304
  case 3:
2239
2305
  currentUser = _a.sent();
2240
2306
  dispatchAuthEvent('signIn', currentUser, "A user " + currentUser.username + " has been signed in");
@@ -2251,7 +2317,7 @@ var InternalAuthClass = /** @class */ (function () {
2251
2317
  */
2252
2318
  InternalAuthClass.prototype._handleAuthResponse = function (URL) {
2253
2319
  return __awaiter(this, void 0, void 0, function () {
2254
- var currentUrl, hasCodeOrError, hasTokenOrError, _a, accessToken, idToken, refreshToken, state, session, credentials, isCustomStateIncluded, currentUser, customState, err_3;
2320
+ var currentUrl, hasCodeOrError, hasTokenOrError, userAgentValue, _a, accessToken, idToken, refreshToken, state, session, credentials, isCustomStateIncluded, currentUser, customState, err_3;
2255
2321
  return __generator(this, function (_b) {
2256
2322
  switch (_b.label) {
2257
2323
  case 0:
@@ -2285,10 +2351,12 @@ var InternalAuthClass = /** @class */ (function () {
2285
2351
  });
2286
2352
  if (!(hasCodeOrError || hasTokenOrError)) return [3 /*break*/, 7];
2287
2353
  this._storage.setItem('amplify-redirected-from-hosted-ui', 'true');
2354
+ userAgentValue = this._storage.getItem('aws-amplify-federatedUserAgent') || undefined;
2355
+ this._storage.removeItem('aws-amplify-federatedUserAgent');
2288
2356
  _b.label = 2;
2289
2357
  case 2:
2290
2358
  _b.trys.push([2, 6, , 7]);
2291
- return [4 /*yield*/, this._oAuthHandler.handleAuthResponse(currentUrl)];
2359
+ return [4 /*yield*/, this._oAuthHandler.handleAuthResponse(currentUrl, userAgentValue)];
2292
2360
  case 3:
2293
2361
  _a = _b.sent(), accessToken = _a.accessToken, idToken = _a.idToken, refreshToken = _a.refreshToken, state = _a.state;
2294
2362
  session = new CognitoUserSession({
@@ -2385,11 +2453,11 @@ var InternalAuthClass = /** @class */ (function () {
2385
2453
  };
2386
2454
  userData.Storage = this._storage;
2387
2455
  var authenticationFlowType = this._config.authenticationFlowType;
2388
- var user = new CognitoUser(userData);
2456
+ var internalUser = new InternalCognitoUser(userData);
2389
2457
  if (authenticationFlowType) {
2390
- user.setAuthenticationFlowType(authenticationFlowType);
2458
+ internalUser.setAuthenticationFlowType(authenticationFlowType);
2391
2459
  }
2392
- return user;
2460
+ return internalUser;
2393
2461
  };
2394
2462
  InternalAuthClass.prototype._isValidAuthStorage = function (obj) {
2395
2463
  // We need to check if the obj has the functions of Storage
@@ -2416,23 +2484,26 @@ var InternalAuthClass = /** @class */ (function () {
2416
2484
  };
2417
2485
  InternalAuthClass.prototype.rememberDevice = function (customUserAgentDetails) {
2418
2486
  return __awaiter(this, void 0, void 0, function () {
2419
- var currUser, error_2;
2487
+ var internalUser, userAgentDetails, error_2;
2420
2488
  return __generator(this, function (_a) {
2421
2489
  switch (_a.label) {
2422
2490
  case 0:
2423
- _a.trys.push([0, 2, , 3]);
2424
- return [4 /*yield*/, this.currentUserPoolUser()];
2491
+ userAgentDetails = getAuthUserAgentDetails(AuthAction.RememberDevice, customUserAgentDetails);
2492
+ _a.label = 1;
2425
2493
  case 1:
2426
- currUser = _a.sent();
2427
- return [3 /*break*/, 3];
2494
+ _a.trys.push([1, 3, , 4]);
2495
+ return [4 /*yield*/, this._currentUserPoolUser(undefined, userAgentDetails)];
2428
2496
  case 2:
2497
+ internalUser = _a.sent();
2498
+ return [3 /*break*/, 4];
2499
+ case 3:
2429
2500
  error_2 = _a.sent();
2430
2501
  logger.debug('The user is not authenticated by the error', error_2);
2431
2502
  return [2 /*return*/, Promise.reject('The user is not authenticated')];
2432
- case 3:
2433
- currUser.getCachedDeviceKeyAndPassword();
2503
+ case 4:
2504
+ internalUser.getCachedDeviceKeyAndPassword();
2434
2505
  return [2 /*return*/, new Promise(function (res, rej) {
2435
- currUser.setDeviceStatusRemembered({
2506
+ internalUser.setDeviceStatusRemembered({
2436
2507
  onSuccess: function (data) {
2437
2508
  res(data);
2438
2509
  },
@@ -2447,7 +2518,7 @@ var InternalAuthClass = /** @class */ (function () {
2447
2518
  rej(err);
2448
2519
  }
2449
2520
  },
2450
- });
2521
+ }, getAmplifyUserAgent(userAgentDetails));
2451
2522
  })];
2452
2523
  }
2453
2524
  });
@@ -2455,23 +2526,26 @@ var InternalAuthClass = /** @class */ (function () {
2455
2526
  };
2456
2527
  InternalAuthClass.prototype.forgetDevice = function (customUserAgentDetails) {
2457
2528
  return __awaiter(this, void 0, void 0, function () {
2458
- var currUser, error_3;
2529
+ var internalUser, userAgentDetails, error_3;
2459
2530
  return __generator(this, function (_a) {
2460
2531
  switch (_a.label) {
2461
2532
  case 0:
2462
- _a.trys.push([0, 2, , 3]);
2463
- return [4 /*yield*/, this.currentUserPoolUser()];
2533
+ userAgentDetails = getAuthUserAgentDetails(AuthAction.ForgetDevice, customUserAgentDetails);
2534
+ _a.label = 1;
2464
2535
  case 1:
2465
- currUser = _a.sent();
2466
- return [3 /*break*/, 3];
2536
+ _a.trys.push([1, 3, , 4]);
2537
+ return [4 /*yield*/, this._currentUserPoolUser(undefined, userAgentDetails)];
2467
2538
  case 2:
2539
+ internalUser = _a.sent();
2540
+ return [3 /*break*/, 4];
2541
+ case 3:
2468
2542
  error_3 = _a.sent();
2469
2543
  logger.debug('The user is not authenticated by the error', error_3);
2470
2544
  return [2 /*return*/, Promise.reject('The user is not authenticated')];
2471
- case 3:
2472
- currUser.getCachedDeviceKeyAndPassword();
2545
+ case 4:
2546
+ internalUser.getCachedDeviceKeyAndPassword();
2473
2547
  return [2 /*return*/, new Promise(function (res, rej) {
2474
- currUser.forgetDevice({
2548
+ internalUser.forgetDevice({
2475
2549
  onSuccess: function (data) {
2476
2550
  res(data);
2477
2551
  },
@@ -2486,7 +2560,7 @@ var InternalAuthClass = /** @class */ (function () {
2486
2560
  rej(err);
2487
2561
  }
2488
2562
  },
2489
- });
2563
+ }, getAmplifyUserAgent(userAgentDetails));
2490
2564
  })];
2491
2565
  }
2492
2566
  });
@@ -2494,21 +2568,24 @@ var InternalAuthClass = /** @class */ (function () {
2494
2568
  };
2495
2569
  InternalAuthClass.prototype.fetchDevices = function (customUserAgentDetails) {
2496
2570
  return __awaiter(this, void 0, void 0, function () {
2497
- var currUser, error_4;
2571
+ var internalUser, userAgentDetails, error_4;
2498
2572
  return __generator(this, function (_a) {
2499
2573
  switch (_a.label) {
2500
2574
  case 0:
2501
- _a.trys.push([0, 2, , 3]);
2502
- return [4 /*yield*/, this.currentUserPoolUser()];
2575
+ userAgentDetails = getAuthUserAgentDetails(AuthAction.FetchDevices, customUserAgentDetails);
2576
+ _a.label = 1;
2503
2577
  case 1:
2504
- currUser = _a.sent();
2505
- return [3 /*break*/, 3];
2578
+ _a.trys.push([1, 3, , 4]);
2579
+ return [4 /*yield*/, this._currentUserPoolUser(undefined, userAgentDetails)];
2506
2580
  case 2:
2581
+ internalUser = _a.sent();
2582
+ return [3 /*break*/, 4];
2583
+ case 3:
2507
2584
  error_4 = _a.sent();
2508
2585
  logger.debug('The user is not authenticated by the error', error_4);
2509
2586
  throw new Error('The user is not authenticated');
2510
- case 3:
2511
- currUser.getCachedDeviceKeyAndPassword();
2587
+ case 4:
2588
+ internalUser.getCachedDeviceKeyAndPassword();
2512
2589
  return [2 /*return*/, new Promise(function (res, rej) {
2513
2590
  var cb = {
2514
2591
  onSuccess: function (data) {
@@ -2537,7 +2614,7 @@ var InternalAuthClass = /** @class */ (function () {
2537
2614
  }
2538
2615
  },
2539
2616
  };
2540
- currUser.listDevices(MAX_DEVICES, null, cb);
2617
+ internalUser.listDevices(MAX_DEVICES, null, cb, getAmplifyUserAgent(userAgentDetails));
2541
2618
  })];
2542
2619
  }
2543
2620
  });