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