@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/Auth.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export declare class AuthClass {
|
|
|
15
15
|
private _storageSync;
|
|
16
16
|
private oAuthFlowInProgress;
|
|
17
17
|
private pendingSignIn;
|
|
18
|
+
private inflightSessionPromise;
|
|
19
|
+
private inflightSession;
|
|
18
20
|
Credentials: import("@aws-amplify/core").CredentialsClass;
|
|
19
21
|
/**
|
|
20
22
|
* Initialize Auth with AWS configurations
|
|
@@ -192,6 +194,7 @@ export declare class AuthClass {
|
|
|
192
194
|
* @return - A promise resolves to session object if success
|
|
193
195
|
*/
|
|
194
196
|
currentSession(): Promise<CognitoUserSession>;
|
|
197
|
+
private _userSession;
|
|
195
198
|
/**
|
|
196
199
|
* Get the corresponding user session
|
|
197
200
|
* @param {Object} user - The CognitoUser object
|
package/lib/Auth.js
CHANGED
|
@@ -113,6 +113,8 @@ var AuthClass = /** @class */ (function () {
|
|
|
113
113
|
this.userPool = null;
|
|
114
114
|
this.user = null;
|
|
115
115
|
this.oAuthFlowInProgress = false;
|
|
116
|
+
this.inflightSessionPromise = null;
|
|
117
|
+
this.inflightSession = false;
|
|
116
118
|
this.Credentials = core_1.Credentials;
|
|
117
119
|
this.wrapRefreshSessionCallback = function (callback) {
|
|
118
120
|
var wrapped = function (error, data) {
|
|
@@ -1335,10 +1337,10 @@ var AuthClass = /** @class */ (function () {
|
|
|
1335
1337
|
return new Promise(function (res, rej) {
|
|
1336
1338
|
_this._storageSync
|
|
1337
1339
|
.then(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1338
|
-
var user, clientMetadata;
|
|
1340
|
+
var user, session, bypassCache, clientMetadata, _a, scope, err_1;
|
|
1339
1341
|
var _this = this;
|
|
1340
|
-
return __generator(this, function (
|
|
1341
|
-
switch (
|
|
1342
|
+
return __generator(this, function (_b) {
|
|
1343
|
+
switch (_b.label) {
|
|
1342
1344
|
case 0:
|
|
1343
1345
|
if (!this.isOAuthInProgress()) return [3 /*break*/, 2];
|
|
1344
1346
|
logger.debug('OAuth signIn in progress, waiting for resolution...');
|
|
@@ -1362,8 +1364,8 @@ var AuthClass = /** @class */ (function () {
|
|
|
1362
1364
|
}
|
|
1363
1365
|
})];
|
|
1364
1366
|
case 1:
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
+
_b.sent();
|
|
1368
|
+
_b.label = 2;
|
|
1367
1369
|
case 2:
|
|
1368
1370
|
user = this.userPool.getCurrentUser();
|
|
1369
1371
|
if (!user) {
|
|
@@ -1371,96 +1373,77 @@ var AuthClass = /** @class */ (function () {
|
|
|
1371
1373
|
rej('No current user');
|
|
1372
1374
|
return [2 /*return*/];
|
|
1373
1375
|
}
|
|
1376
|
+
_b.label = 3;
|
|
1377
|
+
case 3:
|
|
1378
|
+
_b.trys.push([3, 7, , 8]);
|
|
1379
|
+
return [4 /*yield*/, this._userSession({ user: user })];
|
|
1380
|
+
case 4:
|
|
1381
|
+
session = _b.sent();
|
|
1382
|
+
bypassCache = params ? params.bypassCache : false;
|
|
1383
|
+
if (!bypassCache) return [3 /*break*/, 6];
|
|
1384
|
+
return [4 /*yield*/, this.Credentials.clear()];
|
|
1385
|
+
case 5:
|
|
1386
|
+
_b.sent();
|
|
1387
|
+
_b.label = 6;
|
|
1388
|
+
case 6:
|
|
1374
1389
|
clientMetadata = this._config.clientMetadata;
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
return [
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
logger.debug('getting user data failed', err);
|
|
1417
|
-
if (!this.isSessionInvalid(err)) return [3 /*break*/, 5];
|
|
1418
|
-
_a.label = 1;
|
|
1419
|
-
case 1:
|
|
1420
|
-
_a.trys.push([1, 3, , 4]);
|
|
1421
|
-
return [4 /*yield*/, this.cleanUpInvalidSession(user)];
|
|
1422
|
-
case 2:
|
|
1423
|
-
_a.sent();
|
|
1424
|
-
return [3 /*break*/, 4];
|
|
1425
|
-
case 3:
|
|
1426
|
-
cleanUpError_6 = _a.sent();
|
|
1427
|
-
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_6.message));
|
|
1428
|
-
return [2 /*return*/];
|
|
1429
|
-
case 4:
|
|
1430
|
-
rej(err);
|
|
1431
|
-
return [3 /*break*/, 6];
|
|
1432
|
-
case 5:
|
|
1433
|
-
res(user);
|
|
1434
|
-
_a.label = 6;
|
|
1435
|
-
case 6: return [2 /*return*/];
|
|
1436
|
-
case 7:
|
|
1437
|
-
preferredMFA = data.PreferredMfaSetting || 'NOMFA';
|
|
1438
|
-
attributeList = [];
|
|
1439
|
-
for (i = 0; i < data.UserAttributes.length; i++) {
|
|
1440
|
-
attribute = {
|
|
1441
|
-
Name: data.UserAttributes[i].Name,
|
|
1442
|
-
Value: data.UserAttributes[i].Value,
|
|
1443
|
-
};
|
|
1444
|
-
userAttribute = new amazon_cognito_identity_js_1.CognitoUserAttribute(attribute);
|
|
1445
|
-
attributeList.push(userAttribute);
|
|
1446
|
-
}
|
|
1447
|
-
attributes = this.attributesToObject(attributeList);
|
|
1448
|
-
Object.assign(user, { attributes: attributes, preferredMFA: preferredMFA });
|
|
1449
|
-
return [2 /*return*/, res(user)];
|
|
1450
|
-
}
|
|
1451
|
-
});
|
|
1452
|
-
}); }, { bypassCache: bypassCache, clientMetadata: clientMetadata });
|
|
1453
|
-
}
|
|
1454
|
-
else {
|
|
1455
|
-
logger.debug("Unable to get the user data because the " + USER_ADMIN_SCOPE + " " +
|
|
1456
|
-
"is not in the scopes of the access token");
|
|
1390
|
+
_a = session.getAccessToken().decodePayload().scope, scope = _a === void 0 ? '' : _a;
|
|
1391
|
+
if (scope.split(' ').includes(USER_ADMIN_SCOPE)) {
|
|
1392
|
+
user.getUserData(function (err, data) { return __awaiter(_this, void 0, void 0, function () {
|
|
1393
|
+
var cleanUpError_5, preferredMFA, attributeList, i, attribute, userAttribute, attributes;
|
|
1394
|
+
return __generator(this, function (_a) {
|
|
1395
|
+
switch (_a.label) {
|
|
1396
|
+
case 0:
|
|
1397
|
+
if (!err) return [3 /*break*/, 7];
|
|
1398
|
+
logger.debug('getting user data failed', err);
|
|
1399
|
+
if (!this.isSessionInvalid(err)) return [3 /*break*/, 5];
|
|
1400
|
+
_a.label = 1;
|
|
1401
|
+
case 1:
|
|
1402
|
+
_a.trys.push([1, 3, , 4]);
|
|
1403
|
+
return [4 /*yield*/, this.cleanUpInvalidSession(user)];
|
|
1404
|
+
case 2:
|
|
1405
|
+
_a.sent();
|
|
1406
|
+
return [3 /*break*/, 4];
|
|
1407
|
+
case 3:
|
|
1408
|
+
cleanUpError_5 = _a.sent();
|
|
1409
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_5.message));
|
|
1410
|
+
return [2 /*return*/];
|
|
1411
|
+
case 4:
|
|
1412
|
+
rej(err);
|
|
1413
|
+
return [3 /*break*/, 6];
|
|
1414
|
+
case 5:
|
|
1415
|
+
res(user);
|
|
1416
|
+
_a.label = 6;
|
|
1417
|
+
case 6: return [2 /*return*/];
|
|
1418
|
+
case 7:
|
|
1419
|
+
preferredMFA = data.PreferredMfaSetting || 'NOMFA';
|
|
1420
|
+
attributeList = [];
|
|
1421
|
+
for (i = 0; i < data.UserAttributes.length; i++) {
|
|
1422
|
+
attribute = {
|
|
1423
|
+
Name: data.UserAttributes[i].Name,
|
|
1424
|
+
Value: data.UserAttributes[i].Value,
|
|
1425
|
+
};
|
|
1426
|
+
userAttribute = new amazon_cognito_identity_js_1.CognitoUserAttribute(attribute);
|
|
1427
|
+
attributeList.push(userAttribute);
|
|
1428
|
+
}
|
|
1429
|
+
attributes = this.attributesToObject(attributeList);
|
|
1430
|
+
Object.assign(user, { attributes: attributes, preferredMFA: preferredMFA });
|
|
1457
1431
|
return [2 /*return*/, res(user)];
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1432
|
+
}
|
|
1433
|
+
});
|
|
1434
|
+
}); }, { bypassCache: bypassCache, clientMetadata: clientMetadata });
|
|
1435
|
+
}
|
|
1436
|
+
else {
|
|
1437
|
+
logger.debug("Unable to get the user data because the " + USER_ADMIN_SCOPE + " " +
|
|
1438
|
+
"is not in the scopes of the access token");
|
|
1439
|
+
return [2 /*return*/, res(user)];
|
|
1440
|
+
}
|
|
1441
|
+
return [3 /*break*/, 8];
|
|
1442
|
+
case 7:
|
|
1443
|
+
err_1 = _b.sent();
|
|
1444
|
+
rej(err_1);
|
|
1445
|
+
return [3 /*break*/, 8];
|
|
1446
|
+
case 8: return [2 /*return*/];
|
|
1464
1447
|
}
|
|
1465
1448
|
});
|
|
1466
1449
|
}); })
|
|
@@ -1570,50 +1553,92 @@ var AuthClass = /** @class */ (function () {
|
|
|
1570
1553
|
});
|
|
1571
1554
|
});
|
|
1572
1555
|
};
|
|
1573
|
-
|
|
1574
|
-
* Get the corresponding user session
|
|
1575
|
-
* @param {Object} user - The CognitoUser object
|
|
1576
|
-
* @return - A promise resolves to the session
|
|
1577
|
-
*/
|
|
1578
|
-
AuthClass.prototype.userSession = function (user) {
|
|
1556
|
+
AuthClass.prototype._userSession = function (_a) {
|
|
1579
1557
|
var _this = this;
|
|
1558
|
+
var user = _a.user, _b = _a.bypassCache, bypassCache = _b === void 0 ? false : _b;
|
|
1580
1559
|
if (!user) {
|
|
1581
1560
|
logger.debug('the user is null');
|
|
1582
1561
|
return this.rejectAuthError(Auth_1.AuthErrorTypes.NoUserSession);
|
|
1583
1562
|
}
|
|
1584
1563
|
var clientMetadata = this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
|
|
1585
|
-
return new Promise(function (
|
|
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
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1564
|
+
return new Promise(function (resolve, rej) { return __awaiter(_this, void 0, void 0, function () {
|
|
1565
|
+
var debounceResolver;
|
|
1566
|
+
var _this = this;
|
|
1567
|
+
return __generator(this, function (_a) {
|
|
1568
|
+
switch (_a.label) {
|
|
1569
|
+
case 0:
|
|
1570
|
+
// debugger;
|
|
1571
|
+
logger.debug('Getting the session from this user:', user);
|
|
1572
|
+
if (!this.inflightSession) return [3 /*break*/, 2];
|
|
1573
|
+
logger.debug('Waiting for another userSession call:');
|
|
1574
|
+
return [4 /*yield*/, this.inflightSessionPromise];
|
|
1575
|
+
case 1:
|
|
1576
|
+
_a.sent();
|
|
1577
|
+
logger.debug('Debouncer resolved');
|
|
1578
|
+
return [3 /*break*/, 3];
|
|
1579
|
+
case 2:
|
|
1580
|
+
logger.debug('Debouncer head');
|
|
1581
|
+
this.inflightSession = true;
|
|
1582
|
+
this.inflightSessionPromise = new Promise(function (res) {
|
|
1583
|
+
debounceResolver = function () {
|
|
1584
|
+
logger.debug('Debouncer resolving');
|
|
1585
|
+
_this.inflightSessionPromise = null;
|
|
1586
|
+
_this.inflightSession = false;
|
|
1587
|
+
res();
|
|
1588
|
+
};
|
|
1589
|
+
});
|
|
1590
|
+
_a.label = 3;
|
|
1591
|
+
case 3:
|
|
1592
|
+
user.getSession(function (err, session) { return __awaiter(_this, void 0, void 0, function () {
|
|
1593
|
+
var cleanUpError_6;
|
|
1594
|
+
return __generator(this, function (_a) {
|
|
1595
|
+
switch (_a.label) {
|
|
1596
|
+
case 0:
|
|
1597
|
+
if (!err) return [3 /*break*/, 5];
|
|
1598
|
+
logger.debug('Failed to get the session from user', user);
|
|
1599
|
+
if (!this.isSessionInvalid(err)) return [3 /*break*/, 4];
|
|
1600
|
+
_a.label = 1;
|
|
1601
|
+
case 1:
|
|
1602
|
+
_a.trys.push([1, 3, , 4]);
|
|
1603
|
+
return [4 /*yield*/, this.cleanUpInvalidSession(user)];
|
|
1604
|
+
case 2:
|
|
1605
|
+
_a.sent();
|
|
1606
|
+
return [3 /*break*/, 4];
|
|
1607
|
+
case 3:
|
|
1608
|
+
cleanUpError_6 = _a.sent();
|
|
1609
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_6.message));
|
|
1610
|
+
if (debounceResolver) {
|
|
1611
|
+
debounceResolver();
|
|
1612
|
+
}
|
|
1613
|
+
return [2 /*return*/];
|
|
1614
|
+
case 4:
|
|
1615
|
+
rej(err);
|
|
1616
|
+
if (debounceResolver) {
|
|
1617
|
+
debounceResolver();
|
|
1618
|
+
}
|
|
1619
|
+
return [2 /*return*/];
|
|
1620
|
+
case 5:
|
|
1621
|
+
logger.debug('Succeed to get the user session', session);
|
|
1622
|
+
resolve(session);
|
|
1623
|
+
if (debounceResolver) {
|
|
1624
|
+
debounceResolver();
|
|
1625
|
+
}
|
|
1626
|
+
return [2 /*return*/];
|
|
1627
|
+
}
|
|
1628
|
+
});
|
|
1629
|
+
}); }, { clientMetadata: clientMetadata, bypassCache: bypassCache });
|
|
1630
|
+
return [2 /*return*/];
|
|
1631
|
+
}
|
|
1632
|
+
});
|
|
1633
|
+
}); });
|
|
1634
|
+
};
|
|
1635
|
+
/**
|
|
1636
|
+
* Get the corresponding user session
|
|
1637
|
+
* @param {Object} user - The CognitoUser object
|
|
1638
|
+
* @return - A promise resolves to the session
|
|
1639
|
+
*/
|
|
1640
|
+
AuthClass.prototype.userSession = function (user) {
|
|
1641
|
+
return this._userSession({ user: user, bypassCache: false });
|
|
1617
1642
|
};
|
|
1618
1643
|
/**
|
|
1619
1644
|
* Get authenticated credentials of current user.
|
|
@@ -1757,7 +1782,7 @@ var AuthClass = /** @class */ (function () {
|
|
|
1757
1782
|
// we must validate the user as an authenticated user by using getSession
|
|
1758
1783
|
var clientMetadata = _this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
|
|
1759
1784
|
user.getSession(function (err, result) { return __awaiter(_this, void 0, void 0, function () {
|
|
1760
|
-
var
|
|
1785
|
+
var cleanUpError_7;
|
|
1761
1786
|
var _this = this;
|
|
1762
1787
|
return __generator(this, function (_a) {
|
|
1763
1788
|
switch (_a.label) {
|
|
@@ -1773,8 +1798,8 @@ var AuthClass = /** @class */ (function () {
|
|
|
1773
1798
|
_a.sent();
|
|
1774
1799
|
return [3 /*break*/, 4];
|
|
1775
1800
|
case 3:
|
|
1776
|
-
|
|
1777
|
-
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " +
|
|
1801
|
+
cleanUpError_7 = _a.sent();
|
|
1802
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_7.message));
|
|
1778
1803
|
return [2 /*return*/];
|
|
1779
1804
|
case 4: return [2 /*return*/, rej(err)];
|
|
1780
1805
|
case 5:
|
|
@@ -1998,7 +2023,7 @@ var AuthClass = /** @class */ (function () {
|
|
|
1998
2023
|
*/
|
|
1999
2024
|
AuthClass.prototype.currentUserInfo = function () {
|
|
2000
2025
|
return __awaiter(this, void 0, void 0, function () {
|
|
2001
|
-
var source, user, attributes, userAttrs, credentials, e_12, info,
|
|
2026
|
+
var source, user, attributes, userAttrs, credentials, e_12, info, err_2, user;
|
|
2002
2027
|
return __generator(this, function (_a) {
|
|
2003
2028
|
switch (_a.label) {
|
|
2004
2029
|
case 0:
|
|
@@ -2039,8 +2064,8 @@ var AuthClass = /** @class */ (function () {
|
|
|
2039
2064
|
};
|
|
2040
2065
|
return [2 /*return*/, info];
|
|
2041
2066
|
case 8:
|
|
2042
|
-
|
|
2043
|
-
logger.error('currentUserInfo error',
|
|
2067
|
+
err_2 = _a.sent();
|
|
2068
|
+
logger.error('currentUserInfo error', err_2);
|
|
2044
2069
|
return [2 /*return*/, {}];
|
|
2045
2070
|
case 9:
|
|
2046
2071
|
if (source === 'federated') {
|
|
@@ -2121,7 +2146,7 @@ var AuthClass = /** @class */ (function () {
|
|
|
2121
2146
|
*/
|
|
2122
2147
|
AuthClass.prototype._handleAuthResponse = function (URL) {
|
|
2123
2148
|
return __awaiter(this, void 0, void 0, function () {
|
|
2124
|
-
var currentUrl, hasCodeOrError, hasTokenOrError, _a, accessToken, idToken, refreshToken, state, session, credentials, isCustomStateIncluded, currentUser, customState,
|
|
2149
|
+
var currentUrl, hasCodeOrError, hasTokenOrError, _a, accessToken, idToken, refreshToken, state, session, credentials, isCustomStateIncluded, currentUser, customState, err_3;
|
|
2125
2150
|
return __generator(this, function (_b) {
|
|
2126
2151
|
switch (_b.label) {
|
|
2127
2152
|
case 0:
|
|
@@ -2194,16 +2219,16 @@ var AuthClass = /** @class */ (function () {
|
|
|
2194
2219
|
//#endregion
|
|
2195
2220
|
return [2 /*return*/, credentials];
|
|
2196
2221
|
case 6:
|
|
2197
|
-
|
|
2198
|
-
logger.debug('Error in cognito hosted auth response',
|
|
2222
|
+
err_3 = _b.sent();
|
|
2223
|
+
logger.debug('Error in cognito hosted auth response', err_3);
|
|
2199
2224
|
// Just like a successful handling of `?code`, replace the window history to "dispose" of the `code`.
|
|
2200
2225
|
// Otherwise, reloading the page will throw errors as the `code` has already been spent.
|
|
2201
2226
|
if (window && typeof window.history !== 'undefined') {
|
|
2202
2227
|
window.history.replaceState({}, null, this._config.oauth.redirectSignIn);
|
|
2203
2228
|
}
|
|
2204
|
-
dispatchAuthEvent('signIn_failure',
|
|
2205
|
-
dispatchAuthEvent('cognitoHostedUI_failure',
|
|
2206
|
-
dispatchAuthEvent('customState_failure',
|
|
2229
|
+
dispatchAuthEvent('signIn_failure', err_3, "The OAuth response flow failed");
|
|
2230
|
+
dispatchAuthEvent('cognitoHostedUI_failure', err_3, "A failure occurred when returning to the Cognito Hosted UI");
|
|
2231
|
+
dispatchAuthEvent('customState_failure', err_3, "A failure occurred when returning state");
|
|
2207
2232
|
return [3 /*break*/, 7];
|
|
2208
2233
|
case 7: return [3 /*break*/, 9];
|
|
2209
2234
|
case 8:
|