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