@aws-amplify/auth 4.5.8-unstable.1 → 4.5.9-auth-hotfix.4
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 +8 -0
- package/dist/aws-amplify-auth.js +265 -223
- package/dist/aws-amplify-auth.js.map +1 -1
- package/dist/aws-amplify-auth.min.js +4 -4
- package/dist/aws-amplify-auth.min.js.map +1 -1
- package/lib/Auth.d.ts +3 -0
- package/lib/Auth.js +168 -143
- package/lib/Auth.js.map +1 -1
- package/lib-esm/Auth.d.ts +3 -0
- package/lib-esm/Auth.js +168 -143
- package/lib-esm/Auth.js.map +1 -1
- package/package.json +5 -5
- package/src/Auth.ts +106 -87
package/lib-esm/Auth.js
CHANGED
|
@@ -108,6 +108,8 @@ var AuthClass = /** @class */ (function () {
|
|
|
108
108
|
this.userPool = null;
|
|
109
109
|
this.user = null;
|
|
110
110
|
this.oAuthFlowInProgress = false;
|
|
111
|
+
this.inflightSessionPromise = null;
|
|
112
|
+
this.inflightSession = false;
|
|
111
113
|
this.Credentials = Credentials;
|
|
112
114
|
this.wrapRefreshSessionCallback = function (callback) {
|
|
113
115
|
var wrapped = function (error, data) {
|
|
@@ -1330,10 +1332,10 @@ var AuthClass = /** @class */ (function () {
|
|
|
1330
1332
|
return new Promise(function (res, rej) {
|
|
1331
1333
|
_this._storageSync
|
|
1332
1334
|
.then(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1333
|
-
var user, clientMetadata;
|
|
1335
|
+
var user, session, bypassCache, clientMetadata, _a, scope, err_1;
|
|
1334
1336
|
var _this = this;
|
|
1335
|
-
return __generator(this, function (
|
|
1336
|
-
switch (
|
|
1337
|
+
return __generator(this, function (_b) {
|
|
1338
|
+
switch (_b.label) {
|
|
1337
1339
|
case 0:
|
|
1338
1340
|
if (!this.isOAuthInProgress()) return [3 /*break*/, 2];
|
|
1339
1341
|
logger.debug('OAuth signIn in progress, waiting for resolution...');
|
|
@@ -1357,8 +1359,8 @@ var AuthClass = /** @class */ (function () {
|
|
|
1357
1359
|
}
|
|
1358
1360
|
})];
|
|
1359
1361
|
case 1:
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
+
_b.sent();
|
|
1363
|
+
_b.label = 2;
|
|
1362
1364
|
case 2:
|
|
1363
1365
|
user = this.userPool.getCurrentUser();
|
|
1364
1366
|
if (!user) {
|
|
@@ -1366,96 +1368,77 @@ var AuthClass = /** @class */ (function () {
|
|
|
1366
1368
|
rej('No current user');
|
|
1367
1369
|
return [2 /*return*/];
|
|
1368
1370
|
}
|
|
1371
|
+
_b.label = 3;
|
|
1372
|
+
case 3:
|
|
1373
|
+
_b.trys.push([3, 7, , 8]);
|
|
1374
|
+
return [4 /*yield*/, this._userSession({ user: user })];
|
|
1375
|
+
case 4:
|
|
1376
|
+
session = _b.sent();
|
|
1377
|
+
bypassCache = params ? params.bypassCache : false;
|
|
1378
|
+
if (!bypassCache) return [3 /*break*/, 6];
|
|
1379
|
+
return [4 /*yield*/, this.Credentials.clear()];
|
|
1380
|
+
case 5:
|
|
1381
|
+
_b.sent();
|
|
1382
|
+
_b.label = 6;
|
|
1383
|
+
case 6:
|
|
1369
1384
|
clientMetadata = this._config.clientMetadata;
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
return [
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
logger.debug('getting user data failed', err);
|
|
1412
|
-
if (!this.isSessionInvalid(err)) return [3 /*break*/, 5];
|
|
1413
|
-
_a.label = 1;
|
|
1414
|
-
case 1:
|
|
1415
|
-
_a.trys.push([1, 3, , 4]);
|
|
1416
|
-
return [4 /*yield*/, this.cleanUpInvalidSession(user)];
|
|
1417
|
-
case 2:
|
|
1418
|
-
_a.sent();
|
|
1419
|
-
return [3 /*break*/, 4];
|
|
1420
|
-
case 3:
|
|
1421
|
-
cleanUpError_6 = _a.sent();
|
|
1422
|
-
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_6.message));
|
|
1423
|
-
return [2 /*return*/];
|
|
1424
|
-
case 4:
|
|
1425
|
-
rej(err);
|
|
1426
|
-
return [3 /*break*/, 6];
|
|
1427
|
-
case 5:
|
|
1428
|
-
res(user);
|
|
1429
|
-
_a.label = 6;
|
|
1430
|
-
case 6: return [2 /*return*/];
|
|
1431
|
-
case 7:
|
|
1432
|
-
preferredMFA = data.PreferredMfaSetting || 'NOMFA';
|
|
1433
|
-
attributeList = [];
|
|
1434
|
-
for (i = 0; i < data.UserAttributes.length; i++) {
|
|
1435
|
-
attribute = {
|
|
1436
|
-
Name: data.UserAttributes[i].Name,
|
|
1437
|
-
Value: data.UserAttributes[i].Value,
|
|
1438
|
-
};
|
|
1439
|
-
userAttribute = new CognitoUserAttribute(attribute);
|
|
1440
|
-
attributeList.push(userAttribute);
|
|
1441
|
-
}
|
|
1442
|
-
attributes = this.attributesToObject(attributeList);
|
|
1443
|
-
Object.assign(user, { attributes: attributes, preferredMFA: preferredMFA });
|
|
1444
|
-
return [2 /*return*/, res(user)];
|
|
1445
|
-
}
|
|
1446
|
-
});
|
|
1447
|
-
}); }, { bypassCache: bypassCache, clientMetadata: clientMetadata });
|
|
1448
|
-
}
|
|
1449
|
-
else {
|
|
1450
|
-
logger.debug("Unable to get the user data because the " + USER_ADMIN_SCOPE + " " +
|
|
1451
|
-
"is not in the scopes of the access token");
|
|
1385
|
+
_a = session.getAccessToken().decodePayload().scope, scope = _a === void 0 ? '' : _a;
|
|
1386
|
+
if (scope.split(' ').includes(USER_ADMIN_SCOPE)) {
|
|
1387
|
+
user.getUserData(function (err, data) { return __awaiter(_this, void 0, void 0, function () {
|
|
1388
|
+
var cleanUpError_5, preferredMFA, attributeList, i, attribute, userAttribute, attributes;
|
|
1389
|
+
return __generator(this, function (_a) {
|
|
1390
|
+
switch (_a.label) {
|
|
1391
|
+
case 0:
|
|
1392
|
+
if (!err) return [3 /*break*/, 7];
|
|
1393
|
+
logger.debug('getting user data failed', err);
|
|
1394
|
+
if (!this.isSessionInvalid(err)) return [3 /*break*/, 5];
|
|
1395
|
+
_a.label = 1;
|
|
1396
|
+
case 1:
|
|
1397
|
+
_a.trys.push([1, 3, , 4]);
|
|
1398
|
+
return [4 /*yield*/, this.cleanUpInvalidSession(user)];
|
|
1399
|
+
case 2:
|
|
1400
|
+
_a.sent();
|
|
1401
|
+
return [3 /*break*/, 4];
|
|
1402
|
+
case 3:
|
|
1403
|
+
cleanUpError_5 = _a.sent();
|
|
1404
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_5.message));
|
|
1405
|
+
return [2 /*return*/];
|
|
1406
|
+
case 4:
|
|
1407
|
+
rej(err);
|
|
1408
|
+
return [3 /*break*/, 6];
|
|
1409
|
+
case 5:
|
|
1410
|
+
res(user);
|
|
1411
|
+
_a.label = 6;
|
|
1412
|
+
case 6: return [2 /*return*/];
|
|
1413
|
+
case 7:
|
|
1414
|
+
preferredMFA = data.PreferredMfaSetting || 'NOMFA';
|
|
1415
|
+
attributeList = [];
|
|
1416
|
+
for (i = 0; i < data.UserAttributes.length; i++) {
|
|
1417
|
+
attribute = {
|
|
1418
|
+
Name: data.UserAttributes[i].Name,
|
|
1419
|
+
Value: data.UserAttributes[i].Value,
|
|
1420
|
+
};
|
|
1421
|
+
userAttribute = new CognitoUserAttribute(attribute);
|
|
1422
|
+
attributeList.push(userAttribute);
|
|
1423
|
+
}
|
|
1424
|
+
attributes = this.attributesToObject(attributeList);
|
|
1425
|
+
Object.assign(user, { attributes: attributes, preferredMFA: preferredMFA });
|
|
1452
1426
|
return [2 /*return*/, res(user)];
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1427
|
+
}
|
|
1428
|
+
});
|
|
1429
|
+
}); }, { bypassCache: bypassCache, clientMetadata: clientMetadata });
|
|
1430
|
+
}
|
|
1431
|
+
else {
|
|
1432
|
+
logger.debug("Unable to get the user data because the " + USER_ADMIN_SCOPE + " " +
|
|
1433
|
+
"is not in the scopes of the access token");
|
|
1434
|
+
return [2 /*return*/, res(user)];
|
|
1435
|
+
}
|
|
1436
|
+
return [3 /*break*/, 8];
|
|
1437
|
+
case 7:
|
|
1438
|
+
err_1 = _b.sent();
|
|
1439
|
+
rej(err_1);
|
|
1440
|
+
return [3 /*break*/, 8];
|
|
1441
|
+
case 8: return [2 /*return*/];
|
|
1459
1442
|
}
|
|
1460
1443
|
});
|
|
1461
1444
|
}); })
|
|
@@ -1565,50 +1548,92 @@ var AuthClass = /** @class */ (function () {
|
|
|
1565
1548
|
});
|
|
1566
1549
|
});
|
|
1567
1550
|
};
|
|
1568
|
-
|
|
1569
|
-
* Get the corresponding user session
|
|
1570
|
-
* @param {Object} user - The CognitoUser object
|
|
1571
|
-
* @return - A promise resolves to the session
|
|
1572
|
-
*/
|
|
1573
|
-
AuthClass.prototype.userSession = function (user) {
|
|
1551
|
+
AuthClass.prototype._userSession = function (_a) {
|
|
1574
1552
|
var _this = this;
|
|
1553
|
+
var user = _a.user, _b = _a.bypassCache, bypassCache = _b === void 0 ? false : _b;
|
|
1575
1554
|
if (!user) {
|
|
1576
1555
|
logger.debug('the user is null');
|
|
1577
1556
|
return this.rejectAuthError(AuthErrorTypes.NoUserSession);
|
|
1578
1557
|
}
|
|
1579
1558
|
var clientMetadata = this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
|
|
1580
|
-
return new Promise(function (
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1559
|
+
return new Promise(function (resolve, rej) { return __awaiter(_this, void 0, void 0, function () {
|
|
1560
|
+
var debounceResolver;
|
|
1561
|
+
var _this = this;
|
|
1562
|
+
return __generator(this, function (_a) {
|
|
1563
|
+
switch (_a.label) {
|
|
1564
|
+
case 0:
|
|
1565
|
+
// debugger;
|
|
1566
|
+
logger.debug('Getting the session from this user:', user);
|
|
1567
|
+
if (!this.inflightSession) return [3 /*break*/, 2];
|
|
1568
|
+
logger.debug('Waiting for another userSession call:');
|
|
1569
|
+
return [4 /*yield*/, this.inflightSessionPromise];
|
|
1570
|
+
case 1:
|
|
1571
|
+
_a.sent();
|
|
1572
|
+
logger.debug('Debouncer resolved');
|
|
1573
|
+
return [3 /*break*/, 3];
|
|
1574
|
+
case 2:
|
|
1575
|
+
logger.debug('Debouncer head');
|
|
1576
|
+
this.inflightSession = true;
|
|
1577
|
+
this.inflightSessionPromise = new Promise(function (res) {
|
|
1578
|
+
debounceResolver = function () {
|
|
1579
|
+
logger.debug('Debouncer resolving');
|
|
1580
|
+
_this.inflightSessionPromise = null;
|
|
1581
|
+
_this.inflightSession = false;
|
|
1582
|
+
res();
|
|
1583
|
+
};
|
|
1584
|
+
});
|
|
1585
|
+
_a.label = 3;
|
|
1586
|
+
case 3:
|
|
1587
|
+
user.getSession(function (err, session) { return __awaiter(_this, void 0, void 0, function () {
|
|
1588
|
+
var cleanUpError_6;
|
|
1589
|
+
return __generator(this, function (_a) {
|
|
1590
|
+
switch (_a.label) {
|
|
1591
|
+
case 0:
|
|
1592
|
+
if (!err) return [3 /*break*/, 5];
|
|
1593
|
+
logger.debug('Failed to get the session from user', user);
|
|
1594
|
+
if (!this.isSessionInvalid(err)) return [3 /*break*/, 4];
|
|
1595
|
+
_a.label = 1;
|
|
1596
|
+
case 1:
|
|
1597
|
+
_a.trys.push([1, 3, , 4]);
|
|
1598
|
+
return [4 /*yield*/, this.cleanUpInvalidSession(user)];
|
|
1599
|
+
case 2:
|
|
1600
|
+
_a.sent();
|
|
1601
|
+
return [3 /*break*/, 4];
|
|
1602
|
+
case 3:
|
|
1603
|
+
cleanUpError_6 = _a.sent();
|
|
1604
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_6.message));
|
|
1605
|
+
if (debounceResolver) {
|
|
1606
|
+
debounceResolver();
|
|
1607
|
+
}
|
|
1608
|
+
return [2 /*return*/];
|
|
1609
|
+
case 4:
|
|
1610
|
+
rej(err);
|
|
1611
|
+
if (debounceResolver) {
|
|
1612
|
+
debounceResolver();
|
|
1613
|
+
}
|
|
1614
|
+
return [2 /*return*/];
|
|
1615
|
+
case 5:
|
|
1616
|
+
logger.debug('Succeed to get the user session', session);
|
|
1617
|
+
resolve(session);
|
|
1618
|
+
if (debounceResolver) {
|
|
1619
|
+
debounceResolver();
|
|
1620
|
+
}
|
|
1621
|
+
return [2 /*return*/];
|
|
1622
|
+
}
|
|
1623
|
+
});
|
|
1624
|
+
}); }, { clientMetadata: clientMetadata, bypassCache: bypassCache });
|
|
1625
|
+
return [2 /*return*/];
|
|
1626
|
+
}
|
|
1627
|
+
});
|
|
1628
|
+
}); });
|
|
1629
|
+
};
|
|
1630
|
+
/**
|
|
1631
|
+
* Get the corresponding user session
|
|
1632
|
+
* @param {Object} user - The CognitoUser object
|
|
1633
|
+
* @return - A promise resolves to the session
|
|
1634
|
+
*/
|
|
1635
|
+
AuthClass.prototype.userSession = function (user) {
|
|
1636
|
+
return this._userSession({ user: user, bypassCache: false });
|
|
1612
1637
|
};
|
|
1613
1638
|
/**
|
|
1614
1639
|
* Get authenticated credentials of current user.
|
|
@@ -1752,7 +1777,7 @@ var AuthClass = /** @class */ (function () {
|
|
|
1752
1777
|
// we must validate the user as an authenticated user by using getSession
|
|
1753
1778
|
var clientMetadata = _this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
|
|
1754
1779
|
user.getSession(function (err, result) { return __awaiter(_this, void 0, void 0, function () {
|
|
1755
|
-
var
|
|
1780
|
+
var cleanUpError_7;
|
|
1756
1781
|
var _this = this;
|
|
1757
1782
|
return __generator(this, function (_a) {
|
|
1758
1783
|
switch (_a.label) {
|
|
@@ -1768,8 +1793,8 @@ var AuthClass = /** @class */ (function () {
|
|
|
1768
1793
|
_a.sent();
|
|
1769
1794
|
return [3 /*break*/, 4];
|
|
1770
1795
|
case 3:
|
|
1771
|
-
|
|
1772
|
-
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " +
|
|
1796
|
+
cleanUpError_7 = _a.sent();
|
|
1797
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_7.message));
|
|
1773
1798
|
return [2 /*return*/];
|
|
1774
1799
|
case 4: return [2 /*return*/, rej(err)];
|
|
1775
1800
|
case 5:
|
|
@@ -1993,7 +2018,7 @@ var AuthClass = /** @class */ (function () {
|
|
|
1993
2018
|
*/
|
|
1994
2019
|
AuthClass.prototype.currentUserInfo = function () {
|
|
1995
2020
|
return __awaiter(this, void 0, void 0, function () {
|
|
1996
|
-
var source, user, attributes, userAttrs, credentials, e_12, info,
|
|
2021
|
+
var source, user, attributes, userAttrs, credentials, e_12, info, err_2, user;
|
|
1997
2022
|
return __generator(this, function (_a) {
|
|
1998
2023
|
switch (_a.label) {
|
|
1999
2024
|
case 0:
|
|
@@ -2034,8 +2059,8 @@ var AuthClass = /** @class */ (function () {
|
|
|
2034
2059
|
};
|
|
2035
2060
|
return [2 /*return*/, info];
|
|
2036
2061
|
case 8:
|
|
2037
|
-
|
|
2038
|
-
logger.error('currentUserInfo error',
|
|
2062
|
+
err_2 = _a.sent();
|
|
2063
|
+
logger.error('currentUserInfo error', err_2);
|
|
2039
2064
|
return [2 /*return*/, {}];
|
|
2040
2065
|
case 9:
|
|
2041
2066
|
if (source === 'federated') {
|
|
@@ -2116,7 +2141,7 @@ var AuthClass = /** @class */ (function () {
|
|
|
2116
2141
|
*/
|
|
2117
2142
|
AuthClass.prototype._handleAuthResponse = function (URL) {
|
|
2118
2143
|
return __awaiter(this, void 0, void 0, function () {
|
|
2119
|
-
var currentUrl, hasCodeOrError, hasTokenOrError, _a, accessToken, idToken, refreshToken, state, session, credentials, isCustomStateIncluded, currentUser, customState,
|
|
2144
|
+
var currentUrl, hasCodeOrError, hasTokenOrError, _a, accessToken, idToken, refreshToken, state, session, credentials, isCustomStateIncluded, currentUser, customState, err_3;
|
|
2120
2145
|
return __generator(this, function (_b) {
|
|
2121
2146
|
switch (_b.label) {
|
|
2122
2147
|
case 0:
|
|
@@ -2189,16 +2214,16 @@ var AuthClass = /** @class */ (function () {
|
|
|
2189
2214
|
//#endregion
|
|
2190
2215
|
return [2 /*return*/, credentials];
|
|
2191
2216
|
case 6:
|
|
2192
|
-
|
|
2193
|
-
logger.debug('Error in cognito hosted auth response',
|
|
2217
|
+
err_3 = _b.sent();
|
|
2218
|
+
logger.debug('Error in cognito hosted auth response', err_3);
|
|
2194
2219
|
// Just like a successful handling of `?code`, replace the window history to "dispose" of the `code`.
|
|
2195
2220
|
// Otherwise, reloading the page will throw errors as the `code` has already been spent.
|
|
2196
2221
|
if (window && typeof window.history !== 'undefined') {
|
|
2197
2222
|
window.history.replaceState({}, null, this._config.oauth.redirectSignIn);
|
|
2198
2223
|
}
|
|
2199
|
-
dispatchAuthEvent('signIn_failure',
|
|
2200
|
-
dispatchAuthEvent('cognitoHostedUI_failure',
|
|
2201
|
-
dispatchAuthEvent('customState_failure',
|
|
2224
|
+
dispatchAuthEvent('signIn_failure', err_3, "The OAuth response flow failed");
|
|
2225
|
+
dispatchAuthEvent('cognitoHostedUI_failure', err_3, "A failure occurred when returning to the Cognito Hosted UI");
|
|
2226
|
+
dispatchAuthEvent('customState_failure', err_3, "A failure occurred when returning state");
|
|
2202
2227
|
return [3 /*break*/, 7];
|
|
2203
2228
|
case 7: return [3 /*break*/, 9];
|
|
2204
2229
|
case 8:
|