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