@aws-amplify/auth 4.4.3-unstable.3 → 4.4.3
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/CHANGELOG.md +11 -0
- package/dist/aws-amplify-auth.js +572 -156
- package/dist/aws-amplify-auth.js.map +1 -1
- package/dist/aws-amplify-auth.min.js +8 -8
- package/dist/aws-amplify-auth.min.js.map +1 -1
- package/lib/Auth.d.ts +9 -0
- package/lib/Auth.js +363 -162
- package/lib/Auth.js.map +1 -1
- package/lib-esm/Auth.d.ts +9 -0
- package/lib-esm/Auth.js +363 -162
- package/lib-esm/Auth.js.map +1 -1
- package/package.json +5 -5
- package/src/Auth.ts +194 -25
package/dist/aws-amplify-auth.js
CHANGED
|
@@ -11323,21 +11323,68 @@ function () {
|
|
|
11323
11323
|
|
|
11324
11324
|
var bypassCache = params ? params.bypassCache : false;
|
|
11325
11325
|
user.getUserData(function (err, data) {
|
|
11326
|
-
|
|
11327
|
-
|
|
11328
|
-
|
|
11329
|
-
|
|
11330
|
-
|
|
11326
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
11327
|
+
var cleanUpError_1, mfaType;
|
|
11328
|
+
return __generator(this, function (_a) {
|
|
11329
|
+
switch (_a.label) {
|
|
11330
|
+
case 0:
|
|
11331
|
+
if (!err) return [3
|
|
11332
|
+
/*break*/
|
|
11333
|
+
, 5];
|
|
11334
|
+
logger.debug('getting preferred mfa failed', err);
|
|
11335
|
+
if (!this.isSessionInvalid(err)) return [3
|
|
11336
|
+
/*break*/
|
|
11337
|
+
, 4];
|
|
11338
|
+
_a.label = 1;
|
|
11331
11339
|
|
|
11332
|
-
|
|
11340
|
+
case 1:
|
|
11341
|
+
_a.trys.push([1, 3,, 4]);
|
|
11333
11342
|
|
|
11334
|
-
|
|
11335
|
-
|
|
11336
|
-
|
|
11337
|
-
|
|
11338
|
-
|
|
11339
|
-
|
|
11340
|
-
|
|
11343
|
+
return [4
|
|
11344
|
+
/*yield*/
|
|
11345
|
+
, this.cleanUpInvalidSession(user)];
|
|
11346
|
+
|
|
11347
|
+
case 2:
|
|
11348
|
+
_a.sent();
|
|
11349
|
+
|
|
11350
|
+
return [3
|
|
11351
|
+
/*break*/
|
|
11352
|
+
, 4];
|
|
11353
|
+
|
|
11354
|
+
case 3:
|
|
11355
|
+
cleanUpError_1 = _a.sent();
|
|
11356
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_1.message));
|
|
11357
|
+
return [2
|
|
11358
|
+
/*return*/
|
|
11359
|
+
];
|
|
11360
|
+
|
|
11361
|
+
case 4:
|
|
11362
|
+
rej(err);
|
|
11363
|
+
return [2
|
|
11364
|
+
/*return*/
|
|
11365
|
+
];
|
|
11366
|
+
|
|
11367
|
+
case 5:
|
|
11368
|
+
mfaType = that._getMfaTypeFromUserData(data);
|
|
11369
|
+
|
|
11370
|
+
if (!mfaType) {
|
|
11371
|
+
rej('invalid MFA Type');
|
|
11372
|
+
return [2
|
|
11373
|
+
/*return*/
|
|
11374
|
+
];
|
|
11375
|
+
} else {
|
|
11376
|
+
res(mfaType);
|
|
11377
|
+
return [2
|
|
11378
|
+
/*return*/
|
|
11379
|
+
];
|
|
11380
|
+
}
|
|
11381
|
+
|
|
11382
|
+
return [2
|
|
11383
|
+
/*return*/
|
|
11384
|
+
];
|
|
11385
|
+
}
|
|
11386
|
+
});
|
|
11387
|
+
});
|
|
11341
11388
|
}, {
|
|
11342
11389
|
bypassCache: bypassCache,
|
|
11343
11390
|
clientMetadata: clientMetadata
|
|
@@ -11379,16 +11426,62 @@ function () {
|
|
|
11379
11426
|
};
|
|
11380
11427
|
|
|
11381
11428
|
AuthClass.prototype._getUserData = function (user, params) {
|
|
11429
|
+
var _this = this;
|
|
11430
|
+
|
|
11382
11431
|
return new Promise(function (res, rej) {
|
|
11383
11432
|
user.getUserData(function (err, data) {
|
|
11384
|
-
|
|
11385
|
-
|
|
11386
|
-
|
|
11387
|
-
|
|
11388
|
-
|
|
11389
|
-
|
|
11390
|
-
|
|
11391
|
-
|
|
11433
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
11434
|
+
var cleanUpError_2;
|
|
11435
|
+
return __generator(this, function (_a) {
|
|
11436
|
+
switch (_a.label) {
|
|
11437
|
+
case 0:
|
|
11438
|
+
if (!err) return [3
|
|
11439
|
+
/*break*/
|
|
11440
|
+
, 5];
|
|
11441
|
+
logger.debug('getting user data failed', err);
|
|
11442
|
+
if (!this.isSessionInvalid(err)) return [3
|
|
11443
|
+
/*break*/
|
|
11444
|
+
, 4];
|
|
11445
|
+
_a.label = 1;
|
|
11446
|
+
|
|
11447
|
+
case 1:
|
|
11448
|
+
_a.trys.push([1, 3,, 4]);
|
|
11449
|
+
|
|
11450
|
+
return [4
|
|
11451
|
+
/*yield*/
|
|
11452
|
+
, this.cleanUpInvalidSession(user)];
|
|
11453
|
+
|
|
11454
|
+
case 2:
|
|
11455
|
+
_a.sent();
|
|
11456
|
+
|
|
11457
|
+
return [3
|
|
11458
|
+
/*break*/
|
|
11459
|
+
, 4];
|
|
11460
|
+
|
|
11461
|
+
case 3:
|
|
11462
|
+
cleanUpError_2 = _a.sent();
|
|
11463
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_2.message));
|
|
11464
|
+
return [2
|
|
11465
|
+
/*return*/
|
|
11466
|
+
];
|
|
11467
|
+
|
|
11468
|
+
case 4:
|
|
11469
|
+
rej(err);
|
|
11470
|
+
return [2
|
|
11471
|
+
/*return*/
|
|
11472
|
+
];
|
|
11473
|
+
|
|
11474
|
+
case 5:
|
|
11475
|
+
res(data);
|
|
11476
|
+
_a.label = 6;
|
|
11477
|
+
|
|
11478
|
+
case 6:
|
|
11479
|
+
return [2
|
|
11480
|
+
/*return*/
|
|
11481
|
+
];
|
|
11482
|
+
}
|
|
11483
|
+
});
|
|
11484
|
+
});
|
|
11392
11485
|
}, params);
|
|
11393
11486
|
});
|
|
11394
11487
|
};
|
|
@@ -11404,6 +11497,8 @@ function () {
|
|
|
11404
11497
|
return __awaiter(this, void 0, void 0, function () {
|
|
11405
11498
|
var clientMetadata, userData, smsMfaSettings, totpMfaSettings, _a, mfaList, currentMFAType, that;
|
|
11406
11499
|
|
|
11500
|
+
var _this = this;
|
|
11501
|
+
|
|
11407
11502
|
return __generator(this, function (_b) {
|
|
11408
11503
|
switch (_b.label) {
|
|
11409
11504
|
case 0:
|
|
@@ -11543,12 +11638,53 @@ function () {
|
|
|
11543
11638
|
logger.debug('Caching the latest user data into local'); // cache the latest result into user data
|
|
11544
11639
|
|
|
11545
11640
|
user.getUserData(function (err, data) {
|
|
11546
|
-
|
|
11547
|
-
|
|
11548
|
-
return
|
|
11549
|
-
|
|
11550
|
-
|
|
11551
|
-
|
|
11641
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
11642
|
+
var cleanUpError_3;
|
|
11643
|
+
return __generator(this, function (_a) {
|
|
11644
|
+
switch (_a.label) {
|
|
11645
|
+
case 0:
|
|
11646
|
+
if (!err) return [3
|
|
11647
|
+
/*break*/
|
|
11648
|
+
, 5];
|
|
11649
|
+
logger.debug('getting user data failed', err);
|
|
11650
|
+
if (!this.isSessionInvalid(err)) return [3
|
|
11651
|
+
/*break*/
|
|
11652
|
+
, 4];
|
|
11653
|
+
_a.label = 1;
|
|
11654
|
+
|
|
11655
|
+
case 1:
|
|
11656
|
+
_a.trys.push([1, 3,, 4]);
|
|
11657
|
+
|
|
11658
|
+
return [4
|
|
11659
|
+
/*yield*/
|
|
11660
|
+
, this.cleanUpInvalidSession(user)];
|
|
11661
|
+
|
|
11662
|
+
case 2:
|
|
11663
|
+
_a.sent();
|
|
11664
|
+
|
|
11665
|
+
return [3
|
|
11666
|
+
/*break*/
|
|
11667
|
+
, 4];
|
|
11668
|
+
|
|
11669
|
+
case 3:
|
|
11670
|
+
cleanUpError_3 = _a.sent();
|
|
11671
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_3.message));
|
|
11672
|
+
return [2
|
|
11673
|
+
/*return*/
|
|
11674
|
+
];
|
|
11675
|
+
|
|
11676
|
+
case 4:
|
|
11677
|
+
return [2
|
|
11678
|
+
/*return*/
|
|
11679
|
+
, rej(err)];
|
|
11680
|
+
|
|
11681
|
+
case 5:
|
|
11682
|
+
return [2
|
|
11683
|
+
/*return*/
|
|
11684
|
+
, res(result)];
|
|
11685
|
+
}
|
|
11686
|
+
});
|
|
11687
|
+
});
|
|
11552
11688
|
}, {
|
|
11553
11689
|
bypassCache: true,
|
|
11554
11690
|
clientMetadata: clientMetadata
|
|
@@ -11885,7 +12021,7 @@ function () {
|
|
|
11885
12021
|
* Delete the current authenticated user
|
|
11886
12022
|
* @return {Promise}
|
|
11887
12023
|
**/
|
|
11888
|
-
//TODO: Check return type void
|
|
12024
|
+
// TODO: Check return type void
|
|
11889
12025
|
|
|
11890
12026
|
|
|
11891
12027
|
AuthClass.prototype.deleteUser = function () {
|
|
@@ -11937,44 +12073,80 @@ function () {
|
|
|
11937
12073
|
} else {
|
|
11938
12074
|
user_1.getSession(function (err, session) {
|
|
11939
12075
|
return __awaiter(_this, void 0, void 0, function () {
|
|
12076
|
+
var cleanUpError_4;
|
|
12077
|
+
|
|
11940
12078
|
var _this = this;
|
|
11941
12079
|
|
|
11942
12080
|
return __generator(this, function (_a) {
|
|
11943
|
-
|
|
11944
|
-
|
|
11945
|
-
|
|
11946
|
-
|
|
11947
|
-
|
|
11948
|
-
|
|
11949
|
-
|
|
11950
|
-
|
|
11951
|
-
|
|
11952
|
-
|
|
11953
|
-
|
|
11954
|
-
|
|
11955
|
-
|
|
11956
|
-
|
|
11957
|
-
|
|
11958
|
-
|
|
11959
|
-
|
|
11960
|
-
|
|
11961
|
-
|
|
11962
|
-
|
|
11963
|
-
|
|
11964
|
-
|
|
11965
|
-
|
|
11966
|
-
|
|
12081
|
+
switch (_a.label) {
|
|
12082
|
+
case 0:
|
|
12083
|
+
if (!err) return [3
|
|
12084
|
+
/*break*/
|
|
12085
|
+
, 5];
|
|
12086
|
+
logger.debug('Failed to get the user session', err);
|
|
12087
|
+
if (!this.isSessionInvalid(err)) return [3
|
|
12088
|
+
/*break*/
|
|
12089
|
+
, 4];
|
|
12090
|
+
_a.label = 1;
|
|
12091
|
+
|
|
12092
|
+
case 1:
|
|
12093
|
+
_a.trys.push([1, 3,, 4]);
|
|
12094
|
+
|
|
12095
|
+
return [4
|
|
12096
|
+
/*yield*/
|
|
12097
|
+
, this.cleanUpInvalidSession(user_1)];
|
|
12098
|
+
|
|
12099
|
+
case 2:
|
|
12100
|
+
_a.sent();
|
|
12101
|
+
|
|
12102
|
+
return [3
|
|
12103
|
+
/*break*/
|
|
12104
|
+
, 4];
|
|
12105
|
+
|
|
12106
|
+
case 3:
|
|
12107
|
+
cleanUpError_4 = _a.sent();
|
|
12108
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_4.message));
|
|
12109
|
+
return [2
|
|
12110
|
+
/*return*/
|
|
12111
|
+
];
|
|
12112
|
+
|
|
12113
|
+
case 4:
|
|
12114
|
+
return [2
|
|
12115
|
+
/*return*/
|
|
12116
|
+
, rej(err)];
|
|
12117
|
+
|
|
12118
|
+
case 5:
|
|
12119
|
+
user_1.deleteUser(function (err, result) {
|
|
12120
|
+
if (err) {
|
|
12121
|
+
rej(err);
|
|
11967
12122
|
} else {
|
|
11968
|
-
dispatchAuthEvent('
|
|
11969
|
-
|
|
12123
|
+
dispatchAuthEvent('userDeleted', result, 'The authenticated user has been deleted.');
|
|
12124
|
+
user_1.signOut();
|
|
12125
|
+
_this.user = null;
|
|
12126
|
+
|
|
12127
|
+
try {
|
|
12128
|
+
_this.cleanCachedItems(); // clean aws credentials
|
|
12129
|
+
|
|
12130
|
+
} catch (e) {
|
|
12131
|
+
// TODO: change to rejects in refactor
|
|
12132
|
+
logger.debug('failed to clear cached items');
|
|
12133
|
+
}
|
|
12134
|
+
|
|
12135
|
+
if (isSignedInHostedUI) {
|
|
12136
|
+
_this.oAuthSignOutRedirect(res, rej);
|
|
12137
|
+
} else {
|
|
12138
|
+
dispatchAuthEvent('signOut', _this.user, "A user has been signed out");
|
|
12139
|
+
res(result);
|
|
12140
|
+
}
|
|
11970
12141
|
}
|
|
11971
|
-
}
|
|
11972
|
-
|
|
11973
|
-
}
|
|
12142
|
+
});
|
|
12143
|
+
_a.label = 6;
|
|
11974
12144
|
|
|
11975
|
-
|
|
11976
|
-
|
|
11977
|
-
|
|
12145
|
+
case 6:
|
|
12146
|
+
return [2
|
|
12147
|
+
/*return*/
|
|
12148
|
+
];
|
|
12149
|
+
}
|
|
11978
12150
|
});
|
|
11979
12151
|
});
|
|
11980
12152
|
});
|
|
@@ -12082,6 +12254,93 @@ function () {
|
|
|
12082
12254
|
};
|
|
12083
12255
|
});
|
|
12084
12256
|
};
|
|
12257
|
+
|
|
12258
|
+
AuthClass.prototype.isErrorWithMessage = function (err) {
|
|
12259
|
+
return _typeof(err) === 'object' && Object.prototype.hasOwnProperty.call(err, 'message');
|
|
12260
|
+
}; // Session revoked by another app
|
|
12261
|
+
|
|
12262
|
+
|
|
12263
|
+
AuthClass.prototype.isTokenRevokedError = function (err) {
|
|
12264
|
+
return this.isErrorWithMessage(err) && err.message === 'Access Token has been revoked';
|
|
12265
|
+
};
|
|
12266
|
+
|
|
12267
|
+
AuthClass.prototype.isRefreshTokenRevokedError = function (err) {
|
|
12268
|
+
return this.isErrorWithMessage(err) && err.message === 'Refresh Token has been revoked';
|
|
12269
|
+
};
|
|
12270
|
+
|
|
12271
|
+
AuthClass.prototype.isUserDisabledError = function (err) {
|
|
12272
|
+
return this.isErrorWithMessage(err) && err.message === 'User is disabled.';
|
|
12273
|
+
};
|
|
12274
|
+
|
|
12275
|
+
AuthClass.prototype.isUserDoesNotExistError = function (err) {
|
|
12276
|
+
return this.isErrorWithMessage(err) && err.message === 'User does not exist.';
|
|
12277
|
+
};
|
|
12278
|
+
|
|
12279
|
+
AuthClass.prototype.isRefreshTokenExpiredError = function (err) {
|
|
12280
|
+
return this.isErrorWithMessage(err) && err.message === 'Refresh Token has expired';
|
|
12281
|
+
};
|
|
12282
|
+
|
|
12283
|
+
AuthClass.prototype.isSignedInHostedUI = function () {
|
|
12284
|
+
return this._oAuthHandler && this._storage.getItem('amplify-signin-with-hostedUI') === 'true';
|
|
12285
|
+
};
|
|
12286
|
+
|
|
12287
|
+
AuthClass.prototype.isSessionInvalid = function (err) {
|
|
12288
|
+
return this.isUserDisabledError(err) || this.isUserDoesNotExistError(err) || this.isTokenRevokedError(err) || this.isRefreshTokenRevokedError(err) || this.isRefreshTokenExpiredError(err);
|
|
12289
|
+
};
|
|
12290
|
+
|
|
12291
|
+
AuthClass.prototype.cleanUpInvalidSession = function (user) {
|
|
12292
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
12293
|
+
var e_6;
|
|
12294
|
+
|
|
12295
|
+
var _this = this;
|
|
12296
|
+
|
|
12297
|
+
return __generator(this, function (_a) {
|
|
12298
|
+
switch (_a.label) {
|
|
12299
|
+
case 0:
|
|
12300
|
+
user.signOut();
|
|
12301
|
+
this.user = null;
|
|
12302
|
+
_a.label = 1;
|
|
12303
|
+
|
|
12304
|
+
case 1:
|
|
12305
|
+
_a.trys.push([1, 3,, 4]);
|
|
12306
|
+
|
|
12307
|
+
return [4
|
|
12308
|
+
/*yield*/
|
|
12309
|
+
, this.cleanCachedItems()];
|
|
12310
|
+
|
|
12311
|
+
case 2:
|
|
12312
|
+
_a.sent(); // clean aws credentials
|
|
12313
|
+
|
|
12314
|
+
|
|
12315
|
+
return [3
|
|
12316
|
+
/*break*/
|
|
12317
|
+
, 4];
|
|
12318
|
+
|
|
12319
|
+
case 3:
|
|
12320
|
+
e_6 = _a.sent();
|
|
12321
|
+
logger.debug('failed to clear cached items');
|
|
12322
|
+
return [3
|
|
12323
|
+
/*break*/
|
|
12324
|
+
, 4];
|
|
12325
|
+
|
|
12326
|
+
case 4:
|
|
12327
|
+
if (this.isSignedInHostedUI()) {
|
|
12328
|
+
return [2
|
|
12329
|
+
/*return*/
|
|
12330
|
+
, new Promise(function (res, rej) {
|
|
12331
|
+
_this.oAuthSignOutRedirect(res, rej);
|
|
12332
|
+
})];
|
|
12333
|
+
} else {
|
|
12334
|
+
dispatchAuthEvent('signOut', this.user, "A user has been signed out");
|
|
12335
|
+
}
|
|
12336
|
+
|
|
12337
|
+
return [2
|
|
12338
|
+
/*return*/
|
|
12339
|
+
];
|
|
12340
|
+
}
|
|
12341
|
+
});
|
|
12342
|
+
});
|
|
12343
|
+
};
|
|
12085
12344
|
/**
|
|
12086
12345
|
* Get current authenticated user
|
|
12087
12346
|
* @return - A promise resolves to current authenticated CognitoUser if success
|
|
@@ -12152,74 +12411,143 @@ function () {
|
|
|
12152
12411
|
|
|
12153
12412
|
user.getSession(function (err, session) {
|
|
12154
12413
|
return __awaiter(_this, void 0, void 0, function () {
|
|
12155
|
-
var bypassCache, clientMetadata, _a, scope;
|
|
12414
|
+
var cleanUpError_5, bypassCache, clientMetadata, _a, scope;
|
|
12156
12415
|
|
|
12157
12416
|
var _this = this;
|
|
12158
12417
|
|
|
12159
12418
|
return __generator(this, function (_b) {
|
|
12160
12419
|
switch (_b.label) {
|
|
12161
12420
|
case 0:
|
|
12162
|
-
if (err)
|
|
12163
|
-
|
|
12164
|
-
|
|
12165
|
-
|
|
12166
|
-
|
|
12167
|
-
|
|
12168
|
-
|
|
12421
|
+
if (!err) return [3
|
|
12422
|
+
/*break*/
|
|
12423
|
+
, 5];
|
|
12424
|
+
logger.debug('Failed to get the user session', err);
|
|
12425
|
+
if (!this.isSessionInvalid(err)) return [3
|
|
12426
|
+
/*break*/
|
|
12427
|
+
, 4];
|
|
12428
|
+
_b.label = 1;
|
|
12169
12429
|
|
|
12430
|
+
case 1:
|
|
12431
|
+
_b.trys.push([1, 3,, 4]);
|
|
12432
|
+
|
|
12433
|
+
return [4
|
|
12434
|
+
/*yield*/
|
|
12435
|
+
, this.cleanUpInvalidSession(user)];
|
|
12436
|
+
|
|
12437
|
+
case 2:
|
|
12438
|
+
_b.sent();
|
|
12439
|
+
|
|
12440
|
+
return [3
|
|
12441
|
+
/*break*/
|
|
12442
|
+
, 4];
|
|
12443
|
+
|
|
12444
|
+
case 3:
|
|
12445
|
+
cleanUpError_5 = _b.sent();
|
|
12446
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_5.message));
|
|
12447
|
+
return [2
|
|
12448
|
+
/*return*/
|
|
12449
|
+
];
|
|
12450
|
+
|
|
12451
|
+
case 4:
|
|
12452
|
+
rej(err);
|
|
12453
|
+
return [2
|
|
12454
|
+
/*return*/
|
|
12455
|
+
];
|
|
12456
|
+
|
|
12457
|
+
case 5:
|
|
12170
12458
|
bypassCache = params ? params.bypassCache : false;
|
|
12171
12459
|
if (!bypassCache) return [3
|
|
12172
12460
|
/*break*/
|
|
12173
|
-
,
|
|
12461
|
+
, 7];
|
|
12174
12462
|
return [4
|
|
12175
12463
|
/*yield*/
|
|
12176
12464
|
, this.Credentials.clear()];
|
|
12177
12465
|
|
|
12178
|
-
case
|
|
12466
|
+
case 6:
|
|
12179
12467
|
_b.sent();
|
|
12180
12468
|
|
|
12181
|
-
_b.label =
|
|
12469
|
+
_b.label = 7;
|
|
12182
12470
|
|
|
12183
|
-
case
|
|
12471
|
+
case 7:
|
|
12184
12472
|
clientMetadata = this._config.clientMetadata;
|
|
12185
12473
|
_a = session.getAccessToken().decodePayload().scope, scope = _a === void 0 ? '' : _a;
|
|
12186
12474
|
|
|
12187
12475
|
if (scope.split(' ').includes(USER_ADMIN_SCOPE)) {
|
|
12188
12476
|
user.getUserData(function (err, data) {
|
|
12189
|
-
|
|
12190
|
-
|
|
12191
|
-
|
|
12192
|
-
|
|
12193
|
-
|
|
12194
|
-
|
|
12195
|
-
|
|
12196
|
-
|
|
12197
|
-
|
|
12198
|
-
|
|
12199
|
-
|
|
12200
|
-
|
|
12201
|
-
|
|
12202
|
-
|
|
12203
|
-
|
|
12204
|
-
|
|
12205
|
-
|
|
12206
|
-
|
|
12207
|
-
|
|
12208
|
-
|
|
12209
|
-
|
|
12210
|
-
|
|
12211
|
-
|
|
12212
|
-
|
|
12213
|
-
|
|
12214
|
-
|
|
12215
|
-
|
|
12216
|
-
|
|
12217
|
-
|
|
12218
|
-
|
|
12219
|
-
|
|
12220
|
-
|
|
12477
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
12478
|
+
var cleanUpError_6, preferredMFA, attributeList, i, attribute, userAttribute, attributes;
|
|
12479
|
+
return __generator(this, function (_a) {
|
|
12480
|
+
switch (_a.label) {
|
|
12481
|
+
case 0:
|
|
12482
|
+
if (!err) return [3
|
|
12483
|
+
/*break*/
|
|
12484
|
+
, 7];
|
|
12485
|
+
logger.debug('getting user data failed', err);
|
|
12486
|
+
if (!this.isSessionInvalid(err)) return [3
|
|
12487
|
+
/*break*/
|
|
12488
|
+
, 5];
|
|
12489
|
+
_a.label = 1;
|
|
12490
|
+
|
|
12491
|
+
case 1:
|
|
12492
|
+
_a.trys.push([1, 3,, 4]);
|
|
12493
|
+
|
|
12494
|
+
return [4
|
|
12495
|
+
/*yield*/
|
|
12496
|
+
, this.cleanUpInvalidSession(user)];
|
|
12497
|
+
|
|
12498
|
+
case 2:
|
|
12499
|
+
_a.sent();
|
|
12500
|
+
|
|
12501
|
+
return [3
|
|
12502
|
+
/*break*/
|
|
12503
|
+
, 4];
|
|
12504
|
+
|
|
12505
|
+
case 3:
|
|
12506
|
+
cleanUpError_6 = _a.sent();
|
|
12507
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_6.message));
|
|
12508
|
+
return [2
|
|
12509
|
+
/*return*/
|
|
12510
|
+
];
|
|
12511
|
+
|
|
12512
|
+
case 4:
|
|
12513
|
+
rej(err);
|
|
12514
|
+
return [3
|
|
12515
|
+
/*break*/
|
|
12516
|
+
, 6];
|
|
12517
|
+
|
|
12518
|
+
case 5:
|
|
12519
|
+
res(user);
|
|
12520
|
+
_a.label = 6;
|
|
12521
|
+
|
|
12522
|
+
case 6:
|
|
12523
|
+
return [2
|
|
12524
|
+
/*return*/
|
|
12525
|
+
];
|
|
12526
|
+
|
|
12527
|
+
case 7:
|
|
12528
|
+
preferredMFA = data.PreferredMfaSetting || 'NOMFA';
|
|
12529
|
+
attributeList = [];
|
|
12530
|
+
|
|
12531
|
+
for (i = 0; i < data.UserAttributes.length; i++) {
|
|
12532
|
+
attribute = {
|
|
12533
|
+
Name: data.UserAttributes[i].Name,
|
|
12534
|
+
Value: data.UserAttributes[i].Value
|
|
12535
|
+
};
|
|
12536
|
+
userAttribute = new amazon_cognito_identity_js__WEBPACK_IMPORTED_MODULE_2__["CognitoUserAttribute"](attribute);
|
|
12537
|
+
attributeList.push(userAttribute);
|
|
12538
|
+
}
|
|
12539
|
+
|
|
12540
|
+
attributes = this.attributesToObject(attributeList);
|
|
12541
|
+
Object.assign(user, {
|
|
12542
|
+
attributes: attributes,
|
|
12543
|
+
preferredMFA: preferredMFA
|
|
12544
|
+
});
|
|
12545
|
+
return [2
|
|
12546
|
+
/*return*/
|
|
12547
|
+
, res(user)];
|
|
12548
|
+
}
|
|
12549
|
+
});
|
|
12221
12550
|
});
|
|
12222
|
-
return res(user);
|
|
12223
12551
|
}, {
|
|
12224
12552
|
bypassCache: bypassCache,
|
|
12225
12553
|
clientMetadata: clientMetadata
|
|
@@ -12265,7 +12593,7 @@ function () {
|
|
|
12265
12593
|
|
|
12266
12594
|
AuthClass.prototype.currentAuthenticatedUser = function (params) {
|
|
12267
12595
|
return __awaiter(this, void 0, void 0, function () {
|
|
12268
|
-
var federatedUser,
|
|
12596
|
+
var federatedUser, e_7, federatedInfo, user, e_8;
|
|
12269
12597
|
return __generator(this, function (_a) {
|
|
12270
12598
|
switch (_a.label) {
|
|
12271
12599
|
case 0:
|
|
@@ -12288,9 +12616,9 @@ function () {
|
|
|
12288
12616
|
, 4];
|
|
12289
12617
|
|
|
12290
12618
|
case 3:
|
|
12291
|
-
|
|
12292
|
-
logger.debug('Failed to sync cache info into memory',
|
|
12293
|
-
throw
|
|
12619
|
+
e_7 = _a.sent();
|
|
12620
|
+
logger.debug('Failed to sync cache info into memory', e_7);
|
|
12621
|
+
throw e_7;
|
|
12294
12622
|
|
|
12295
12623
|
case 4:
|
|
12296
12624
|
try {
|
|
@@ -12333,13 +12661,13 @@ function () {
|
|
|
12333
12661
|
, 9];
|
|
12334
12662
|
|
|
12335
12663
|
case 8:
|
|
12336
|
-
|
|
12664
|
+
e_8 = _a.sent();
|
|
12337
12665
|
|
|
12338
|
-
if (
|
|
12666
|
+
if (e_8 === 'No userPool') {
|
|
12339
12667
|
logger.error('Cannot get the current user because the user pool is missing. ' + 'Please make sure the Auth module is configured with a valid Cognito User Pool ID');
|
|
12340
12668
|
}
|
|
12341
12669
|
|
|
12342
|
-
logger.debug('The user is not authenticated by the error',
|
|
12670
|
+
logger.debug('The user is not authenticated by the error', e_8);
|
|
12343
12671
|
return [2
|
|
12344
12672
|
/*return*/
|
|
12345
12673
|
, Promise.reject('The user is not authenticated')];
|
|
@@ -12364,7 +12692,7 @@ function () {
|
|
|
12364
12692
|
logger.debug('Getting current session'); // Purposely not calling the reject method here because we don't need a console error
|
|
12365
12693
|
|
|
12366
12694
|
if (!this.userPool) {
|
|
12367
|
-
return
|
|
12695
|
+
return this.rejectNoUserPool();
|
|
12368
12696
|
}
|
|
12369
12697
|
|
|
12370
12698
|
return new Promise(function (res, rej) {
|
|
@@ -12392,6 +12720,8 @@ function () {
|
|
|
12392
12720
|
|
|
12393
12721
|
|
|
12394
12722
|
AuthClass.prototype.userSession = function (user) {
|
|
12723
|
+
var _this = this;
|
|
12724
|
+
|
|
12395
12725
|
if (!user) {
|
|
12396
12726
|
logger.debug('the user is null');
|
|
12397
12727
|
return this.rejectAuthError(_types_Auth__WEBPACK_IMPORTED_MODULE_7__["AuthErrorTypes"].NoUserSession);
|
|
@@ -12399,18 +12729,59 @@ function () {
|
|
|
12399
12729
|
|
|
12400
12730
|
var clientMetadata = this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
|
|
12401
12731
|
|
|
12402
|
-
return new Promise(function (
|
|
12732
|
+
return new Promise(function (res, rej) {
|
|
12403
12733
|
logger.debug('Getting the session from this user:', user);
|
|
12404
12734
|
user.getSession(function (err, session) {
|
|
12405
|
-
|
|
12406
|
-
|
|
12407
|
-
|
|
12408
|
-
|
|
12409
|
-
|
|
12410
|
-
|
|
12411
|
-
|
|
12412
|
-
|
|
12413
|
-
|
|
12735
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
12736
|
+
var cleanUpError_7;
|
|
12737
|
+
return __generator(this, function (_a) {
|
|
12738
|
+
switch (_a.label) {
|
|
12739
|
+
case 0:
|
|
12740
|
+
if (!err) return [3
|
|
12741
|
+
/*break*/
|
|
12742
|
+
, 5];
|
|
12743
|
+
logger.debug('Failed to get the session from user', user);
|
|
12744
|
+
if (!this.isSessionInvalid(err)) return [3
|
|
12745
|
+
/*break*/
|
|
12746
|
+
, 4];
|
|
12747
|
+
_a.label = 1;
|
|
12748
|
+
|
|
12749
|
+
case 1:
|
|
12750
|
+
_a.trys.push([1, 3,, 4]);
|
|
12751
|
+
|
|
12752
|
+
return [4
|
|
12753
|
+
/*yield*/
|
|
12754
|
+
, this.cleanUpInvalidSession(user)];
|
|
12755
|
+
|
|
12756
|
+
case 2:
|
|
12757
|
+
_a.sent();
|
|
12758
|
+
|
|
12759
|
+
return [3
|
|
12760
|
+
/*break*/
|
|
12761
|
+
, 4];
|
|
12762
|
+
|
|
12763
|
+
case 3:
|
|
12764
|
+
cleanUpError_7 = _a.sent();
|
|
12765
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_7.message));
|
|
12766
|
+
return [2
|
|
12767
|
+
/*return*/
|
|
12768
|
+
];
|
|
12769
|
+
|
|
12770
|
+
case 4:
|
|
12771
|
+
rej(err);
|
|
12772
|
+
return [2
|
|
12773
|
+
/*return*/
|
|
12774
|
+
];
|
|
12775
|
+
|
|
12776
|
+
case 5:
|
|
12777
|
+
logger.debug('Succeed to get the user session', session);
|
|
12778
|
+
res(session);
|
|
12779
|
+
return [2
|
|
12780
|
+
/*return*/
|
|
12781
|
+
];
|
|
12782
|
+
}
|
|
12783
|
+
});
|
|
12784
|
+
});
|
|
12414
12785
|
}, {
|
|
12415
12786
|
clientMetadata: clientMetadata
|
|
12416
12787
|
});
|
|
@@ -12424,7 +12795,7 @@ function () {
|
|
|
12424
12795
|
|
|
12425
12796
|
AuthClass.prototype.currentUserCredentials = function () {
|
|
12426
12797
|
return __awaiter(this, void 0, void 0, function () {
|
|
12427
|
-
var
|
|
12798
|
+
var e_9, federatedInfo;
|
|
12428
12799
|
|
|
12429
12800
|
var _this = this;
|
|
12430
12801
|
|
|
@@ -12449,9 +12820,9 @@ function () {
|
|
|
12449
12820
|
, 4];
|
|
12450
12821
|
|
|
12451
12822
|
case 3:
|
|
12452
|
-
|
|
12453
|
-
logger.debug('Failed to sync cache info into memory',
|
|
12454
|
-
throw
|
|
12823
|
+
e_9 = _a.sent();
|
|
12824
|
+
logger.debug('Failed to sync cache info into memory', e_9);
|
|
12825
|
+
throw e_9;
|
|
12455
12826
|
|
|
12456
12827
|
case 4:
|
|
12457
12828
|
federatedInfo = null;
|
|
@@ -12473,8 +12844,8 @@ function () {
|
|
|
12473
12844
|
, this.currentSession().then(function (session) {
|
|
12474
12845
|
logger.debug('getting session success', session);
|
|
12475
12846
|
return _this.Credentials.set(session, 'session');
|
|
12476
|
-
})["catch"](function (
|
|
12477
|
-
logger.debug('getting
|
|
12847
|
+
})["catch"](function () {
|
|
12848
|
+
logger.debug('getting guest credentials');
|
|
12478
12849
|
return _this.Credentials.set(null, 'guest');
|
|
12479
12850
|
})];
|
|
12480
12851
|
}
|
|
@@ -12566,7 +12937,7 @@ function () {
|
|
|
12566
12937
|
|
|
12567
12938
|
AuthClass.prototype.cognitoIdentitySignOut = function (opts, user) {
|
|
12568
12939
|
return __awaiter(this, void 0, void 0, function () {
|
|
12569
|
-
var
|
|
12940
|
+
var e_10, isSignedInHostedUI;
|
|
12570
12941
|
|
|
12571
12942
|
var _this = this;
|
|
12572
12943
|
|
|
@@ -12587,9 +12958,9 @@ function () {
|
|
|
12587
12958
|
, 3];
|
|
12588
12959
|
|
|
12589
12960
|
case 2:
|
|
12590
|
-
|
|
12591
|
-
logger.debug('Failed to sync cache info into memory',
|
|
12592
|
-
throw
|
|
12961
|
+
e_10 = _a.sent();
|
|
12962
|
+
logger.debug('Failed to sync cache info into memory', e_10);
|
|
12963
|
+
throw e_10;
|
|
12593
12964
|
|
|
12594
12965
|
case 3:
|
|
12595
12966
|
isSignedInHostedUI = this._oAuthHandler && this._storage.getItem('amplify-signin-with-hostedUI') === 'true';
|
|
@@ -12603,25 +12974,70 @@ function () {
|
|
|
12603
12974
|
var clientMetadata = _this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
|
|
12604
12975
|
|
|
12605
12976
|
user.getSession(function (err, result) {
|
|
12606
|
-
|
|
12607
|
-
|
|
12608
|
-
return rej(err);
|
|
12609
|
-
}
|
|
12977
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
12978
|
+
var cleanUpError_8;
|
|
12610
12979
|
|
|
12611
|
-
|
|
12612
|
-
onSuccess: function onSuccess(data) {
|
|
12613
|
-
logger.debug('global sign out success');
|
|
12980
|
+
var _this = this;
|
|
12614
12981
|
|
|
12615
|
-
|
|
12616
|
-
|
|
12617
|
-
|
|
12618
|
-
|
|
12982
|
+
return __generator(this, function (_a) {
|
|
12983
|
+
switch (_a.label) {
|
|
12984
|
+
case 0:
|
|
12985
|
+
if (!err) return [3
|
|
12986
|
+
/*break*/
|
|
12987
|
+
, 5];
|
|
12988
|
+
logger.debug('failed to get the user session', err);
|
|
12989
|
+
if (!this.isSessionInvalid(err)) return [3
|
|
12990
|
+
/*break*/
|
|
12991
|
+
, 4];
|
|
12992
|
+
_a.label = 1;
|
|
12993
|
+
|
|
12994
|
+
case 1:
|
|
12995
|
+
_a.trys.push([1, 3,, 4]);
|
|
12996
|
+
|
|
12997
|
+
return [4
|
|
12998
|
+
/*yield*/
|
|
12999
|
+
, this.cleanUpInvalidSession(user)];
|
|
13000
|
+
|
|
13001
|
+
case 2:
|
|
13002
|
+
_a.sent();
|
|
13003
|
+
|
|
13004
|
+
return [3
|
|
13005
|
+
/*break*/
|
|
13006
|
+
, 4];
|
|
13007
|
+
|
|
13008
|
+
case 3:
|
|
13009
|
+
cleanUpError_8 = _a.sent();
|
|
13010
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_8.message));
|
|
13011
|
+
return [2
|
|
13012
|
+
/*return*/
|
|
13013
|
+
];
|
|
13014
|
+
|
|
13015
|
+
case 4:
|
|
13016
|
+
return [2
|
|
13017
|
+
/*return*/
|
|
13018
|
+
, rej(err)];
|
|
13019
|
+
|
|
13020
|
+
case 5:
|
|
13021
|
+
user.globalSignOut({
|
|
13022
|
+
onSuccess: function onSuccess(data) {
|
|
13023
|
+
logger.debug('global sign out success');
|
|
13024
|
+
|
|
13025
|
+
if (isSignedInHostedUI) {
|
|
13026
|
+
_this.oAuthSignOutRedirect(res, rej);
|
|
13027
|
+
} else {
|
|
13028
|
+
return res();
|
|
13029
|
+
}
|
|
13030
|
+
},
|
|
13031
|
+
onFailure: function onFailure(err) {
|
|
13032
|
+
logger.debug('global sign out failed', err);
|
|
13033
|
+
return rej(err);
|
|
13034
|
+
}
|
|
13035
|
+
});
|
|
13036
|
+
return [2
|
|
13037
|
+
/*return*/
|
|
13038
|
+
];
|
|
12619
13039
|
}
|
|
12620
|
-
}
|
|
12621
|
-
onFailure: function onFailure(err) {
|
|
12622
|
-
logger.debug('global sign out failed', err);
|
|
12623
|
-
return rej(err);
|
|
12624
|
-
}
|
|
13040
|
+
});
|
|
12625
13041
|
});
|
|
12626
13042
|
}, {
|
|
12627
13043
|
clientMetadata: clientMetadata
|
|
@@ -12664,7 +13080,7 @@ function () {
|
|
|
12664
13080
|
|
|
12665
13081
|
|
|
12666
13082
|
setTimeout(function () {
|
|
12667
|
-
return reject('Signout timeout fail');
|
|
13083
|
+
return reject(Error('Signout timeout fail'));
|
|
12668
13084
|
}, 3000);
|
|
12669
13085
|
};
|
|
12670
13086
|
/**
|
|
@@ -12676,7 +13092,7 @@ function () {
|
|
|
12676
13092
|
|
|
12677
13093
|
AuthClass.prototype.signOut = function (opts) {
|
|
12678
13094
|
return __awaiter(this, void 0, void 0, function () {
|
|
12679
|
-
var
|
|
13095
|
+
var e_11, user;
|
|
12680
13096
|
return __generator(this, function (_a) {
|
|
12681
13097
|
switch (_a.label) {
|
|
12682
13098
|
case 0:
|
|
@@ -12694,7 +13110,7 @@ function () {
|
|
|
12694
13110
|
, 3];
|
|
12695
13111
|
|
|
12696
13112
|
case 2:
|
|
12697
|
-
|
|
13113
|
+
e_11 = _a.sent();
|
|
12698
13114
|
logger.debug('failed to clear cached items');
|
|
12699
13115
|
return [3
|
|
12700
13116
|
/*break*/
|
|
@@ -12729,7 +13145,7 @@ function () {
|
|
|
12729
13145
|
, 8];
|
|
12730
13146
|
|
|
12731
13147
|
case 7:
|
|
12732
|
-
logger.debug('no
|
|
13148
|
+
logger.debug('no Cognito User pool');
|
|
12733
13149
|
_a.label = 8;
|
|
12734
13150
|
|
|
12735
13151
|
case 8:
|
|
@@ -12895,7 +13311,7 @@ function () {
|
|
|
12895
13311
|
|
|
12896
13312
|
AuthClass.prototype.currentUserInfo = function () {
|
|
12897
13313
|
return __awaiter(this, void 0, void 0, function () {
|
|
12898
|
-
var source, user, attributes, userAttrs, credentials,
|
|
13314
|
+
var source, user, attributes, userAttrs, credentials, e_12, info, err_1, user;
|
|
12899
13315
|
return __generator(this, function (_a) {
|
|
12900
13316
|
switch (_a.label) {
|
|
12901
13317
|
case 0:
|
|
@@ -12947,8 +13363,8 @@ function () {
|
|
|
12947
13363
|
, 7];
|
|
12948
13364
|
|
|
12949
13365
|
case 6:
|
|
12950
|
-
|
|
12951
|
-
logger.debug('Failed to retrieve credentials while getting current user info',
|
|
13366
|
+
e_12 = _a.sent();
|
|
13367
|
+
logger.debug('Failed to retrieve credentials while getting current user info', e_12);
|
|
12952
13368
|
return [3
|
|
12953
13369
|
/*break*/
|
|
12954
13370
|
, 7];
|