@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.
@@ -25,9 +25,11 @@ import {
25
25
 
26
26
  import {
27
27
  Amplify,
28
+ AuthAction,
28
29
  ConsoleLogger as Logger,
29
30
  Credentials,
30
31
  CustomUserAgentDetails,
32
+ getAmplifyUserAgent,
31
33
  Hub,
32
34
  StorageHelper,
33
35
  ICredentials,
@@ -40,7 +42,6 @@ import {
40
42
  } from '@aws-amplify/core';
41
43
  import {
42
44
  CookieStorage,
43
- CognitoUserPool,
44
45
  AuthenticationDetails,
45
46
  ICognitoUserPoolData,
46
47
  ICognitoUserData,
@@ -60,6 +61,8 @@ import {
60
61
  import {
61
62
  addAuthCategoryToCognitoUserAgent,
62
63
  addFrameworkToCognitoUserAgent,
64
+ InternalCognitoUser,
65
+ InternalCognitoUserPool,
63
66
  } from 'amazon-cognito-identity-js/internals';
64
67
 
65
68
  import { parse } from 'url';
@@ -72,6 +75,7 @@ import {
72
75
  CognitoHostedUIIdentityProvider,
73
76
  IAuthDevice,
74
77
  } from '../types/Auth';
78
+ import { getAuthUserAgentDetails, getAuthUserAgentValue } from '../utils';
75
79
 
76
80
  const logger = new Logger('AuthClass');
77
81
  const USER_ADMIN_SCOPE = 'aws.cognito.signin.user.admin';
@@ -101,7 +105,7 @@ const MAX_AUTOSIGNIN_POLLING_MS = 3 * 60 * 1000;
101
105
  */
102
106
  export class InternalAuthClass {
103
107
  private _config: AuthOptions;
104
- private userPool: CognitoUserPool = null;
108
+ private userPool: InternalCognitoUserPool = null;
105
109
  private user: any = null;
106
110
  private _oAuthHandler: OAuth;
107
111
  private _storage;
@@ -205,7 +209,7 @@ export class InternalAuthClass {
205
209
  };
206
210
  userPoolData.Storage = this._storage;
207
211
 
208
- this.userPool = new CognitoUserPool(
212
+ this.userPool = new InternalCognitoUserPool(
209
213
  userPoolData,
210
214
  this.wrapRefreshSessionCallback
211
215
  );
@@ -408,6 +412,10 @@ export class InternalAuthClass {
408
412
  logger.debug('signUp validation data:', validationData);
409
413
 
410
414
  return new Promise((resolve, reject) => {
415
+ const userAgentDetails = getAuthUserAgentDetails(
416
+ AuthAction.SignUp,
417
+ customUserAgentDetails
418
+ );
411
419
  this.userPool.signUp(
412
420
  username,
413
421
  password,
@@ -433,13 +441,15 @@ export class InternalAuthClass {
433
441
  password,
434
442
  autoSignInValidationData,
435
443
  autoSignInClientMetaData,
436
- data
444
+ data,
445
+ userAgentDetails
437
446
  );
438
447
  }
439
448
  resolve(data);
440
449
  }
441
450
  },
442
- clientMetadata
451
+ clientMetadata,
452
+ getAmplifyUserAgent(userAgentDetails)
443
453
  );
444
454
  });
445
455
  }
@@ -449,7 +459,8 @@ export class InternalAuthClass {
449
459
  password: string,
450
460
  validationData: {},
451
461
  clientMetadata: any,
452
- data: any
462
+ data: any,
463
+ customUserAgentDetails: CustomUserAgentDetails
453
464
  ) {
454
465
  this.autoSignInInitiated = true;
455
466
  const authDetails = new AuthenticationDetails({
@@ -459,24 +470,34 @@ export class InternalAuthClass {
459
470
  ClientMetadata: clientMetadata,
460
471
  });
461
472
  if (data.userConfirmed) {
462
- this.signInAfterUserConfirmed(authDetails);
473
+ this.signInAfterUserConfirmed(authDetails, customUserAgentDetails);
463
474
  } else if (this._config.signUpVerificationMethod === 'link') {
464
- this.handleLinkAutoSignIn(authDetails);
475
+ this.handleLinkAutoSignIn(authDetails, customUserAgentDetails);
465
476
  } else {
466
- this.handleCodeAutoSignIn(authDetails);
477
+ this.handleCodeAutoSignIn(authDetails, customUserAgentDetails);
467
478
  }
468
479
  }
469
480
 
470
- private handleCodeAutoSignIn(authDetails: AuthenticationDetails) {
481
+ private handleCodeAutoSignIn(
482
+ authDetails: AuthenticationDetails,
483
+ customUserAgentDetails: CustomUserAgentDetails
484
+ ) {
471
485
  const listenEvent = ({ payload }) => {
472
486
  if (payload.event === 'confirmSignUp') {
473
- this.signInAfterUserConfirmed(authDetails, listenEvent);
487
+ this.signInAfterUserConfirmed(
488
+ authDetails,
489
+ customUserAgentDetails,
490
+ listenEvent
491
+ );
474
492
  }
475
493
  };
476
494
  Hub.listen('auth', listenEvent);
477
495
  }
478
496
 
479
- private handleLinkAutoSignIn(authDetails: AuthenticationDetails) {
497
+ private handleLinkAutoSignIn(
498
+ authDetails: AuthenticationDetails,
499
+ customUserAgentDetails: CustomUserAgentDetails
500
+ ) {
480
501
  this._storage.setItem('amplify-polling-started', 'true');
481
502
  const start = Date.now();
482
503
  const autoSignInPollingIntervalId = setInterval(() => {
@@ -491,7 +512,8 @@ export class InternalAuthClass {
491
512
  } else {
492
513
  this.signInAfterUserConfirmed(
493
514
  authDetails,
494
- null,
515
+ customUserAgentDetails,
516
+ undefined,
495
517
  autoSignInPollingIntervalId
496
518
  );
497
519
  }
@@ -500,6 +522,7 @@ export class InternalAuthClass {
500
522
 
501
523
  private async signInAfterUserConfirmed(
502
524
  authDetails: AuthenticationDetails,
525
+ customUserAgentDetails: CustomUserAgentDetails,
503
526
  listenEvent?: HubCallback,
504
527
  autoSignInPollingIntervalId?: ReturnType<typeof setInterval>
505
528
  ) {
@@ -527,8 +550,10 @@ export class InternalAuthClass {
527
550
  error => {
528
551
  logger.error(error);
529
552
  this._storage.removeItem('amplify-auto-sign-in');
530
- }
531
- )
553
+ },
554
+ customUserAgentDetails
555
+ ),
556
+ getAmplifyUserAgent(customUserAgentDetails)
532
557
  );
533
558
  } catch (error) {
534
559
  logger.error(error);
@@ -596,7 +621,8 @@ export class InternalAuthClass {
596
621
  resolve(data);
597
622
  }
598
623
  },
599
- clientMetadata
624
+ clientMetadata,
625
+ getAuthUserAgentValue(AuthAction.ConfirmSignUp, customUserAgentDetails)
600
626
  );
601
627
  });
602
628
  }
@@ -627,13 +653,17 @@ export class InternalAuthClass {
627
653
 
628
654
  const user = this.createCognitoUser(username);
629
655
  return new Promise((resolve, reject) => {
630
- user.resendConfirmationCode((err, data) => {
631
- if (err) {
632
- reject(err);
633
- } else {
634
- resolve(data);
635
- }
636
- }, clientMetadata);
656
+ user.resendConfirmationCode(
657
+ (err, data) => {
658
+ if (err) {
659
+ reject(err);
660
+ } else {
661
+ resolve(data);
662
+ }
663
+ },
664
+ clientMetadata,
665
+ getAuthUserAgentValue(AuthAction.ResendSignUp, customUserAgentDetails)
666
+ );
637
667
  });
638
668
  }
639
669
 
@@ -683,24 +713,29 @@ export class InternalAuthClass {
683
713
  ValidationData: validationData,
684
714
  ClientMetadata: clientMetadata,
685
715
  });
716
+ const userAgentDetails = getAuthUserAgentDetails(
717
+ AuthAction.SignIn,
718
+ customUserAgentDetails
719
+ );
686
720
  if (password) {
687
- return this.signInWithPassword(authDetails);
721
+ return this.signInWithPassword(authDetails, userAgentDetails);
688
722
  } else {
689
- return this.signInWithoutPassword(authDetails);
723
+ return this.signInWithoutPassword(authDetails, userAgentDetails);
690
724
  }
691
725
  }
692
726
 
693
727
  /**
694
728
  * Return an object with the authentication callbacks
695
- * @param {CognitoUser} user - the cognito user object
729
+ * @param {InternalCognitoUser} user - the cognito user object
696
730
  * @param {} resolve - function called when resolving the current step
697
731
  * @param {} reject - function called when rejecting the current step
698
732
  * @return - an object with the callback methods for user authentication
699
733
  */
700
734
  private authCallbacks(
701
- user: CognitoUser,
702
- resolve: (value?: CognitoUser | any) => void,
703
- reject: (value?: any) => void
735
+ user: InternalCognitoUser,
736
+ resolve: (value?: InternalCognitoUser | any) => void,
737
+ reject: (value?: any) => void,
738
+ customUserAgentDetails: CustomUserAgentDetails
704
739
  ): IAuthenticationCallback {
705
740
  const that = this;
706
741
  return {
@@ -718,7 +753,10 @@ export class InternalAuthClass {
718
753
  try {
719
754
  // In order to get user attributes and MFA methods
720
755
  // We need to trigger currentUserPoolUser again
721
- const currentUser = await this.currentUserPoolUser();
756
+ const currentUser = await this._currentUserPoolUser(
757
+ undefined,
758
+ customUserAgentDetails
759
+ );
722
760
  that.user = currentUser;
723
761
  dispatchAuthEvent(
724
762
  'signIn',
@@ -787,11 +825,13 @@ export class InternalAuthClass {
787
825
  * Sign in with a password
788
826
  * @private
789
827
  * @param {AuthenticationDetails} authDetails - the user sign in data
828
+ * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
790
829
  * @return - A promise resolves the CognitoUser object if success or mfa required
791
830
  */
792
831
  private signInWithPassword(
793
- authDetails: AuthenticationDetails
794
- ): Promise<CognitoUser | any> {
832
+ authDetails: AuthenticationDetails,
833
+ customUserAgentDetails: CustomUserAgentDetails
834
+ ): Promise<InternalCognitoUser | any> {
795
835
  if (this.pendingSignIn) {
796
836
  throw new Error('Pending sign-in attempt already in progress');
797
837
  }
@@ -810,8 +850,10 @@ export class InternalAuthClass {
810
850
  error => {
811
851
  this.pendingSignIn = null;
812
852
  reject(error);
813
- }
814
- )
853
+ },
854
+ customUserAgentDetails
855
+ ),
856
+ getAmplifyUserAgent(customUserAgentDetails)
815
857
  );
816
858
  });
817
859
 
@@ -822,16 +864,22 @@ export class InternalAuthClass {
822
864
  * Sign in without a password
823
865
  * @private
824
866
  * @param {AuthenticationDetails} authDetails - the user sign in data
825
- * @return - A promise resolves the CognitoUser object if success or mfa required
867
+ * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
868
+ * @return - A promise resolves the InternalCognitoUser object if success or mfa required
826
869
  */
827
870
  private signInWithoutPassword(
828
- authDetails: AuthenticationDetails
829
- ): Promise<CognitoUser | any> {
871
+ authDetails: AuthenticationDetails,
872
+ customUserAgentDetails: CustomUserAgentDetails
873
+ ): Promise<InternalCognitoUser | any> {
830
874
  const user = this.createCognitoUser(authDetails.getUsername());
831
875
  user.setAuthenticationFlowType('CUSTOM_AUTH');
832
876
 
833
877
  return new Promise((resolve, reject) => {
834
- user.initiateAuth(authDetails, this.authCallbacks(user, resolve, reject));
878
+ user.initiateAuth(
879
+ authDetails,
880
+ this.authCallbacks(user, resolve, reject, customUserAgentDetails),
881
+ getAmplifyUserAgent(customUserAgentDetails)
882
+ );
835
883
  });
836
884
  }
837
885
 
@@ -848,8 +896,10 @@ export class InternalAuthClass {
848
896
  user: CognitoUser | any,
849
897
  customUserAgentDetails?: CustomUserAgentDetails
850
898
  ): Promise<MFAOption[]> {
899
+ const internalUser: InternalCognitoUser | any = user;
900
+
851
901
  return new Promise((res, rej) => {
852
- user.getMFAOptions((err, mfaOptions) => {
902
+ internalUser.getMFAOptions((err, mfaOptions) => {
853
903
  if (err) {
854
904
  logger.debug('get MFA Options failed', err);
855
905
  rej(err);
@@ -858,7 +908,7 @@ export class InternalAuthClass {
858
908
  logger.debug('get MFA options success', mfaOptions);
859
909
  res(mfaOptions);
860
910
  return;
861
- });
911
+ }, getAuthUserAgentValue(AuthAction.GetMFAOptions, customUserAgentDetails));
862
912
  });
863
913
  }
864
914
 
@@ -873,18 +923,23 @@ export class InternalAuthClass {
873
923
  params?: GetPreferredMFAOpts,
874
924
  customUserAgentDetails?: CustomUserAgentDetails
875
925
  ): Promise<string> {
926
+ const internalUser: InternalCognitoUser | any = user;
876
927
  const that = this;
877
928
  return new Promise((res, rej) => {
878
929
  const clientMetadata = this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
879
930
 
880
931
  const bypassCache = params ? params.bypassCache : false;
881
- user.getUserData(
932
+ const userAgentValue = getAuthUserAgentValue(
933
+ AuthAction.GetPreferredMFA,
934
+ customUserAgentDetails
935
+ );
936
+ internalUser.getUserData(
882
937
  async (err, data) => {
883
938
  if (err) {
884
939
  logger.debug('getting preferred mfa failed', err);
885
940
  if (this.isSessionInvalid(err)) {
886
941
  try {
887
- await this.cleanUpInvalidSession(user);
942
+ await this.cleanUpInvalidSession(user, userAgentValue);
888
943
  } catch (cleanUpError) {
889
944
  rej(
890
945
  new Error(
@@ -907,7 +962,8 @@ export class InternalAuthClass {
907
962
  return;
908
963
  }
909
964
  },
910
- { bypassCache, clientMetadata }
965
+ { bypassCache, clientMetadata },
966
+ userAgentValue
911
967
  );
912
968
  });
913
969
  }
@@ -942,29 +998,37 @@ export class InternalAuthClass {
942
998
  return ret;
943
999
  }
944
1000
 
945
- private _getUserData(user, params) {
1001
+ private _getUserData(
1002
+ user: InternalCognitoUser,
1003
+ params,
1004
+ userAgentValue: string
1005
+ ) {
946
1006
  return new Promise((res, rej) => {
947
- user.getUserData(async (err, data) => {
948
- if (err) {
949
- logger.debug('getting user data failed', err);
950
- if (this.isSessionInvalid(err)) {
951
- try {
952
- await this.cleanUpInvalidSession(user);
953
- } catch (cleanUpError) {
954
- rej(
955
- new Error(
956
- `Session is invalid due to: ${err.message} and failed to clean up invalid session: ${cleanUpError.message}`
957
- )
958
- );
959
- return;
1007
+ user.getUserData(
1008
+ async (err, data) => {
1009
+ if (err) {
1010
+ logger.debug('getting user data failed', err);
1011
+ if (this.isSessionInvalid(err)) {
1012
+ try {
1013
+ await this.cleanUpInvalidSession(user, userAgentValue);
1014
+ } catch (cleanUpError) {
1015
+ rej(
1016
+ new Error(
1017
+ `Session is invalid due to: ${err.message} and failed to clean up invalid session: ${cleanUpError.message}`
1018
+ )
1019
+ );
1020
+ return;
1021
+ }
960
1022
  }
1023
+ rej(err);
1024
+ return;
1025
+ } else {
1026
+ res(data);
961
1027
  }
962
- rej(err);
963
- return;
964
- } else {
965
- res(data);
966
- }
967
- }, params);
1028
+ },
1029
+ params,
1030
+ userAgentValue
1031
+ );
968
1032
  });
969
1033
  }
970
1034
 
@@ -980,12 +1044,21 @@ export class InternalAuthClass {
980
1044
  mfaMethod: 'TOTP' | 'SMS' | 'NOMFA' | 'SMS_MFA' | 'SOFTWARE_TOKEN_MFA',
981
1045
  customUserAgentDetails?: CustomUserAgentDetails
982
1046
  ): Promise<string> {
1047
+ const internalUser: InternalCognitoUser | any = user;
1048
+ const userAgentValue = getAuthUserAgentValue(
1049
+ AuthAction.SetPreferredMFA,
1050
+ customUserAgentDetails
1051
+ );
983
1052
  const clientMetadata = this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
984
1053
 
985
- const userData = await this._getUserData(user, {
986
- bypassCache: true,
987
- clientMetadata,
988
- });
1054
+ const userData = await this._getUserData(
1055
+ user,
1056
+ {
1057
+ bypassCache: true,
1058
+ clientMetadata,
1059
+ },
1060
+ userAgentValue
1061
+ );
989
1062
  let smsMfaSettings = null;
990
1063
  let totpMfaSettings = null;
991
1064
 
@@ -1048,7 +1121,7 @@ export class InternalAuthClass {
1048
1121
 
1049
1122
  const that = this;
1050
1123
  return new Promise<string>((res, rej) => {
1051
- user.setUserMfaPreference(
1124
+ internalUser.setUserMfaPreference(
1052
1125
  smsMfaSettings,
1053
1126
  totpMfaSettings,
1054
1127
  (err, result) => {
@@ -1059,13 +1132,13 @@ export class InternalAuthClass {
1059
1132
  logger.debug('Set user mfa success', result);
1060
1133
  logger.debug('Caching the latest user data into local');
1061
1134
  // cache the latest result into user data
1062
- user.getUserData(
1135
+ internalUser.getUserData(
1063
1136
  async (err, data) => {
1064
1137
  if (err) {
1065
1138
  logger.debug('getting user data failed', err);
1066
1139
  if (this.isSessionInvalid(err)) {
1067
1140
  try {
1068
- await this.cleanUpInvalidSession(user);
1141
+ await this.cleanUpInvalidSession(user, userAgentValue);
1069
1142
  } catch (cleanUpError) {
1070
1143
  rej(
1071
1144
  new Error(
@@ -1083,9 +1156,11 @@ export class InternalAuthClass {
1083
1156
  {
1084
1157
  bypassCache: true,
1085
1158
  clientMetadata,
1086
- }
1159
+ },
1160
+ userAgentValue
1087
1161
  );
1088
- }
1162
+ },
1163
+ userAgentValue
1089
1164
  );
1090
1165
  });
1091
1166
  }
@@ -1101,8 +1176,10 @@ export class InternalAuthClass {
1101
1176
  user: CognitoUser,
1102
1177
  customUserAgentDetails?: CustomUserAgentDetails
1103
1178
  ): Promise<string> {
1179
+ const internalUser = user as InternalCognitoUser;
1180
+
1104
1181
  return new Promise((res, rej) => {
1105
- user.disableMFA((err, data) => {
1182
+ internalUser.disableMFA((err, data) => {
1106
1183
  if (err) {
1107
1184
  logger.debug('disable mfa failed', err);
1108
1185
  rej(err);
@@ -1111,7 +1188,7 @@ export class InternalAuthClass {
1111
1188
  logger.debug('disable mfa succeed', data);
1112
1189
  res(data);
1113
1190
  return;
1114
- });
1191
+ }, getAuthUserAgentValue(AuthAction.DisableSMS, customUserAgentDetails));
1115
1192
  });
1116
1193
  }
1117
1194
 
@@ -1126,8 +1203,10 @@ export class InternalAuthClass {
1126
1203
  user: CognitoUser,
1127
1204
  customUserAgentDetails?: CustomUserAgentDetails
1128
1205
  ): Promise<string> {
1206
+ const internalUser = user as InternalCognitoUser;
1207
+
1129
1208
  return new Promise((res, rej) => {
1130
- user.enableMFA((err, data) => {
1209
+ internalUser.enableMFA((err, data) => {
1131
1210
  if (err) {
1132
1211
  logger.debug('enable mfa failed', err);
1133
1212
  rej(err);
@@ -1136,7 +1215,7 @@ export class InternalAuthClass {
1136
1215
  logger.debug('enable mfa succeed', data);
1137
1216
  res(data);
1138
1217
  return;
1139
- });
1218
+ }, getAuthUserAgentValue(AuthAction.EnableSMS, customUserAgentDetails));
1140
1219
  });
1141
1220
  }
1142
1221
 
@@ -1150,19 +1229,24 @@ export class InternalAuthClass {
1150
1229
  user: CognitoUser | any,
1151
1230
  customUserAgentDetails?: CustomUserAgentDetails
1152
1231
  ): Promise<string> {
1232
+ const internalUser: InternalCognitoUser | any = user;
1233
+
1153
1234
  return new Promise((res, rej) => {
1154
- user.associateSoftwareToken({
1155
- onFailure: err => {
1156
- logger.debug('associateSoftwareToken failed', err);
1157
- rej(err);
1158
- return;
1159
- },
1160
- associateSecretCode: secretCode => {
1161
- logger.debug('associateSoftwareToken success', secretCode);
1162
- res(secretCode);
1163
- return;
1235
+ internalUser.associateSoftwareToken(
1236
+ {
1237
+ onFailure: err => {
1238
+ logger.debug('associateSoftwareToken failed', err);
1239
+ rej(err);
1240
+ return;
1241
+ },
1242
+ associateSecretCode: secretCode => {
1243
+ logger.debug('associateSoftwareToken success', secretCode);
1244
+ res(secretCode);
1245
+ return;
1246
+ },
1164
1247
  },
1165
- });
1248
+ getAuthUserAgentValue(AuthAction.SetupTOTP, customUserAgentDetails)
1249
+ );
1166
1250
  });
1167
1251
  }
1168
1252
 
@@ -1179,38 +1263,50 @@ export class InternalAuthClass {
1179
1263
  customUserAgentDetails?: CustomUserAgentDetails
1180
1264
  ): Promise<CognitoUserSession> {
1181
1265
  logger.debug('verification totp token', user, challengeAnswer);
1266
+ const internalUser: InternalCognitoUser | any = user;
1182
1267
 
1183
1268
  let signInUserSession;
1184
- if (user && typeof user.getSignInUserSession === 'function') {
1185
- signInUserSession = (user as CognitoUser).getSignInUserSession();
1269
+ if (
1270
+ internalUser &&
1271
+ typeof internalUser.getSignInUserSession === 'function'
1272
+ ) {
1273
+ signInUserSession = (user as InternalCognitoUser).getSignInUserSession();
1186
1274
  }
1187
1275
  const isLoggedIn = signInUserSession?.isValid();
1188
1276
 
1189
1277
  return new Promise((res, rej) => {
1190
- user.verifySoftwareToken(challengeAnswer, 'My TOTP device', {
1191
- onFailure: err => {
1192
- logger.debug('verifyTotpToken failed', err);
1193
- rej(err);
1194
- return;
1195
- },
1196
- onSuccess: data => {
1197
- if (!isLoggedIn) {
1278
+ internalUser.verifySoftwareToken(
1279
+ challengeAnswer,
1280
+ 'My TOTP device',
1281
+ {
1282
+ onFailure: err => {
1283
+ logger.debug('verifyTotpToken failed', err);
1284
+ rej(err);
1285
+ return;
1286
+ },
1287
+ onSuccess: data => {
1288
+ if (!isLoggedIn) {
1289
+ dispatchAuthEvent(
1290
+ 'signIn',
1291
+ internalUser,
1292
+ `A user ${internalUser.getUsername()} has been signed in`
1293
+ );
1294
+ }
1198
1295
  dispatchAuthEvent(
1199
- 'signIn',
1200
- user,
1201
- `A user ${user.getUsername()} has been signed in`
1296
+ 'verify',
1297
+ internalUser,
1298
+ `A user ${internalUser.getUsername()} has been verified`
1202
1299
  );
1203
- }
1204
- dispatchAuthEvent(
1205
- 'verify',
1206
- user,
1207
- `A user ${user.getUsername()} has been verified`
1208
- );
1209
- logger.debug('verifyTotpToken success', data);
1210
- res(data);
1211
- return;
1300
+ logger.debug('verifyTotpToken success', data);
1301
+ res(data);
1302
+ return;
1303
+ },
1212
1304
  },
1213
- });
1305
+ getAuthUserAgentValue(
1306
+ AuthAction.VerifyTotpToken,
1307
+ customUserAgentDetails
1308
+ )
1309
+ );
1214
1310
  });
1215
1311
  }
1216
1312
 
@@ -1229,13 +1325,19 @@ export class InternalAuthClass {
1229
1325
  clientMetadata: ClientMetaData = this._config.clientMetadata,
1230
1326
  customUserAgentDetails?: CustomUserAgentDetails
1231
1327
  ): Promise<CognitoUser | any> {
1328
+ const internalUser: InternalCognitoUser | any = user;
1329
+
1232
1330
  if (!code) {
1233
1331
  return this.rejectAuthError(AuthErrorTypes.EmptyCode);
1234
1332
  }
1235
1333
 
1236
1334
  const that = this;
1335
+ const userAgentDetails = getAuthUserAgentDetails(
1336
+ AuthAction.ConfirmSignIn,
1337
+ customUserAgentDetails
1338
+ );
1237
1339
  return new Promise((resolve, reject) => {
1238
- user.sendMFACode(
1340
+ internalUser.sendMFACode(
1239
1341
  code,
1240
1342
  {
1241
1343
  onSuccess: async session => {
@@ -1247,19 +1349,24 @@ export class InternalAuthClass {
1247
1349
  } catch (e) {
1248
1350
  logger.debug('cannot get cognito credentials', e);
1249
1351
  } finally {
1250
- that.user = user;
1352
+ that.user = internalUser;
1251
1353
  try {
1252
- const currentUser = await this.currentUserPoolUser();
1253
- user.attributes = currentUser.attributes;
1354
+ const currentUser = await this._currentUserPoolUser(
1355
+ undefined,
1356
+ userAgentDetails
1357
+ );
1358
+ Object.assign(internalUser, {
1359
+ attributes: currentUser.attributes,
1360
+ });
1254
1361
  } catch (e) {
1255
1362
  logger.debug('cannot get updated Cognito User', e);
1256
1363
  }
1257
1364
  dispatchAuthEvent(
1258
1365
  'signIn',
1259
- user,
1260
- `A user ${user.getUsername()} has been signed in`
1366
+ internalUser,
1367
+ `A user ${internalUser.getUsername()} has been signed in`
1261
1368
  );
1262
- resolve(user);
1369
+ resolve(internalUser);
1263
1370
  }
1264
1371
  },
1265
1372
  onFailure: err => {
@@ -1268,7 +1375,8 @@ export class InternalAuthClass {
1268
1375
  },
1269
1376
  },
1270
1377
  mfaType,
1271
- clientMetadata
1378
+ clientMetadata,
1379
+ getAmplifyUserAgent(userAgentDetails)
1272
1380
  );
1273
1381
  });
1274
1382
  }
@@ -1280,13 +1388,15 @@ export class InternalAuthClass {
1280
1388
  clientMetadata: ClientMetaData = this._config.clientMetadata,
1281
1389
  customUserAgentDetails?: CustomUserAgentDetails
1282
1390
  ): Promise<CognitoUser | any> {
1391
+ const internalUser: InternalCognitoUser | any = user;
1392
+
1283
1393
  if (!password) {
1284
1394
  return this.rejectAuthError(AuthErrorTypes.EmptyPassword);
1285
1395
  }
1286
1396
 
1287
1397
  const that = this;
1288
1398
  return new Promise((resolve, reject) => {
1289
- user.completeNewPasswordChallenge(
1399
+ internalUser.completeNewPasswordChallenge(
1290
1400
  password,
1291
1401
  requiredAttributes,
1292
1402
  {
@@ -1299,13 +1409,13 @@ export class InternalAuthClass {
1299
1409
  } catch (e) {
1300
1410
  logger.debug('cannot get cognito credentials', e);
1301
1411
  } finally {
1302
- that.user = user;
1412
+ that.user = internalUser;
1303
1413
  dispatchAuthEvent(
1304
1414
  'signIn',
1305
- user,
1306
- `A user ${user.getUsername()} has been signed in`
1415
+ internalUser,
1416
+ `A user ${internalUser.getUsername()} has been signed in`
1307
1417
  );
1308
- resolve(user);
1418
+ resolve(internalUser);
1309
1419
  }
1310
1420
  },
1311
1421
  onFailure: err => {
@@ -1319,24 +1429,28 @@ export class InternalAuthClass {
1319
1429
  },
1320
1430
  mfaRequired: (challengeName, challengeParam) => {
1321
1431
  logger.debug('signIn MFA required');
1322
- user['challengeName'] = challengeName;
1323
- user['challengeParam'] = challengeParam;
1324
- resolve(user);
1432
+ internalUser['challengeName'] = challengeName;
1433
+ internalUser['challengeParam'] = challengeParam;
1434
+ resolve(internalUser);
1325
1435
  },
1326
1436
  mfaSetup: (challengeName, challengeParam) => {
1327
1437
  logger.debug('signIn mfa setup', challengeName);
1328
- user['challengeName'] = challengeName;
1329
- user['challengeParam'] = challengeParam;
1330
- resolve(user);
1438
+ internalUser['challengeName'] = challengeName;
1439
+ internalUser['challengeParam'] = challengeParam;
1440
+ resolve(internalUser);
1331
1441
  },
1332
1442
  totpRequired: (challengeName, challengeParam) => {
1333
1443
  logger.debug('signIn mfa setup', challengeName);
1334
- user['challengeName'] = challengeName;
1335
- user['challengeParam'] = challengeParam;
1336
- resolve(user);
1444
+ internalUser['challengeName'] = challengeName;
1445
+ internalUser['challengeParam'] = challengeParam;
1446
+ resolve(internalUser);
1337
1447
  },
1338
1448
  },
1339
- clientMetadata
1449
+ clientMetadata,
1450
+ getAuthUserAgentValue(
1451
+ AuthAction.CompleteNewPassword,
1452
+ customUserAgentDetails
1453
+ )
1340
1454
  );
1341
1455
  });
1342
1456
  }
@@ -1347,6 +1461,7 @@ export class InternalAuthClass {
1347
1461
  * @param {String} challengeResponses - The confirmation code
1348
1462
  * @param {ClientMetaData} clientMetadata - optional client metadata defaults to config
1349
1463
  * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
1464
+ *
1350
1465
  */
1351
1466
  public sendCustomChallengeAnswer(
1352
1467
  user: CognitoUser | any,
@@ -1354,6 +1469,8 @@ export class InternalAuthClass {
1354
1469
  clientMetadata: ClientMetaData = this._config.clientMetadata,
1355
1470
  customUserAgentDetails?: CustomUserAgentDetails
1356
1471
  ): Promise<CognitoUser | any> {
1472
+ const internalUser: InternalCognitoUser | any = user;
1473
+
1357
1474
  if (!this.userPool) {
1358
1475
  return this.rejectNoUserPool();
1359
1476
  }
@@ -1362,11 +1479,16 @@ export class InternalAuthClass {
1362
1479
  }
1363
1480
 
1364
1481
  const that = this;
1482
+ const userAgentDetails = getAuthUserAgentDetails(
1483
+ AuthAction.SendCustomChallengeAnswer,
1484
+ customUserAgentDetails
1485
+ );
1365
1486
  return new Promise((resolve, reject) => {
1366
- user.sendCustomChallengeAnswer(
1487
+ internalUser.sendCustomChallengeAnswer(
1367
1488
  challengeResponses,
1368
- this.authCallbacks(user, resolve, reject),
1369
- clientMetadata
1489
+ this.authCallbacks(internalUser, resolve, reject, userAgentDetails),
1490
+ clientMetadata,
1491
+ getAmplifyUserAgent(userAgentDetails)
1370
1492
  );
1371
1493
  });
1372
1494
  }
@@ -1383,16 +1505,25 @@ export class InternalAuthClass {
1383
1505
  attributeNames: string[],
1384
1506
  customUserAgentDetails?: CustomUserAgentDetails
1385
1507
  ) {
1508
+ const internalUser: InternalCognitoUser | any = user;
1386
1509
  const that = this;
1510
+ const userAgentValue = getAuthUserAgentValue(
1511
+ AuthAction.DeleteUserAttributes,
1512
+ customUserAgentDetails
1513
+ );
1387
1514
  return new Promise((resolve, reject) => {
1388
- that.userSession(user).then(session => {
1389
- user.deleteAttributes(attributeNames, (err, result) => {
1390
- if (err) {
1391
- return reject(err);
1392
- } else {
1393
- return resolve(result);
1394
- }
1395
- });
1515
+ that._userSession(userAgentValue, internalUser).then(session => {
1516
+ internalUser.deleteAttributes(
1517
+ attributeNames,
1518
+ (err, result) => {
1519
+ if (err) {
1520
+ return reject(err);
1521
+ } else {
1522
+ return resolve(result);
1523
+ }
1524
+ },
1525
+ userAgentValue
1526
+ );
1396
1527
  });
1397
1528
  });
1398
1529
  }
@@ -1419,18 +1550,26 @@ export class InternalAuthClass {
1419
1550
 
1420
1551
  return new Promise(async (res, rej) => {
1421
1552
  if (this.userPool) {
1422
- const user = this.userPool.getCurrentUser();
1553
+ const internalUser =
1554
+ this.userPool.getCurrentUser() as InternalCognitoUser;
1423
1555
 
1424
- if (!user) {
1556
+ if (!internalUser) {
1425
1557
  logger.debug('Failed to get user from user pool');
1426
1558
  return rej(new Error('No current user.'));
1427
1559
  } else {
1428
- user.getSession(async (err, session) => {
1560
+ const userAgentValue = getAuthUserAgentValue(
1561
+ AuthAction.DeleteUser,
1562
+ customUserAgentDetails
1563
+ );
1564
+ internalUser.getSession(async (err, session) => {
1429
1565
  if (err) {
1430
1566
  logger.debug('Failed to get the user session', err);
1431
1567
  if (this.isSessionInvalid(err)) {
1432
1568
  try {
1433
- await this.cleanUpInvalidSession(user);
1569
+ await this.cleanUpInvalidSession(
1570
+ internalUser,
1571
+ userAgentValue
1572
+ );
1434
1573
  } catch (cleanUpError) {
1435
1574
  rej(
1436
1575
  new Error(
@@ -1442,36 +1581,40 @@ export class InternalAuthClass {
1442
1581
  }
1443
1582
  return rej(err);
1444
1583
  } else {
1445
- user.deleteUser((err, result: string) => {
1446
- if (err) {
1447
- rej(err);
1448
- } else {
1449
- dispatchAuthEvent(
1450
- 'userDeleted',
1451
- result,
1452
- 'The authenticated user has been deleted.'
1453
- );
1454
- user.signOut();
1455
- this.user = null;
1456
- try {
1457
- this.cleanCachedItems(); // clean aws credentials
1458
- } catch (e) {
1459
- // TODO: change to rejects in refactor
1460
- logger.debug('failed to clear cached items');
1461
- }
1462
-
1463
- if (isSignedInHostedUI) {
1464
- this.oAuthSignOutRedirect(res, rej);
1584
+ internalUser.deleteUser(
1585
+ (err, result: string) => {
1586
+ if (err) {
1587
+ rej(err);
1465
1588
  } else {
1466
1589
  dispatchAuthEvent(
1467
- 'signOut',
1468
- this.user,
1469
- `A user has been signed out`
1590
+ 'userDeleted',
1591
+ result,
1592
+ 'The authenticated user has been deleted.'
1470
1593
  );
1471
- res(result);
1594
+ internalUser.signOut(undefined, userAgentValue);
1595
+ this.user = null;
1596
+ try {
1597
+ this.cleanCachedItems(); // clean aws credentials
1598
+ } catch (e) {
1599
+ // TODO: change to rejects in refactor
1600
+ logger.debug('failed to clear cached items');
1601
+ }
1602
+
1603
+ if (isSignedInHostedUI) {
1604
+ this.oAuthSignOutRedirect(res, rej);
1605
+ } else {
1606
+ dispatchAuthEvent(
1607
+ 'signOut',
1608
+ this.user,
1609
+ `A user has been signed out`
1610
+ );
1611
+ res(result);
1612
+ }
1472
1613
  }
1473
- }
1474
- });
1614
+ },
1615
+ undefined,
1616
+ userAgentValue
1617
+ );
1475
1618
  }
1476
1619
  });
1477
1620
  }
@@ -1496,10 +1639,15 @@ export class InternalAuthClass {
1496
1639
  clientMetadata: ClientMetaData = this._config.clientMetadata,
1497
1640
  customUserAgentDetails?: CustomUserAgentDetails
1498
1641
  ): Promise<string> {
1642
+ const internalUser: InternalCognitoUser | any = user;
1499
1643
  const attributeList: ICognitoUserAttributeData[] = [];
1500
1644
  const that = this;
1645
+ const userAgentValue = getAuthUserAgentValue(
1646
+ AuthAction.UpdateUserAttributes,
1647
+ customUserAgentDetails
1648
+ );
1501
1649
  return new Promise((resolve, reject) => {
1502
- that.userSession(user).then(session => {
1650
+ that._userSession(userAgentValue, internalUser).then(session => {
1503
1651
  for (const key in attributes) {
1504
1652
  if (key !== 'sub' && key.indexOf('_verified') < 0) {
1505
1653
  const attr: ICognitoUserAttributeData = {
@@ -1509,7 +1657,7 @@ export class InternalAuthClass {
1509
1657
  attributeList.push(attr);
1510
1658
  }
1511
1659
  }
1512
- user.updateAttributes(
1660
+ internalUser.updateAttributes(
1513
1661
  attributeList,
1514
1662
  (err, result, details) => {
1515
1663
  if (err) {
@@ -1532,7 +1680,8 @@ export class InternalAuthClass {
1532
1680
  return resolve(result);
1533
1681
  }
1534
1682
  },
1535
- clientMetadata
1683
+ clientMetadata,
1684
+ userAgentValue
1536
1685
  );
1537
1686
  });
1538
1687
  });
@@ -1568,15 +1717,27 @@ export class InternalAuthClass {
1568
1717
  user: CognitoUser | any,
1569
1718
  customUserAgentDetails?: CustomUserAgentDetails
1570
1719
  ): Promise<CognitoUserAttribute[]> {
1720
+ return this._userAttributes(user, customUserAgentDetails);
1721
+ }
1722
+
1723
+ private _userAttributes(
1724
+ user: CognitoUser | any,
1725
+ customUserAgentDetails?: CustomUserAgentDetails
1726
+ ): Promise<CognitoUserAttribute[]> {
1727
+ const internalUser: InternalCognitoUser | any = user;
1728
+ const userAgentValue = getAuthUserAgentValue(
1729
+ AuthAction.UserAttributes,
1730
+ customUserAgentDetails
1731
+ );
1571
1732
  return new Promise((resolve, reject) => {
1572
- this.userSession(user).then(session => {
1573
- user.getUserAttributes((err, attributes) => {
1733
+ this._userSession(userAgentValue, internalUser).then(session => {
1734
+ internalUser.getUserAttributes((err, attributes) => {
1574
1735
  if (err) {
1575
1736
  reject(err);
1576
1737
  } else {
1577
1738
  resolve(attributes);
1578
1739
  }
1579
- });
1740
+ }, userAgentValue);
1580
1741
  });
1581
1742
  });
1582
1743
  }
@@ -1586,7 +1747,13 @@ export class InternalAuthClass {
1586
1747
  customUserAgentDetails?: CustomUserAgentDetails
1587
1748
  ) {
1588
1749
  const that = this;
1589
- return this.userAttributes(user).then(attributes => {
1750
+ return this._userAttributes(
1751
+ user,
1752
+ getAuthUserAgentDetails(
1753
+ AuthAction.VerifiedContact,
1754
+ customUserAgentDetails
1755
+ )
1756
+ ).then(attributes => {
1590
1757
  const attrs = that.attributesToObject(attributes);
1591
1758
  const unverified = {};
1592
1759
  const verified = {};
@@ -1687,8 +1854,11 @@ export class InternalAuthClass {
1687
1854
  );
1688
1855
  }
1689
1856
 
1690
- private async cleanUpInvalidSession(user: CognitoUser) {
1691
- user.signOut();
1857
+ private async cleanUpInvalidSession(
1858
+ internalUser: InternalCognitoUser,
1859
+ userAgentValue: string
1860
+ ) {
1861
+ internalUser.signOut(undefined, userAgentValue);
1692
1862
  this.user = null;
1693
1863
  try {
1694
1864
  await this.cleanCachedItems(); // clean aws credentials
@@ -1713,6 +1883,13 @@ export class InternalAuthClass {
1713
1883
  public currentUserPoolUser(
1714
1884
  params?: CurrentUserOpts,
1715
1885
  customUserAgentDetails?: CustomUserAgentDetails
1886
+ ): Promise<CognitoUser | any> {
1887
+ return this._currentUserPoolUser(params, customUserAgentDetails);
1888
+ }
1889
+
1890
+ private _currentUserPoolUser(
1891
+ params?: CurrentUserOpts,
1892
+ customUserAgentDetails?: CustomUserAgentDetails
1716
1893
  ): Promise<CognitoUser | any> {
1717
1894
  if (!this.userPool) {
1718
1895
  return this.rejectNoUserPool();
@@ -1753,9 +1930,10 @@ export class InternalAuthClass {
1753
1930
  });
1754
1931
  }
1755
1932
 
1756
- const user = this.userPool.getCurrentUser();
1933
+ const internalUser =
1934
+ this.userPool.getCurrentUser() as InternalCognitoUser;
1757
1935
 
1758
- if (!user) {
1936
+ if (!internalUser) {
1759
1937
  logger.debug('Failed to get user from user pool');
1760
1938
  rej('No current user');
1761
1939
  return;
@@ -1763,7 +1941,14 @@ export class InternalAuthClass {
1763
1941
 
1764
1942
  // refresh the session if the session expired.
1765
1943
  try {
1766
- const session = await this._userSession(user);
1944
+ const userAgentValue = getAuthUserAgentValue(
1945
+ AuthAction.CurrentUserPoolUser,
1946
+ customUserAgentDetails
1947
+ );
1948
+ const session = await this._userSession(
1949
+ userAgentValue,
1950
+ internalUser
1951
+ );
1767
1952
 
1768
1953
  // get user data from Cognito
1769
1954
  const bypassCache = params ? params.bypassCache : false;
@@ -1777,13 +1962,16 @@ export class InternalAuthClass {
1777
1962
  // validate the token's scope first before calling this function
1778
1963
  const { scope = '' } = session.getAccessToken().decodePayload();
1779
1964
  if (scope.split(' ').includes(USER_ADMIN_SCOPE)) {
1780
- user.getUserData(
1965
+ internalUser.getUserData(
1781
1966
  async (err, data) => {
1782
1967
  if (err) {
1783
1968
  logger.debug('getting user data failed', err);
1784
1969
  if (this.isSessionInvalid(err)) {
1785
1970
  try {
1786
- await this.cleanUpInvalidSession(user);
1971
+ await this.cleanUpInvalidSession(
1972
+ internalUser,
1973
+ userAgentValue
1974
+ );
1787
1975
  } catch (cleanUpError) {
1788
1976
  rej(
1789
1977
  new Error(
@@ -1794,12 +1982,12 @@ export class InternalAuthClass {
1794
1982
  }
1795
1983
  rej(err);
1796
1984
  } else {
1797
- res(user);
1985
+ res(internalUser);
1798
1986
  }
1799
1987
  return;
1800
1988
  }
1801
1989
  const preferredMFA = data.PreferredMfaSetting || 'NOMFA';
1802
- const attributeList = [];
1990
+ const attributeList: CognitoUserAttribute[] = [];
1803
1991
 
1804
1992
  for (let i = 0; i < data.UserAttributes.length; i++) {
1805
1993
  const attribute = {
@@ -1811,17 +1999,18 @@ export class InternalAuthClass {
1811
1999
  }
1812
2000
 
1813
2001
  const attributes = this.attributesToObject(attributeList);
1814
- Object.assign(user, { attributes, preferredMFA });
1815
- return res(user);
2002
+ Object.assign(internalUser, { attributes, preferredMFA });
2003
+ return res(internalUser);
1816
2004
  },
1817
- { bypassCache, clientMetadata }
2005
+ { bypassCache, clientMetadata },
2006
+ userAgentValue
1818
2007
  );
1819
2008
  } else {
1820
2009
  logger.debug(
1821
2010
  `Unable to get the user data because the ${USER_ADMIN_SCOPE} ` +
1822
2011
  `is not in the scopes of the access token`
1823
2012
  );
1824
- return res(user);
2013
+ return res(internalUser);
1825
2014
  }
1826
2015
  } catch (err) {
1827
2016
  rej(err);
@@ -1844,7 +2033,14 @@ export class InternalAuthClass {
1844
2033
  * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
1845
2034
  * @return - A promise resolves to current authenticated CognitoUser if success
1846
2035
  */
1847
- public async currentAuthenticatedUser(
2036
+ public currentAuthenticatedUser(
2037
+ params?: CurrentUserOpts,
2038
+ customUserAgentDetails?: CustomUserAgentDetails
2039
+ ): Promise<CognitoUser | any> {
2040
+ return this._currentAuthenticatedUser(params, customUserAgentDetails);
2041
+ }
2042
+
2043
+ private async _currentAuthenticatedUser(
1848
2044
  params?: CurrentUserOpts,
1849
2045
  customUserAgentDetails?: CustomUserAgentDetails
1850
2046
  ): Promise<CognitoUser | any> {
@@ -1879,7 +2075,13 @@ export class InternalAuthClass {
1879
2075
  logger.debug('get current authenticated userpool user');
1880
2076
  let user = null;
1881
2077
  try {
1882
- user = await this.currentUserPoolUser(params);
2078
+ user = await this._currentUserPoolUser(
2079
+ params,
2080
+ getAuthUserAgentDetails(
2081
+ AuthAction.CurrentAuthenticatedUser,
2082
+ customUserAgentDetails
2083
+ )
2084
+ );
1883
2085
  } catch (e) {
1884
2086
  if (e === 'No userPool') {
1885
2087
  logger.error(
@@ -1902,8 +2104,18 @@ export class InternalAuthClass {
1902
2104
  */
1903
2105
  public currentSession(
1904
2106
  customUserAgentDetails?: CustomUserAgentDetails
2107
+ ): Promise<CognitoUserSession> {
2108
+ return this._currentSession(customUserAgentDetails);
2109
+ }
2110
+
2111
+ private _currentSession(
2112
+ customUserAgentDetails?: CustomUserAgentDetails
1905
2113
  ): Promise<CognitoUserSession> {
1906
2114
  const that = this;
2115
+ const userAgentDetails = getAuthUserAgentDetails(
2116
+ AuthAction.CurrentSession,
2117
+ customUserAgentDetails
2118
+ );
1907
2119
  logger.debug('Getting current session');
1908
2120
  // Purposely not calling the reject method here because we don't need a console error
1909
2121
  if (!this.userPool) {
@@ -1912,10 +2124,10 @@ export class InternalAuthClass {
1912
2124
 
1913
2125
  return new Promise((res, rej) => {
1914
2126
  that
1915
- .currentUserPoolUser()
2127
+ ._currentUserPoolUser(undefined, userAgentDetails)
1916
2128
  .then(user => {
1917
2129
  that
1918
- .userSession(user)
2130
+ ._userSession(getAmplifyUserAgent(userAgentDetails), user)
1919
2131
  .then(session => {
1920
2132
  res(session);
1921
2133
  return;
@@ -1934,8 +2146,11 @@ export class InternalAuthClass {
1934
2146
  });
1935
2147
  }
1936
2148
 
1937
- private async _userSession(user?: CognitoUser): Promise<CognitoUserSession> {
1938
- if (!user) {
2149
+ private async _userSession(
2150
+ userAgentValue: string,
2151
+ internalUser?: InternalCognitoUser
2152
+ ): Promise<CognitoUserSession> {
2153
+ if (!internalUser) {
1939
2154
  logger.debug('the user is null');
1940
2155
  return this.rejectAuthError(AuthErrorTypes.NoUserSession);
1941
2156
  }
@@ -1945,13 +2160,19 @@ export class InternalAuthClass {
1945
2160
  if (this.inflightSessionPromiseCounter === 0) {
1946
2161
  this.inflightSessionPromise = new Promise<CognitoUserSession>(
1947
2162
  (res, rej) => {
1948
- user.getSession(
2163
+ internalUser.getSession(
1949
2164
  async (err, session) => {
1950
2165
  if (err) {
1951
- logger.debug('Failed to get the session from user', user);
2166
+ logger.debug(
2167
+ 'Failed to get the session from user',
2168
+ internalUser
2169
+ );
1952
2170
  if (this.isSessionInvalid(err)) {
1953
2171
  try {
1954
- await this.cleanUpInvalidSession(user);
2172
+ await this.cleanUpInvalidSession(
2173
+ internalUser,
2174
+ userAgentValue
2175
+ );
1955
2176
  } catch (cleanUpError) {
1956
2177
  rej(
1957
2178
  new Error(
@@ -1969,7 +2190,8 @@ export class InternalAuthClass {
1969
2190
  return;
1970
2191
  }
1971
2192
  },
1972
- { clientMetadata }
2193
+ { clientMetadata },
2194
+ userAgentValue
1973
2195
  );
1974
2196
  }
1975
2197
  );
@@ -1980,7 +2202,7 @@ export class InternalAuthClass {
1980
2202
  const userSession = await this.inflightSessionPromise;
1981
2203
  // Set private member. Avoid user.setSignInUserSession() to prevent excessive localstorage refresh.
1982
2204
  // @ts-ignore
1983
- user.signInUserSession = userSession;
2205
+ internalUser.signInUserSession = userSession;
1984
2206
  return userSession!;
1985
2207
  } finally {
1986
2208
  this.inflightSessionPromiseCounter--;
@@ -1997,7 +2219,10 @@ export class InternalAuthClass {
1997
2219
  user,
1998
2220
  customUserAgentDetails?: CustomUserAgentDetails
1999
2221
  ): Promise<CognitoUserSession> {
2000
- return this._userSession(user);
2222
+ return this._userSession(
2223
+ getAuthUserAgentValue(AuthAction.UserSession, customUserAgentDetails),
2224
+ user
2225
+ );
2001
2226
  }
2002
2227
 
2003
2228
  /**
@@ -2031,7 +2256,12 @@ export class InternalAuthClass {
2031
2256
  // refresh the jwt token here if necessary
2032
2257
  return this.Credentials.refreshFederatedToken(federatedInfo);
2033
2258
  } else {
2034
- return this.currentSession()
2259
+ return this._currentSession(
2260
+ getAuthUserAgentDetails(
2261
+ AuthAction.CurrentUserCredentials,
2262
+ customUserAgentDetails
2263
+ )
2264
+ )
2035
2265
  .then(session => {
2036
2266
  logger.debug('getting session success', session);
2037
2267
  return this.Credentials.set(session, 'session');
@@ -2054,6 +2284,8 @@ export class InternalAuthClass {
2054
2284
  * Initiate an attribute confirmation request
2055
2285
  * @param {Object} user - The CognitoUser
2056
2286
  * @param {Object} attr - The attributes to be verified
2287
+ * @param {ClientMetaData} clientMetadata - optional client metadata, defaults to config
2288
+ * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
2057
2289
  * @return - A promise resolves to callback data if success
2058
2290
  */
2059
2291
  public verifyUserAttribute(
@@ -2062,8 +2294,24 @@ export class InternalAuthClass {
2062
2294
  clientMetadata: ClientMetaData = this._config.clientMetadata,
2063
2295
  customUserAgentDetails?: CustomUserAgentDetails
2064
2296
  ): Promise<void> {
2297
+ return this._verifyUserAttribute(
2298
+ user,
2299
+ attr,
2300
+ clientMetadata,
2301
+ customUserAgentDetails
2302
+ );
2303
+ }
2304
+
2305
+ private _verifyUserAttribute(
2306
+ user: CognitoUser | any,
2307
+ attr: string,
2308
+ clientMetadata: ClientMetaData = this._config.clientMetadata,
2309
+ customUserAgentDetails?: CustomUserAgentDetails
2310
+ ): Promise<void> {
2311
+ const internalUser: InternalCognitoUser | any = user;
2312
+
2065
2313
  return new Promise((resolve, reject) => {
2066
- user.getAttributeVerificationCode(
2314
+ internalUser.getAttributeVerificationCode(
2067
2315
  attr,
2068
2316
  {
2069
2317
  onSuccess(success) {
@@ -2073,7 +2321,11 @@ export class InternalAuthClass {
2073
2321
  return reject(err);
2074
2322
  },
2075
2323
  },
2076
- clientMetadata
2324
+ clientMetadata,
2325
+ getAuthUserAgentValue(
2326
+ AuthAction.VerifyUserAttribute,
2327
+ customUserAgentDetails
2328
+ )
2077
2329
  );
2078
2330
  });
2079
2331
  }
@@ -2091,22 +2343,45 @@ export class InternalAuthClass {
2091
2343
  attr: string,
2092
2344
  code: string,
2093
2345
  customUserAgentDetails?: CustomUserAgentDetails
2346
+ ): Promise<string> {
2347
+ return this._verifyUserAttributeSubmit(
2348
+ user,
2349
+ attr,
2350
+ code,
2351
+ customUserAgentDetails
2352
+ );
2353
+ }
2354
+
2355
+ private _verifyUserAttributeSubmit(
2356
+ user: CognitoUser | any,
2357
+ attr: string,
2358
+ code: string,
2359
+ customUserAgentDetails?: CustomUserAgentDetails
2094
2360
  ): Promise<string> {
2095
2361
  if (!code) {
2096
2362
  return this.rejectAuthError(AuthErrorTypes.EmptyCode);
2097
2363
  }
2364
+ const internalUser: InternalCognitoUser | any = user;
2098
2365
 
2099
2366
  return new Promise((resolve, reject) => {
2100
- user.verifyAttribute(attr, code, {
2101
- onSuccess(data) {
2102
- resolve(data);
2103
- return;
2104
- },
2105
- onFailure(err) {
2106
- reject(err);
2107
- return;
2367
+ internalUser.verifyAttribute(
2368
+ attr,
2369
+ code,
2370
+ {
2371
+ onSuccess(data) {
2372
+ resolve(data);
2373
+ return;
2374
+ },
2375
+ onFailure(err) {
2376
+ reject(err);
2377
+ return;
2378
+ },
2108
2379
  },
2109
- });
2380
+ getAuthUserAgentValue(
2381
+ AuthAction.VerifyUserAttributeSubmit,
2382
+ customUserAgentDetails
2383
+ )
2384
+ );
2110
2385
  });
2111
2386
  }
2112
2387
 
@@ -2114,10 +2389,16 @@ export class InternalAuthClass {
2114
2389
  attr: string,
2115
2390
  customUserAgentDetails?: CustomUserAgentDetails
2116
2391
  ): Promise<void> {
2392
+ const userAgentDetails = getAuthUserAgentDetails(
2393
+ AuthAction.VerifyCurrentUserAttribute,
2394
+ customUserAgentDetails
2395
+ );
2117
2396
  const that = this;
2118
2397
  return that
2119
- .currentUserPoolUser()
2120
- .then(user => that.verifyUserAttribute(user, attr));
2398
+ ._currentUserPoolUser(undefined, userAgentDetails)
2399
+ .then(user =>
2400
+ that._verifyUserAttribute(user, attr, undefined, userAgentDetails)
2401
+ );
2121
2402
  }
2122
2403
 
2123
2404
  /**
@@ -2132,15 +2413,22 @@ export class InternalAuthClass {
2132
2413
  code: string,
2133
2414
  customUserAgentDetails?: CustomUserAgentDetails
2134
2415
  ): Promise<string> {
2416
+ const userAgentDetails = getAuthUserAgentDetails(
2417
+ AuthAction.VerifyCurrentUserAttributeSubmit,
2418
+ customUserAgentDetails
2419
+ );
2135
2420
  const that = this;
2136
2421
  return that
2137
- .currentUserPoolUser()
2138
- .then(user => that.verifyUserAttributeSubmit(user, attr, code));
2422
+ ._currentUserPoolUser(undefined, userAgentDetails)
2423
+ .then(user =>
2424
+ that._verifyUserAttributeSubmit(user, attr, code, userAgentDetails)
2425
+ );
2139
2426
  }
2140
2427
 
2141
2428
  private async cognitoIdentitySignOut(
2142
2429
  opts: SignOutOpts,
2143
- user: CognitoUser | any
2430
+ internalUser: InternalCognitoUser | any,
2431
+ userAgentValue: string
2144
2432
  ) {
2145
2433
  try {
2146
2434
  await this._storageSync;
@@ -2155,18 +2443,21 @@ export class InternalAuthClass {
2155
2443
 
2156
2444
  return new Promise((res, rej) => {
2157
2445
  if (opts && opts.global) {
2158
- logger.debug('user global sign out', user);
2446
+ logger.debug('user global sign out', internalUser);
2159
2447
  // in order to use global signout
2160
2448
  // we must validate the user as an authenticated user by using getSession
2161
2449
  const clientMetadata = this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
2162
2450
 
2163
- user.getSession(
2451
+ internalUser.getSession(
2164
2452
  async (err, result) => {
2165
2453
  if (err) {
2166
2454
  logger.debug('failed to get the user session', err);
2167
2455
  if (this.isSessionInvalid(err)) {
2168
2456
  try {
2169
- await this.cleanUpInvalidSession(user);
2457
+ await this.cleanUpInvalidSession(
2458
+ internalUser,
2459
+ userAgentValue
2460
+ );
2170
2461
  } catch (cleanUpError) {
2171
2462
  rej(
2172
2463
  new Error(
@@ -2178,32 +2469,36 @@ export class InternalAuthClass {
2178
2469
  }
2179
2470
  return rej(err);
2180
2471
  }
2181
- user.globalSignOut({
2182
- onSuccess: data => {
2183
- logger.debug('global sign out success');
2184
- if (isSignedInHostedUI) {
2185
- this.oAuthSignOutRedirect(res, rej);
2186
- } else {
2187
- return res();
2188
- }
2189
- },
2190
- onFailure: err => {
2191
- logger.debug('global sign out failed', err);
2192
- return rej(err);
2472
+ internalUser.globalSignOut(
2473
+ {
2474
+ onSuccess: data => {
2475
+ logger.debug('global sign out success');
2476
+ if (isSignedInHostedUI) {
2477
+ this.oAuthSignOutRedirect(res, rej);
2478
+ } else {
2479
+ return res();
2480
+ }
2481
+ },
2482
+ onFailure: err => {
2483
+ logger.debug('global sign out failed', err);
2484
+ return rej(err);
2485
+ },
2193
2486
  },
2194
- });
2487
+ userAgentValue
2488
+ );
2195
2489
  },
2196
- { clientMetadata }
2490
+ { clientMetadata },
2491
+ userAgentValue
2197
2492
  );
2198
2493
  } else {
2199
- logger.debug('user sign out', user);
2200
- user.signOut(() => {
2494
+ logger.debug('user sign out', internalUser);
2495
+ internalUser.signOut(() => {
2201
2496
  if (isSignedInHostedUI) {
2202
2497
  this.oAuthSignOutRedirect(res, rej);
2203
2498
  } else {
2204
2499
  return res();
2205
2500
  }
2206
- });
2501
+ }, userAgentValue);
2207
2502
  }
2208
2503
  });
2209
2504
  }
@@ -2250,9 +2545,14 @@ export class InternalAuthClass {
2250
2545
  }
2251
2546
 
2252
2547
  if (this.userPool) {
2253
- const user = this.userPool.getCurrentUser();
2254
- if (user) {
2255
- await this.cognitoIdentitySignOut(opts, user);
2548
+ const internalUser =
2549
+ this.userPool.getCurrentUser() as InternalCognitoUser;
2550
+ if (internalUser) {
2551
+ await this.cognitoIdentitySignOut(
2552
+ opts,
2553
+ internalUser,
2554
+ getAuthUserAgentValue(AuthAction.SignOut, customUserAgentDetails)
2555
+ );
2256
2556
  } else {
2257
2557
  logger.debug('no current Cognito user');
2258
2558
  }
@@ -2291,9 +2591,15 @@ export class InternalAuthClass {
2291
2591
  clientMetadata: ClientMetaData = this._config.clientMetadata,
2292
2592
  customUserAgentDetails?: CustomUserAgentDetails
2293
2593
  ): Promise<'SUCCESS'> {
2594
+ const internalUser: InternalCognitoUser | any = user;
2595
+ const userAgentValue = getAuthUserAgentValue(
2596
+ AuthAction.ChangePassword,
2597
+ customUserAgentDetails
2598
+ );
2599
+
2294
2600
  return new Promise((resolve, reject) => {
2295
- this.userSession(user).then(session => {
2296
- user.changePassword(
2601
+ this._userSession(userAgentValue, internalUser).then(session => {
2602
+ internalUser.changePassword(
2297
2603
  oldPassword,
2298
2604
  newPassword,
2299
2605
  (err, data) => {
@@ -2304,7 +2610,8 @@ export class InternalAuthClass {
2304
2610
  return resolve(data);
2305
2611
  }
2306
2612
  },
2307
- clientMetadata
2613
+ clientMetadata,
2614
+ userAgentValue
2308
2615
  );
2309
2616
  });
2310
2617
  });
@@ -2329,9 +2636,9 @@ export class InternalAuthClass {
2329
2636
  return this.rejectAuthError(AuthErrorTypes.EmptyUsername);
2330
2637
  }
2331
2638
 
2332
- const user = this.createCognitoUser(username);
2639
+ const internalUser = this.createCognitoUser(username);
2333
2640
  return new Promise((resolve, reject) => {
2334
- user.forgotPassword(
2641
+ internalUser.forgotPassword(
2335
2642
  {
2336
2643
  onSuccess: () => {
2337
2644
  resolve();
@@ -2350,14 +2657,15 @@ export class InternalAuthClass {
2350
2657
  inputVerificationCode: data => {
2351
2658
  dispatchAuthEvent(
2352
2659
  'forgotPassword',
2353
- user,
2660
+ internalUser,
2354
2661
  `${username} has initiated forgot password flow`
2355
2662
  );
2356
2663
  resolve(data);
2357
2664
  return;
2358
2665
  },
2359
2666
  },
2360
- clientMetadata
2667
+ clientMetadata,
2668
+ getAuthUserAgentValue(AuthAction.ForgotPassword, customUserAgentDetails)
2361
2669
  );
2362
2670
  });
2363
2671
  }
@@ -2391,16 +2699,16 @@ export class InternalAuthClass {
2391
2699
  return this.rejectAuthError(AuthErrorTypes.EmptyPassword);
2392
2700
  }
2393
2701
 
2394
- const user = this.createCognitoUser(username);
2702
+ const internalUser = this.createCognitoUser(username);
2395
2703
  return new Promise((resolve, reject) => {
2396
- user.confirmPassword(
2704
+ internalUser.confirmPassword(
2397
2705
  code,
2398
2706
  password,
2399
2707
  {
2400
2708
  onSuccess: success => {
2401
2709
  dispatchAuthEvent(
2402
2710
  'forgotPasswordSubmit',
2403
- user,
2711
+ internalUser,
2404
2712
  `${username} forgotPasswordSubmit successful`
2405
2713
  );
2406
2714
  resolve(success);
@@ -2416,7 +2724,11 @@ export class InternalAuthClass {
2416
2724
  return;
2417
2725
  },
2418
2726
  },
2419
- clientMetadata
2727
+ clientMetadata,
2728
+ getAuthUserAgentValue(
2729
+ AuthAction.ForgotPasswordSubmit,
2730
+ customUserAgentDetails
2731
+ )
2420
2732
  );
2421
2733
  });
2422
2734
  }
@@ -2431,17 +2743,25 @@ export class InternalAuthClass {
2431
2743
  customUserAgentDetails?: CustomUserAgentDetails
2432
2744
  ) {
2433
2745
  const source = this.Credentials.getCredSource();
2746
+ const userAgentDetails = getAuthUserAgentDetails(
2747
+ AuthAction.CurrentUserInfo,
2748
+ customUserAgentDetails
2749
+ );
2434
2750
 
2435
2751
  if (!source || source === 'aws' || source === 'userPool') {
2436
- const user = await this.currentUserPoolUser().catch(err =>
2437
- logger.error(err)
2438
- );
2439
- if (!user) {
2752
+ const internalUser: InternalCognitoUser = await this._currentUserPoolUser(
2753
+ undefined,
2754
+ userAgentDetails
2755
+ ).catch(err => logger.error(err));
2756
+ if (!internalUser) {
2440
2757
  return null;
2441
2758
  }
2442
2759
 
2443
2760
  try {
2444
- const attributes = await this.userAttributes(user);
2761
+ const attributes = await this._userAttributes(
2762
+ internalUser,
2763
+ userAgentDetails
2764
+ );
2445
2765
  const userAttrs: object = this.attributesToObject(attributes);
2446
2766
  let credentials = null;
2447
2767
  try {
@@ -2455,7 +2775,7 @@ export class InternalAuthClass {
2455
2775
 
2456
2776
  const info = {
2457
2777
  id: credentials ? credentials.identityId : undefined,
2458
- username: user.getUsername(),
2778
+ username: internalUser.getUsername(),
2459
2779
  attributes: userAttrs,
2460
2780
  };
2461
2781
  return info;
@@ -2521,6 +2841,14 @@ export class InternalAuthClass {
2521
2841
  ? this._config.oauth.redirectSignIn
2522
2842
  : this._config.oauth.redirectUri;
2523
2843
 
2844
+ this._storage.setItem(
2845
+ 'aws-amplify-federatedUserAgent',
2846
+ getAuthUserAgentValue(
2847
+ AuthAction.FederatedSignIn,
2848
+ customUserAgentDetails
2849
+ )
2850
+ );
2851
+
2524
2852
  this._oAuthHandler.oauthSignIn(
2525
2853
  this._config.oauth.responseType,
2526
2854
  this._config.oauth.domain,
@@ -2550,7 +2878,7 @@ export class InternalAuthClass {
2550
2878
  { provider, token, identity_id, user, expires_at },
2551
2879
  'federation'
2552
2880
  );
2553
- const currentUser = await this.currentAuthenticatedUser();
2881
+ const currentUser = await this._currentAuthenticatedUser();
2554
2882
  dispatchAuthEvent(
2555
2883
  'signIn',
2556
2884
  currentUser,
@@ -2601,9 +2929,15 @@ export class InternalAuthClass {
2601
2929
 
2602
2930
  if (hasCodeOrError || hasTokenOrError) {
2603
2931
  this._storage.setItem('amplify-redirected-from-hosted-ui', 'true');
2932
+ const userAgentValue =
2933
+ this._storage.getItem('aws-amplify-federatedUserAgent') || undefined;
2934
+ this._storage.removeItem('aws-amplify-federatedUserAgent');
2604
2935
  try {
2605
2936
  const { accessToken, idToken, refreshToken, state } =
2606
- await this._oAuthHandler.handleAuthResponse(currentUrl);
2937
+ await this._oAuthHandler.handleAuthResponse(
2938
+ currentUrl,
2939
+ userAgentValue
2940
+ );
2607
2941
  const session = new CognitoUserSession({
2608
2942
  IdToken: new CognitoIdToken({ IdToken: idToken }),
2609
2943
  RefreshToken: new CognitoRefreshToken({
@@ -2745,7 +3079,7 @@ export class InternalAuthClass {
2745
3079
  );
2746
3080
  }
2747
3081
 
2748
- private createCognitoUser(username: string): CognitoUser {
3082
+ private createCognitoUser(username: string): InternalCognitoUser {
2749
3083
  const userData: ICognitoUserData = {
2750
3084
  Username: username,
2751
3085
  Pool: this.userPool,
@@ -2754,11 +3088,11 @@ export class InternalAuthClass {
2754
3088
 
2755
3089
  const { authenticationFlowType } = this._config;
2756
3090
 
2757
- const user = new CognitoUser(userData);
3091
+ const internalUser = new InternalCognitoUser(userData);
2758
3092
  if (authenticationFlowType) {
2759
- user.setAuthenticationFlowType(authenticationFlowType);
3093
+ internalUser.setAuthenticationFlowType(authenticationFlowType);
2760
3094
  }
2761
- return user;
3095
+ return internalUser;
2762
3096
  }
2763
3097
 
2764
3098
  private _isValidAuthStorage(obj) {
@@ -2793,78 +3127,105 @@ export class InternalAuthClass {
2793
3127
  public async rememberDevice(
2794
3128
  customUserAgentDetails?: CustomUserAgentDetails
2795
3129
  ): Promise<string | AuthError> {
2796
- let currUser;
3130
+ let internalUser: InternalCognitoUser | any;
3131
+ const userAgentDetails = getAuthUserAgentDetails(
3132
+ AuthAction.RememberDevice,
3133
+ customUserAgentDetails
3134
+ );
2797
3135
 
2798
3136
  try {
2799
- currUser = await this.currentUserPoolUser();
3137
+ internalUser = await this._currentUserPoolUser(
3138
+ undefined,
3139
+ userAgentDetails
3140
+ );
2800
3141
  } catch (error) {
2801
3142
  logger.debug('The user is not authenticated by the error', error);
2802
3143
  return Promise.reject('The user is not authenticated');
2803
3144
  }
2804
3145
 
2805
- currUser.getCachedDeviceKeyAndPassword();
3146
+ internalUser.getCachedDeviceKeyAndPassword();
2806
3147
  return new Promise((res, rej) => {
2807
- currUser.setDeviceStatusRemembered({
2808
- onSuccess: data => {
2809
- res(data);
2810
- },
2811
- onFailure: err => {
2812
- if (err.code === 'InvalidParameterException') {
2813
- rej(new AuthError(AuthErrorTypes.DeviceConfig));
2814
- } else if (err.code === 'NetworkError') {
2815
- rej(new AuthError(AuthErrorTypes.NetworkError));
2816
- } else {
2817
- rej(err);
2818
- }
3148
+ internalUser.setDeviceStatusRemembered(
3149
+ {
3150
+ onSuccess: data => {
3151
+ res(data);
3152
+ },
3153
+ onFailure: err => {
3154
+ if (err.code === 'InvalidParameterException') {
3155
+ rej(new AuthError(AuthErrorTypes.DeviceConfig));
3156
+ } else if (err.code === 'NetworkError') {
3157
+ rej(new AuthError(AuthErrorTypes.NetworkError));
3158
+ } else {
3159
+ rej(err);
3160
+ }
3161
+ },
2819
3162
  },
2820
- });
3163
+ getAmplifyUserAgent(userAgentDetails)
3164
+ );
2821
3165
  });
2822
3166
  }
2823
3167
 
2824
3168
  public async forgetDevice(
2825
3169
  customUserAgentDetails?: CustomUserAgentDetails
2826
3170
  ): Promise<void> {
2827
- let currUser;
3171
+ let internalUser: InternalCognitoUser | any;
3172
+ const userAgentDetails = getAuthUserAgentDetails(
3173
+ AuthAction.ForgetDevice,
3174
+ customUserAgentDetails
3175
+ );
2828
3176
 
2829
3177
  try {
2830
- currUser = await this.currentUserPoolUser();
3178
+ internalUser = await this._currentUserPoolUser(
3179
+ undefined,
3180
+ userAgentDetails
3181
+ );
2831
3182
  } catch (error) {
2832
3183
  logger.debug('The user is not authenticated by the error', error);
2833
3184
  return Promise.reject('The user is not authenticated');
2834
3185
  }
2835
3186
 
2836
- currUser.getCachedDeviceKeyAndPassword();
3187
+ internalUser.getCachedDeviceKeyAndPassword();
2837
3188
  return new Promise((res, rej) => {
2838
- currUser.forgetDevice({
2839
- onSuccess: data => {
2840
- res(data);
2841
- },
2842
- onFailure: err => {
2843
- if (err.code === 'InvalidParameterException') {
2844
- rej(new AuthError(AuthErrorTypes.DeviceConfig));
2845
- } else if (err.code === 'NetworkError') {
2846
- rej(new AuthError(AuthErrorTypes.NetworkError));
2847
- } else {
2848
- rej(err);
2849
- }
3189
+ internalUser.forgetDevice(
3190
+ {
3191
+ onSuccess: data => {
3192
+ res(data);
3193
+ },
3194
+ onFailure: err => {
3195
+ if (err.code === 'InvalidParameterException') {
3196
+ rej(new AuthError(AuthErrorTypes.DeviceConfig));
3197
+ } else if (err.code === 'NetworkError') {
3198
+ rej(new AuthError(AuthErrorTypes.NetworkError));
3199
+ } else {
3200
+ rej(err);
3201
+ }
3202
+ },
2850
3203
  },
2851
- });
3204
+ getAmplifyUserAgent(userAgentDetails)
3205
+ );
2852
3206
  });
2853
3207
  }
2854
3208
 
2855
3209
  public async fetchDevices(
2856
3210
  customUserAgentDetails?: CustomUserAgentDetails
2857
3211
  ): Promise<IAuthDevice[]> {
2858
- let currUser;
3212
+ let internalUser: InternalCognitoUser | any;
3213
+ const userAgentDetails = getAuthUserAgentDetails(
3214
+ AuthAction.FetchDevices,
3215
+ customUserAgentDetails
3216
+ );
2859
3217
 
2860
3218
  try {
2861
- currUser = await this.currentUserPoolUser();
3219
+ internalUser = await this._currentUserPoolUser(
3220
+ undefined,
3221
+ userAgentDetails
3222
+ );
2862
3223
  } catch (error) {
2863
3224
  logger.debug('The user is not authenticated by the error', error);
2864
3225
  throw new Error('The user is not authenticated');
2865
3226
  }
2866
3227
 
2867
- currUser.getCachedDeviceKeyAndPassword();
3228
+ internalUser.getCachedDeviceKeyAndPassword();
2868
3229
  return new Promise((res, rej) => {
2869
3230
  const cb = {
2870
3231
  onSuccess(data) {
@@ -2892,7 +3253,12 @@ export class InternalAuthClass {
2892
3253
  }
2893
3254
  },
2894
3255
  };
2895
- currUser.listDevices(MAX_DEVICES, null, cb);
3256
+ internalUser.listDevices(
3257
+ MAX_DEVICES,
3258
+ null,
3259
+ cb,
3260
+ getAmplifyUserAgent(userAgentDetails)
3261
+ );
2896
3262
  });
2897
3263
  }
2898
3264
  }