@aws-amplify/auth 4.6.2-next.62 → 4.6.2-next.69
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/Auth.d.ts +0 -2
- package/lib/Auth.js +143 -148
- package/lib/Auth.js.map +1 -1
- package/lib-esm/Auth.d.ts +0 -2
- package/lib-esm/Auth.js +143 -148
- package/lib-esm/Auth.js.map +1 -1
- package/package.json +4 -4
- package/src/Auth.ts +112 -107
package/lib-esm/Auth.js
CHANGED
|
@@ -38,7 +38,6 @@ var AuthClass = /** @class */ (function () {
|
|
|
38
38
|
this.user = null;
|
|
39
39
|
this.oAuthFlowInProgress = false;
|
|
40
40
|
this.autoSignInInitiated = false;
|
|
41
|
-
this.inflightSessionPromise = null;
|
|
42
41
|
this.Credentials = Credentials;
|
|
43
42
|
this.wrapRefreshSessionCallback = function (callback) {
|
|
44
43
|
var wrapped = function (error, data) {
|
|
@@ -1375,10 +1374,10 @@ var AuthClass = /** @class */ (function () {
|
|
|
1375
1374
|
return new Promise(function (res, rej) {
|
|
1376
1375
|
_this._storageSync
|
|
1377
1376
|
.then(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1378
|
-
var user,
|
|
1377
|
+
var user, clientMetadata;
|
|
1379
1378
|
var _this = this;
|
|
1380
|
-
return __generator(this, function (
|
|
1381
|
-
switch (
|
|
1379
|
+
return __generator(this, function (_a) {
|
|
1380
|
+
switch (_a.label) {
|
|
1382
1381
|
case 0:
|
|
1383
1382
|
if (!this.isOAuthInProgress()) return [3 /*break*/, 2];
|
|
1384
1383
|
logger.debug('OAuth signIn in progress, waiting for resolution...');
|
|
@@ -1402,8 +1401,8 @@ var AuthClass = /** @class */ (function () {
|
|
|
1402
1401
|
}
|
|
1403
1402
|
})];
|
|
1404
1403
|
case 1:
|
|
1405
|
-
|
|
1406
|
-
|
|
1404
|
+
_a.sent();
|
|
1405
|
+
_a.label = 2;
|
|
1407
1406
|
case 2:
|
|
1408
1407
|
user = this.userPool.getCurrentUser();
|
|
1409
1408
|
if (!user) {
|
|
@@ -1411,77 +1410,96 @@ var AuthClass = /** @class */ (function () {
|
|
|
1411
1410
|
rej('No current user');
|
|
1412
1411
|
return [2 /*return*/];
|
|
1413
1412
|
}
|
|
1414
|
-
_b.label = 3;
|
|
1415
|
-
case 3:
|
|
1416
|
-
_b.trys.push([3, 7, , 8]);
|
|
1417
|
-
return [4 /*yield*/, this._userSession(user)];
|
|
1418
|
-
case 4:
|
|
1419
|
-
session = _b.sent();
|
|
1420
|
-
bypassCache = params ? params.bypassCache : false;
|
|
1421
|
-
if (!bypassCache) return [3 /*break*/, 6];
|
|
1422
|
-
return [4 /*yield*/, this.Credentials.clear()];
|
|
1423
|
-
case 5:
|
|
1424
|
-
_b.sent();
|
|
1425
|
-
_b.label = 6;
|
|
1426
|
-
case 6:
|
|
1427
1413
|
clientMetadata = this._config.clientMetadata;
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1414
|
+
// refresh the session if the session expired.
|
|
1415
|
+
user.getSession(function (err, session) { return __awaiter(_this, void 0, void 0, function () {
|
|
1416
|
+
var cleanUpError_5, bypassCache, clientMetadata, _a, scope;
|
|
1417
|
+
var _this = this;
|
|
1418
|
+
return __generator(this, function (_b) {
|
|
1419
|
+
switch (_b.label) {
|
|
1420
|
+
case 0:
|
|
1421
|
+
if (!err) return [3 /*break*/, 5];
|
|
1422
|
+
logger.debug('Failed to get the user session', err);
|
|
1423
|
+
if (!this.isSessionInvalid(err)) return [3 /*break*/, 4];
|
|
1424
|
+
_b.label = 1;
|
|
1425
|
+
case 1:
|
|
1426
|
+
_b.trys.push([1, 3, , 4]);
|
|
1427
|
+
return [4 /*yield*/, this.cleanUpInvalidSession(user)];
|
|
1428
|
+
case 2:
|
|
1429
|
+
_b.sent();
|
|
1430
|
+
return [3 /*break*/, 4];
|
|
1431
|
+
case 3:
|
|
1432
|
+
cleanUpError_5 = _b.sent();
|
|
1433
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_5.message));
|
|
1434
|
+
return [2 /*return*/];
|
|
1435
|
+
case 4:
|
|
1436
|
+
rej(err);
|
|
1437
|
+
return [2 /*return*/];
|
|
1438
|
+
case 5:
|
|
1439
|
+
bypassCache = params ? params.bypassCache : false;
|
|
1440
|
+
if (!bypassCache) return [3 /*break*/, 7];
|
|
1441
|
+
return [4 /*yield*/, this.Credentials.clear()];
|
|
1442
|
+
case 6:
|
|
1443
|
+
_b.sent();
|
|
1444
|
+
_b.label = 7;
|
|
1445
|
+
case 7:
|
|
1446
|
+
clientMetadata = this._config.clientMetadata;
|
|
1447
|
+
_a = session.getAccessToken().decodePayload().scope, scope = _a === void 0 ? '' : _a;
|
|
1448
|
+
if (scope.split(' ').includes(USER_ADMIN_SCOPE)) {
|
|
1449
|
+
user.getUserData(function (err, data) { return __awaiter(_this, void 0, void 0, function () {
|
|
1450
|
+
var cleanUpError_6, preferredMFA, attributeList, i, attribute, userAttribute, attributes;
|
|
1451
|
+
return __generator(this, function (_a) {
|
|
1452
|
+
switch (_a.label) {
|
|
1453
|
+
case 0:
|
|
1454
|
+
if (!err) return [3 /*break*/, 7];
|
|
1455
|
+
logger.debug('getting user data failed', err);
|
|
1456
|
+
if (!this.isSessionInvalid(err)) return [3 /*break*/, 5];
|
|
1457
|
+
_a.label = 1;
|
|
1458
|
+
case 1:
|
|
1459
|
+
_a.trys.push([1, 3, , 4]);
|
|
1460
|
+
return [4 /*yield*/, this.cleanUpInvalidSession(user)];
|
|
1461
|
+
case 2:
|
|
1462
|
+
_a.sent();
|
|
1463
|
+
return [3 /*break*/, 4];
|
|
1464
|
+
case 3:
|
|
1465
|
+
cleanUpError_6 = _a.sent();
|
|
1466
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_6.message));
|
|
1467
|
+
return [2 /*return*/];
|
|
1468
|
+
case 4:
|
|
1469
|
+
rej(err);
|
|
1470
|
+
return [3 /*break*/, 6];
|
|
1471
|
+
case 5:
|
|
1472
|
+
res(user);
|
|
1473
|
+
_a.label = 6;
|
|
1474
|
+
case 6: return [2 /*return*/];
|
|
1475
|
+
case 7:
|
|
1476
|
+
preferredMFA = data.PreferredMfaSetting || 'NOMFA';
|
|
1477
|
+
attributeList = [];
|
|
1478
|
+
for (i = 0; i < data.UserAttributes.length; i++) {
|
|
1479
|
+
attribute = {
|
|
1480
|
+
Name: data.UserAttributes[i].Name,
|
|
1481
|
+
Value: data.UserAttributes[i].Value,
|
|
1482
|
+
};
|
|
1483
|
+
userAttribute = new CognitoUserAttribute(attribute);
|
|
1484
|
+
attributeList.push(userAttribute);
|
|
1485
|
+
}
|
|
1486
|
+
attributes = this.attributesToObject(attributeList);
|
|
1487
|
+
Object.assign(user, { attributes: attributes, preferredMFA: preferredMFA });
|
|
1488
|
+
return [2 /*return*/, res(user)];
|
|
1489
|
+
}
|
|
1490
|
+
});
|
|
1491
|
+
}); }, { bypassCache: bypassCache, clientMetadata: clientMetadata });
|
|
1492
|
+
}
|
|
1493
|
+
else {
|
|
1494
|
+
logger.debug("Unable to get the user data because the " + USER_ADMIN_SCOPE + " " +
|
|
1495
|
+
"is not in the scopes of the access token");
|
|
1469
1496
|
return [2 /*return*/, res(user)];
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
"is not in the scopes of the access token");
|
|
1477
|
-
return [2 /*return*/, res(user)];
|
|
1478
|
-
}
|
|
1479
|
-
return [3 /*break*/, 8];
|
|
1480
|
-
case 7:
|
|
1481
|
-
err_1 = _b.sent();
|
|
1482
|
-
rej(err_1);
|
|
1483
|
-
return [3 /*break*/, 8];
|
|
1484
|
-
case 8: return [2 /*return*/];
|
|
1497
|
+
}
|
|
1498
|
+
return [2 /*return*/];
|
|
1499
|
+
}
|
|
1500
|
+
});
|
|
1501
|
+
}); }, { clientMetadata: clientMetadata });
|
|
1502
|
+
return [2 /*return*/];
|
|
1485
1503
|
}
|
|
1486
1504
|
});
|
|
1487
1505
|
}); })
|
|
@@ -1591,73 +1609,50 @@ var AuthClass = /** @class */ (function () {
|
|
|
1591
1609
|
});
|
|
1592
1610
|
});
|
|
1593
1611
|
};
|
|
1594
|
-
AuthClass.prototype._userSession = function (user) {
|
|
1595
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1596
|
-
var clientMetadata;
|
|
1597
|
-
var _this = this;
|
|
1598
|
-
return __generator(this, function (_a) {
|
|
1599
|
-
switch (_a.label) {
|
|
1600
|
-
case 0:
|
|
1601
|
-
if (!user) {
|
|
1602
|
-
logger.debug('the user is null');
|
|
1603
|
-
return [2 /*return*/, this.rejectAuthError(AuthErrorTypes.NoUserSession)];
|
|
1604
|
-
}
|
|
1605
|
-
clientMetadata = this._config.clientMetadata;
|
|
1606
|
-
// Debouncing the concurrent userSession calls by caching the promise.
|
|
1607
|
-
// This solution asumes users will always call this function with the same CognitoUser instance.
|
|
1608
|
-
if (!this.inflightSessionPromise) {
|
|
1609
|
-
this.inflightSessionPromise = new Promise(function (res, rej) {
|
|
1610
|
-
user.getSession(function (err, session) { return __awaiter(_this, void 0, void 0, function () {
|
|
1611
|
-
var cleanUpError_6;
|
|
1612
|
-
return __generator(this, function (_a) {
|
|
1613
|
-
switch (_a.label) {
|
|
1614
|
-
case 0:
|
|
1615
|
-
if (!err) return [3 /*break*/, 5];
|
|
1616
|
-
logger.debug('Failed to get the session from user', user);
|
|
1617
|
-
if (!this.isSessionInvalid(err)) return [3 /*break*/, 4];
|
|
1618
|
-
_a.label = 1;
|
|
1619
|
-
case 1:
|
|
1620
|
-
_a.trys.push([1, 3, , 4]);
|
|
1621
|
-
return [4 /*yield*/, this.cleanUpInvalidSession(user)];
|
|
1622
|
-
case 2:
|
|
1623
|
-
_a.sent();
|
|
1624
|
-
return [3 /*break*/, 4];
|
|
1625
|
-
case 3:
|
|
1626
|
-
cleanUpError_6 = _a.sent();
|
|
1627
|
-
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_6.message));
|
|
1628
|
-
return [2 /*return*/];
|
|
1629
|
-
case 4:
|
|
1630
|
-
rej(err);
|
|
1631
|
-
return [2 /*return*/];
|
|
1632
|
-
case 5:
|
|
1633
|
-
logger.debug('Succeed to get the user session', session);
|
|
1634
|
-
res(session);
|
|
1635
|
-
return [2 /*return*/];
|
|
1636
|
-
}
|
|
1637
|
-
});
|
|
1638
|
-
}); }, { clientMetadata: clientMetadata });
|
|
1639
|
-
});
|
|
1640
|
-
}
|
|
1641
|
-
_a.label = 1;
|
|
1642
|
-
case 1:
|
|
1643
|
-
_a.trys.push([1, , 3, 4]);
|
|
1644
|
-
return [4 /*yield*/, this.inflightSessionPromise];
|
|
1645
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
1646
|
-
case 3:
|
|
1647
|
-
this.inflightSessionPromise = null;
|
|
1648
|
-
return [7 /*endfinally*/];
|
|
1649
|
-
case 4: return [2 /*return*/];
|
|
1650
|
-
}
|
|
1651
|
-
});
|
|
1652
|
-
});
|
|
1653
|
-
};
|
|
1654
1612
|
/**
|
|
1655
1613
|
* Get the corresponding user session
|
|
1656
1614
|
* @param {Object} user - The CognitoUser object
|
|
1657
1615
|
* @return - A promise resolves to the session
|
|
1658
1616
|
*/
|
|
1659
1617
|
AuthClass.prototype.userSession = function (user) {
|
|
1660
|
-
|
|
1618
|
+
var _this = this;
|
|
1619
|
+
if (!user) {
|
|
1620
|
+
logger.debug('the user is null');
|
|
1621
|
+
return this.rejectAuthError(AuthErrorTypes.NoUserSession);
|
|
1622
|
+
}
|
|
1623
|
+
var clientMetadata = this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
|
|
1624
|
+
return new Promise(function (res, rej) {
|
|
1625
|
+
logger.debug('Getting the session from this user:', user);
|
|
1626
|
+
user.getSession(function (err, session) { return __awaiter(_this, void 0, void 0, function () {
|
|
1627
|
+
var cleanUpError_7;
|
|
1628
|
+
return __generator(this, function (_a) {
|
|
1629
|
+
switch (_a.label) {
|
|
1630
|
+
case 0:
|
|
1631
|
+
if (!err) return [3 /*break*/, 5];
|
|
1632
|
+
logger.debug('Failed to get the session from user', user);
|
|
1633
|
+
if (!this.isSessionInvalid(err)) return [3 /*break*/, 4];
|
|
1634
|
+
_a.label = 1;
|
|
1635
|
+
case 1:
|
|
1636
|
+
_a.trys.push([1, 3, , 4]);
|
|
1637
|
+
return [4 /*yield*/, this.cleanUpInvalidSession(user)];
|
|
1638
|
+
case 2:
|
|
1639
|
+
_a.sent();
|
|
1640
|
+
return [3 /*break*/, 4];
|
|
1641
|
+
case 3:
|
|
1642
|
+
cleanUpError_7 = _a.sent();
|
|
1643
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_7.message));
|
|
1644
|
+
return [2 /*return*/];
|
|
1645
|
+
case 4:
|
|
1646
|
+
rej(err);
|
|
1647
|
+
return [2 /*return*/];
|
|
1648
|
+
case 5:
|
|
1649
|
+
logger.debug('Succeed to get the user session', session);
|
|
1650
|
+
res(session);
|
|
1651
|
+
return [2 /*return*/];
|
|
1652
|
+
}
|
|
1653
|
+
});
|
|
1654
|
+
}); }, { clientMetadata: clientMetadata });
|
|
1655
|
+
});
|
|
1661
1656
|
};
|
|
1662
1657
|
/**
|
|
1663
1658
|
* Get authenticated credentials of current user.
|
|
@@ -1801,7 +1796,7 @@ var AuthClass = /** @class */ (function () {
|
|
|
1801
1796
|
// we must validate the user as an authenticated user by using getSession
|
|
1802
1797
|
var clientMetadata = _this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
|
|
1803
1798
|
user.getSession(function (err, result) { return __awaiter(_this, void 0, void 0, function () {
|
|
1804
|
-
var
|
|
1799
|
+
var cleanUpError_8;
|
|
1805
1800
|
var _this = this;
|
|
1806
1801
|
return __generator(this, function (_a) {
|
|
1807
1802
|
switch (_a.label) {
|
|
@@ -1817,8 +1812,8 @@ var AuthClass = /** @class */ (function () {
|
|
|
1817
1812
|
_a.sent();
|
|
1818
1813
|
return [3 /*break*/, 4];
|
|
1819
1814
|
case 3:
|
|
1820
|
-
|
|
1821
|
-
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " +
|
|
1815
|
+
cleanUpError_8 = _a.sent();
|
|
1816
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_8.message));
|
|
1822
1817
|
return [2 /*return*/];
|
|
1823
1818
|
case 4: return [2 /*return*/, rej(err)];
|
|
1824
1819
|
case 5:
|
|
@@ -2042,7 +2037,7 @@ var AuthClass = /** @class */ (function () {
|
|
|
2042
2037
|
*/
|
|
2043
2038
|
AuthClass.prototype.currentUserInfo = function () {
|
|
2044
2039
|
return __awaiter(this, void 0, void 0, function () {
|
|
2045
|
-
var source, user, attributes, userAttrs, credentials, e_12, info,
|
|
2040
|
+
var source, user, attributes, userAttrs, credentials, e_12, info, err_1, user;
|
|
2046
2041
|
return __generator(this, function (_a) {
|
|
2047
2042
|
switch (_a.label) {
|
|
2048
2043
|
case 0:
|
|
@@ -2083,8 +2078,8 @@ var AuthClass = /** @class */ (function () {
|
|
|
2083
2078
|
};
|
|
2084
2079
|
return [2 /*return*/, info];
|
|
2085
2080
|
case 8:
|
|
2086
|
-
|
|
2087
|
-
logger.error('currentUserInfo error',
|
|
2081
|
+
err_1 = _a.sent();
|
|
2082
|
+
logger.error('currentUserInfo error', err_1);
|
|
2088
2083
|
return [2 /*return*/, {}];
|
|
2089
2084
|
case 9:
|
|
2090
2085
|
if (source === 'federated') {
|
|
@@ -2165,7 +2160,7 @@ var AuthClass = /** @class */ (function () {
|
|
|
2165
2160
|
*/
|
|
2166
2161
|
AuthClass.prototype._handleAuthResponse = function (URL) {
|
|
2167
2162
|
return __awaiter(this, void 0, void 0, function () {
|
|
2168
|
-
var currentUrl, hasCodeOrError, hasTokenOrError, _a, accessToken, idToken, refreshToken, state, session, credentials, isCustomStateIncluded, currentUser, customState,
|
|
2163
|
+
var currentUrl, hasCodeOrError, hasTokenOrError, _a, accessToken, idToken, refreshToken, state, session, credentials, isCustomStateIncluded, currentUser, customState, err_2;
|
|
2169
2164
|
return __generator(this, function (_b) {
|
|
2170
2165
|
switch (_b.label) {
|
|
2171
2166
|
case 0:
|
|
@@ -2238,16 +2233,16 @@ var AuthClass = /** @class */ (function () {
|
|
|
2238
2233
|
//#endregion
|
|
2239
2234
|
return [2 /*return*/, credentials];
|
|
2240
2235
|
case 6:
|
|
2241
|
-
|
|
2242
|
-
logger.debug('Error in cognito hosted auth response',
|
|
2236
|
+
err_2 = _b.sent();
|
|
2237
|
+
logger.debug('Error in cognito hosted auth response', err_2);
|
|
2243
2238
|
// Just like a successful handling of `?code`, replace the window history to "dispose" of the `code`.
|
|
2244
2239
|
// Otherwise, reloading the page will throw errors as the `code` has already been spent.
|
|
2245
2240
|
if (window && typeof window.history !== 'undefined') {
|
|
2246
2241
|
window.history.replaceState({}, null, this._config.oauth.redirectSignIn);
|
|
2247
2242
|
}
|
|
2248
|
-
dispatchAuthEvent('signIn_failure',
|
|
2249
|
-
dispatchAuthEvent('cognitoHostedUI_failure',
|
|
2250
|
-
dispatchAuthEvent('customState_failure',
|
|
2243
|
+
dispatchAuthEvent('signIn_failure', err_2, "The OAuth response flow failed");
|
|
2244
|
+
dispatchAuthEvent('cognitoHostedUI_failure', err_2, "A failure occurred when returning to the Cognito Hosted UI");
|
|
2245
|
+
dispatchAuthEvent('customState_failure', err_2, "A failure occurred when returning state");
|
|
2251
2246
|
return [3 /*break*/, 7];
|
|
2252
2247
|
case 7: return [3 /*break*/, 9];
|
|
2253
2248
|
case 8:
|