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