@aws-amplify/auth 4.6.2-next.36 → 4.6.2-next.41
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 +2 -0
- package/lib/Auth.js +150 -155
- package/lib/Auth.js.map +1 -1
- package/lib/Errors.js +2 -12
- package/lib/Errors.js.map +1 -1
- package/lib/OAuth/OAuth.js +2 -12
- package/lib/OAuth/OAuth.js.map +1 -1
- package/lib/OAuth/oauthStorage.js +2 -12
- package/lib/OAuth/oauthStorage.js.map +1 -1
- package/lib/OAuth/oauthStorage.native.js +2 -12
- package/lib/OAuth/oauthStorage.native.js.map +1 -1
- package/lib/OAuth/urlOpener.js +2 -12
- package/lib/OAuth/urlOpener.js.map +1 -1
- package/lib/OAuth/urlOpener.native.js +2 -12
- package/lib/OAuth/urlOpener.native.js.map +1 -1
- package/lib/index.js +2 -12
- package/lib/index.js.map +1 -1
- package/lib/types/Auth.js +2 -12
- package/lib/types/Auth.js.map +1 -1
- package/lib/types/index.js +2 -12
- package/lib/types/index.js.map +1 -1
- package/lib/urlListener.js +2 -12
- package/lib/urlListener.js.map +1 -1
- package/lib/urlListener.native.js +2 -12
- package/lib/urlListener.native.js.map +1 -1
- package/lib-esm/Auth.d.ts +2 -0
- package/lib-esm/Auth.js +150 -155
- package/lib-esm/Auth.js.map +1 -1
- package/lib-esm/Errors.js +2 -12
- package/lib-esm/Errors.js.map +1 -1
- package/lib-esm/OAuth/OAuth.js +2 -12
- package/lib-esm/OAuth/OAuth.js.map +1 -1
- package/lib-esm/OAuth/oauthStorage.js +2 -12
- package/lib-esm/OAuth/oauthStorage.js.map +1 -1
- package/lib-esm/OAuth/oauthStorage.native.js +2 -12
- package/lib-esm/OAuth/oauthStorage.native.js.map +1 -1
- package/lib-esm/OAuth/urlOpener.js +2 -12
- package/lib-esm/OAuth/urlOpener.js.map +1 -1
- package/lib-esm/OAuth/urlOpener.native.js +2 -12
- package/lib-esm/OAuth/urlOpener.native.js.map +1 -1
- package/lib-esm/index.js +2 -12
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/types/Auth.js +2 -12
- package/lib-esm/types/Auth.js.map +1 -1
- package/lib-esm/types/index.js +2 -12
- package/lib-esm/types/index.js.map +1 -1
- package/lib-esm/urlListener.js +2 -12
- package/lib-esm/urlListener.js.map +1 -1
- package/lib-esm/urlListener.native.js +2 -12
- package/lib-esm/urlListener.native.js.map +1 -1
- package/package.json +4 -5
- package/src/Auth.ts +109 -124
- package/src/Errors.ts +2 -12
- package/src/OAuth/OAuth.ts +2 -12
- package/src/OAuth/oauthStorage.native.ts +2 -12
- package/src/OAuth/oauthStorage.ts +2 -12
- package/src/OAuth/urlOpener.native.ts +2 -12
- package/src/OAuth/urlOpener.ts +2 -12
- package/src/index.ts +2 -12
- package/src/types/Auth.ts +2 -12
- package/src/types/index.ts +2 -12
- package/src/urlListener.native.ts +2 -12
- package/src/urlListener.ts +2 -12
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
8
|
-
* the License. A copy of the License is located at
|
|
9
|
-
*
|
|
10
|
-
* http://aws.amazon.com/apache2.0/
|
|
11
|
-
*
|
|
12
|
-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
13
|
-
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
14
|
-
* and limitations under the License.
|
|
15
|
-
*/
|
|
4
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
16
6
|
var core_1 = require("@aws-amplify/core");
|
|
17
7
|
var logger = new core_1.ConsoleLogger('urlListener');
|
|
18
8
|
var handler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlListener.native.js","sourceRoot":"","sources":["../src/urlListener.native.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"urlListener.native.js","sourceRoot":"","sources":["../src/urlListener.native.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AACrE,sCAAsC;AACtC,0CAA4D;AAC5D,IAAM,MAAM,GAAG,IAAI,oBAAM,CAAC,aAAa,CAAC,CAAC;AAEzC,IAAI,OAAO,CAAC;AAEZ,mBAAe,UAAM,QAAQ;;;;;QAC5B,IAAI,OAAO,EAAE;YACZ,sBAAO;SACP;QAKD,IAAI;YACH,CAAC,4BAA+C,EAA7C,oBAAO,EAAE,sBAAQ,CAA6B,CAAC;SAClD;QAAC,OAAO,KAAK,EAAE;YACf,wBAAwB;SACxB;QAED,OAAO;YACN,OAAO;gBACP,CAAC,UAAC,EAAiC;oBAA/B,IAAA,YAAG,EAAE,kCAAO;oBACf,MAAM,CAAC,KAAK,CAAC,aAAa,qBAAI,GAAG,KAAA,IAAK,IAAI,EAAG,CAAC;oBAC9C,QAAQ,CAAC,EAAE,GAAG,KAAA,EAAE,CAAC,CAAC;gBACnB,CAAC,CAAC,CAAC;QAEJ,oGAAoG;QACpG,IAAI,OAAO,CAAC,mBAAmB,KAAK,OAAO,UAAU,EAAE;YACtD,OAAO,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAC5C,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;SACzC;aAAM;YACN,kDAAkD;YAClD,MAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,+CAApB,YAAY,EAAa;YACzB,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;SACxD;QACD,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,UAAM,WAAW;;;;;6BAChD,CAAA,WAAW,KAAK,QAAQ,CAAA,EAAxB,wBAAwB;wBACR,qBAAM,OAAO,CAAC,aAAa,EAAE,EAAA;;wBAA1C,UAAU,GAAG,SAA6B;wBAChD,OAAO,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;;;;;aAE9B,CAAC,CAAC;;;KACH,EAAC"}
|
package/lib-esm/Auth.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare class AuthClass {
|
|
|
16
16
|
private oAuthFlowInProgress;
|
|
17
17
|
private pendingSignIn;
|
|
18
18
|
private autoSignInInitiated;
|
|
19
|
+
private inflightSessionPromise;
|
|
19
20
|
Credentials: import("@aws-amplify/core").CredentialsClass;
|
|
20
21
|
/**
|
|
21
22
|
* Initialize Auth with AWS configurations
|
|
@@ -199,6 +200,7 @@ export declare class AuthClass {
|
|
|
199
200
|
* @return - A promise resolves to session object if success
|
|
200
201
|
*/
|
|
201
202
|
currentSession(): Promise<CognitoUserSession>;
|
|
203
|
+
private _userSession;
|
|
202
204
|
/**
|
|
203
205
|
* Get the corresponding user session
|
|
204
206
|
* @param {Object} user - The CognitoUser object
|
package/lib-esm/Auth.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
5
|
-
* the License. A copy of the License is located at
|
|
6
|
-
*
|
|
7
|
-
* http://aws.amazon.com/apache2.0/
|
|
8
|
-
*
|
|
9
|
-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
10
|
-
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
11
|
-
* and limitations under the License.
|
|
12
|
-
*/
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
13
3
|
import { __assign, __awaiter, __generator, __read } from "tslib";
|
|
14
4
|
import { isUsernamePasswordOpts, isCognitoHostedOpts, isFederatedSignInOptions, isFederatedSignInOptionsCustom, hasCustomState, } from './types';
|
|
15
5
|
import { Amplify, ConsoleLogger as Logger, Credentials, Hub, StorageHelper, browserOrNode, parseAWSExports, UniversalStorage, urlSafeDecode, } from '@aws-amplify/core';
|
|
@@ -48,6 +38,7 @@ var AuthClass = /** @class */ (function () {
|
|
|
48
38
|
this.user = null;
|
|
49
39
|
this.oAuthFlowInProgress = false;
|
|
50
40
|
this.autoSignInInitiated = false;
|
|
41
|
+
this.inflightSessionPromise = null;
|
|
51
42
|
this.Credentials = Credentials;
|
|
52
43
|
this.wrapRefreshSessionCallback = function (callback) {
|
|
53
44
|
var wrapped = function (error, data) {
|
|
@@ -1384,10 +1375,10 @@ var AuthClass = /** @class */ (function () {
|
|
|
1384
1375
|
return new Promise(function (res, rej) {
|
|
1385
1376
|
_this._storageSync
|
|
1386
1377
|
.then(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1387
|
-
var user, clientMetadata;
|
|
1378
|
+
var user, session, bypassCache, clientMetadata, _a, scope, err_1;
|
|
1388
1379
|
var _this = this;
|
|
1389
|
-
return __generator(this, function (
|
|
1390
|
-
switch (
|
|
1380
|
+
return __generator(this, function (_b) {
|
|
1381
|
+
switch (_b.label) {
|
|
1391
1382
|
case 0:
|
|
1392
1383
|
if (!this.isOAuthInProgress()) return [3 /*break*/, 2];
|
|
1393
1384
|
logger.debug('OAuth signIn in progress, waiting for resolution...');
|
|
@@ -1411,8 +1402,8 @@ var AuthClass = /** @class */ (function () {
|
|
|
1411
1402
|
}
|
|
1412
1403
|
})];
|
|
1413
1404
|
case 1:
|
|
1414
|
-
|
|
1415
|
-
|
|
1405
|
+
_b.sent();
|
|
1406
|
+
_b.label = 2;
|
|
1416
1407
|
case 2:
|
|
1417
1408
|
user = this.userPool.getCurrentUser();
|
|
1418
1409
|
if (!user) {
|
|
@@ -1420,96 +1411,77 @@ var AuthClass = /** @class */ (function () {
|
|
|
1420
1411
|
rej('No current user');
|
|
1421
1412
|
return [2 /*return*/];
|
|
1422
1413
|
}
|
|
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:
|
|
1423
1427
|
clientMetadata = this._config.clientMetadata;
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
return [
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
logger.debug('getting user data failed', err);
|
|
1466
|
-
if (!this.isSessionInvalid(err)) return [3 /*break*/, 5];
|
|
1467
|
-
_a.label = 1;
|
|
1468
|
-
case 1:
|
|
1469
|
-
_a.trys.push([1, 3, , 4]);
|
|
1470
|
-
return [4 /*yield*/, this.cleanUpInvalidSession(user)];
|
|
1471
|
-
case 2:
|
|
1472
|
-
_a.sent();
|
|
1473
|
-
return [3 /*break*/, 4];
|
|
1474
|
-
case 3:
|
|
1475
|
-
cleanUpError_6 = _a.sent();
|
|
1476
|
-
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_6.message));
|
|
1477
|
-
return [2 /*return*/];
|
|
1478
|
-
case 4:
|
|
1479
|
-
rej(err);
|
|
1480
|
-
return [3 /*break*/, 6];
|
|
1481
|
-
case 5:
|
|
1482
|
-
res(user);
|
|
1483
|
-
_a.label = 6;
|
|
1484
|
-
case 6: return [2 /*return*/];
|
|
1485
|
-
case 7:
|
|
1486
|
-
preferredMFA = data.PreferredMfaSetting || 'NOMFA';
|
|
1487
|
-
attributeList = [];
|
|
1488
|
-
for (i = 0; i < data.UserAttributes.length; i++) {
|
|
1489
|
-
attribute = {
|
|
1490
|
-
Name: data.UserAttributes[i].Name,
|
|
1491
|
-
Value: data.UserAttributes[i].Value,
|
|
1492
|
-
};
|
|
1493
|
-
userAttribute = new CognitoUserAttribute(attribute);
|
|
1494
|
-
attributeList.push(userAttribute);
|
|
1495
|
-
}
|
|
1496
|
-
attributes = this.attributesToObject(attributeList);
|
|
1497
|
-
Object.assign(user, { attributes: attributes, preferredMFA: preferredMFA });
|
|
1498
|
-
return [2 /*return*/, res(user)];
|
|
1499
|
-
}
|
|
1500
|
-
});
|
|
1501
|
-
}); }, { bypassCache: bypassCache, clientMetadata: clientMetadata });
|
|
1502
|
-
}
|
|
1503
|
-
else {
|
|
1504
|
-
logger.debug("Unable to get the user data because the " + USER_ADMIN_SCOPE + " " +
|
|
1505
|
-
"is not in the scopes of the access token");
|
|
1428
|
+
_a = session.getAccessToken().decodePayload().scope, scope = _a === void 0 ? '' : _a;
|
|
1429
|
+
if (scope.split(' ').includes(USER_ADMIN_SCOPE)) {
|
|
1430
|
+
user.getUserData(function (err, data) { return __awaiter(_this, void 0, void 0, function () {
|
|
1431
|
+
var cleanUpError_5, preferredMFA, attributeList, i, attribute, userAttribute, attributes;
|
|
1432
|
+
return __generator(this, function (_a) {
|
|
1433
|
+
switch (_a.label) {
|
|
1434
|
+
case 0:
|
|
1435
|
+
if (!err) return [3 /*break*/, 7];
|
|
1436
|
+
logger.debug('getting user data failed', err);
|
|
1437
|
+
if (!this.isSessionInvalid(err)) return [3 /*break*/, 5];
|
|
1438
|
+
_a.label = 1;
|
|
1439
|
+
case 1:
|
|
1440
|
+
_a.trys.push([1, 3, , 4]);
|
|
1441
|
+
return [4 /*yield*/, this.cleanUpInvalidSession(user)];
|
|
1442
|
+
case 2:
|
|
1443
|
+
_a.sent();
|
|
1444
|
+
return [3 /*break*/, 4];
|
|
1445
|
+
case 3:
|
|
1446
|
+
cleanUpError_5 = _a.sent();
|
|
1447
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_5.message));
|
|
1448
|
+
return [2 /*return*/];
|
|
1449
|
+
case 4:
|
|
1450
|
+
rej(err);
|
|
1451
|
+
return [3 /*break*/, 6];
|
|
1452
|
+
case 5:
|
|
1453
|
+
res(user);
|
|
1454
|
+
_a.label = 6;
|
|
1455
|
+
case 6: return [2 /*return*/];
|
|
1456
|
+
case 7:
|
|
1457
|
+
preferredMFA = data.PreferredMfaSetting || 'NOMFA';
|
|
1458
|
+
attributeList = [];
|
|
1459
|
+
for (i = 0; i < data.UserAttributes.length; i++) {
|
|
1460
|
+
attribute = {
|
|
1461
|
+
Name: data.UserAttributes[i].Name,
|
|
1462
|
+
Value: data.UserAttributes[i].Value,
|
|
1463
|
+
};
|
|
1464
|
+
userAttribute = new CognitoUserAttribute(attribute);
|
|
1465
|
+
attributeList.push(userAttribute);
|
|
1466
|
+
}
|
|
1467
|
+
attributes = this.attributesToObject(attributeList);
|
|
1468
|
+
Object.assign(user, { attributes: attributes, preferredMFA: preferredMFA });
|
|
1506
1469
|
return [2 /*return*/, res(user)];
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1470
|
+
}
|
|
1471
|
+
});
|
|
1472
|
+
}); }, { bypassCache: bypassCache, clientMetadata: clientMetadata });
|
|
1473
|
+
}
|
|
1474
|
+
else {
|
|
1475
|
+
logger.debug("Unable to get the user data because the " + USER_ADMIN_SCOPE + " " +
|
|
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*/];
|
|
1513
1485
|
}
|
|
1514
1486
|
});
|
|
1515
1487
|
}); })
|
|
@@ -1619,50 +1591,73 @@ var AuthClass = /** @class */ (function () {
|
|
|
1619
1591
|
});
|
|
1620
1592
|
});
|
|
1621
1593
|
};
|
|
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
|
+
};
|
|
1622
1654
|
/**
|
|
1623
1655
|
* Get the corresponding user session
|
|
1624
1656
|
* @param {Object} user - The CognitoUser object
|
|
1625
1657
|
* @return - A promise resolves to the session
|
|
1626
1658
|
*/
|
|
1627
1659
|
AuthClass.prototype.userSession = function (user) {
|
|
1628
|
-
|
|
1629
|
-
if (!user) {
|
|
1630
|
-
logger.debug('the user is null');
|
|
1631
|
-
return this.rejectAuthError(AuthErrorTypes.NoUserSession);
|
|
1632
|
-
}
|
|
1633
|
-
var clientMetadata = this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
|
|
1634
|
-
return new Promise(function (res, rej) {
|
|
1635
|
-
logger.debug('Getting the session from this user:', user);
|
|
1636
|
-
user.getSession(function (err, session) { return __awaiter(_this, void 0, void 0, function () {
|
|
1637
|
-
var cleanUpError_7;
|
|
1638
|
-
return __generator(this, function (_a) {
|
|
1639
|
-
switch (_a.label) {
|
|
1640
|
-
case 0:
|
|
1641
|
-
if (!err) return [3 /*break*/, 5];
|
|
1642
|
-
logger.debug('Failed to get the session from user', user);
|
|
1643
|
-
if (!this.isSessionInvalid(err)) return [3 /*break*/, 4];
|
|
1644
|
-
_a.label = 1;
|
|
1645
|
-
case 1:
|
|
1646
|
-
_a.trys.push([1, 3, , 4]);
|
|
1647
|
-
return [4 /*yield*/, this.cleanUpInvalidSession(user)];
|
|
1648
|
-
case 2:
|
|
1649
|
-
_a.sent();
|
|
1650
|
-
return [3 /*break*/, 4];
|
|
1651
|
-
case 3:
|
|
1652
|
-
cleanUpError_7 = _a.sent();
|
|
1653
|
-
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_7.message));
|
|
1654
|
-
return [2 /*return*/];
|
|
1655
|
-
case 4:
|
|
1656
|
-
rej(err);
|
|
1657
|
-
return [2 /*return*/];
|
|
1658
|
-
case 5:
|
|
1659
|
-
logger.debug('Succeed to get the user session', session);
|
|
1660
|
-
res(session);
|
|
1661
|
-
return [2 /*return*/];
|
|
1662
|
-
}
|
|
1663
|
-
});
|
|
1664
|
-
}); }, { clientMetadata: clientMetadata });
|
|
1665
|
-
});
|
|
1660
|
+
return this._userSession(user);
|
|
1666
1661
|
};
|
|
1667
1662
|
/**
|
|
1668
1663
|
* Get authenticated credentials of current user.
|
|
@@ -1806,7 +1801,7 @@ var AuthClass = /** @class */ (function () {
|
|
|
1806
1801
|
// we must validate the user as an authenticated user by using getSession
|
|
1807
1802
|
var clientMetadata = _this._config.clientMetadata; // TODO: verify behavior if this is override during signIn
|
|
1808
1803
|
user.getSession(function (err, result) { return __awaiter(_this, void 0, void 0, function () {
|
|
1809
|
-
var
|
|
1804
|
+
var cleanUpError_7;
|
|
1810
1805
|
var _this = this;
|
|
1811
1806
|
return __generator(this, function (_a) {
|
|
1812
1807
|
switch (_a.label) {
|
|
@@ -1822,8 +1817,8 @@ var AuthClass = /** @class */ (function () {
|
|
|
1822
1817
|
_a.sent();
|
|
1823
1818
|
return [3 /*break*/, 4];
|
|
1824
1819
|
case 3:
|
|
1825
|
-
|
|
1826
|
-
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " +
|
|
1820
|
+
cleanUpError_7 = _a.sent();
|
|
1821
|
+
rej(new Error("Session is invalid due to: " + err.message + " and failed to clean up invalid session: " + cleanUpError_7.message));
|
|
1827
1822
|
return [2 /*return*/];
|
|
1828
1823
|
case 4: return [2 /*return*/, rej(err)];
|
|
1829
1824
|
case 5:
|
|
@@ -2047,7 +2042,7 @@ var AuthClass = /** @class */ (function () {
|
|
|
2047
2042
|
*/
|
|
2048
2043
|
AuthClass.prototype.currentUserInfo = function () {
|
|
2049
2044
|
return __awaiter(this, void 0, void 0, function () {
|
|
2050
|
-
var source, user, attributes, userAttrs, credentials, e_12, info,
|
|
2045
|
+
var source, user, attributes, userAttrs, credentials, e_12, info, err_2, user;
|
|
2051
2046
|
return __generator(this, function (_a) {
|
|
2052
2047
|
switch (_a.label) {
|
|
2053
2048
|
case 0:
|
|
@@ -2088,8 +2083,8 @@ var AuthClass = /** @class */ (function () {
|
|
|
2088
2083
|
};
|
|
2089
2084
|
return [2 /*return*/, info];
|
|
2090
2085
|
case 8:
|
|
2091
|
-
|
|
2092
|
-
logger.error('currentUserInfo error',
|
|
2086
|
+
err_2 = _a.sent();
|
|
2087
|
+
logger.error('currentUserInfo error', err_2);
|
|
2093
2088
|
return [2 /*return*/, {}];
|
|
2094
2089
|
case 9:
|
|
2095
2090
|
if (source === 'federated') {
|
|
@@ -2170,7 +2165,7 @@ var AuthClass = /** @class */ (function () {
|
|
|
2170
2165
|
*/
|
|
2171
2166
|
AuthClass.prototype._handleAuthResponse = function (URL) {
|
|
2172
2167
|
return __awaiter(this, void 0, void 0, function () {
|
|
2173
|
-
var currentUrl, hasCodeOrError, hasTokenOrError, _a, accessToken, idToken, refreshToken, state, session, credentials, isCustomStateIncluded, currentUser, customState,
|
|
2168
|
+
var currentUrl, hasCodeOrError, hasTokenOrError, _a, accessToken, idToken, refreshToken, state, session, credentials, isCustomStateIncluded, currentUser, customState, err_3;
|
|
2174
2169
|
return __generator(this, function (_b) {
|
|
2175
2170
|
switch (_b.label) {
|
|
2176
2171
|
case 0:
|
|
@@ -2243,16 +2238,16 @@ var AuthClass = /** @class */ (function () {
|
|
|
2243
2238
|
//#endregion
|
|
2244
2239
|
return [2 /*return*/, credentials];
|
|
2245
2240
|
case 6:
|
|
2246
|
-
|
|
2247
|
-
logger.debug('Error in cognito hosted auth response',
|
|
2241
|
+
err_3 = _b.sent();
|
|
2242
|
+
logger.debug('Error in cognito hosted auth response', err_3);
|
|
2248
2243
|
// Just like a successful handling of `?code`, replace the window history to "dispose" of the `code`.
|
|
2249
2244
|
// Otherwise, reloading the page will throw errors as the `code` has already been spent.
|
|
2250
2245
|
if (window && typeof window.history !== 'undefined') {
|
|
2251
2246
|
window.history.replaceState({}, null, this._config.oauth.redirectSignIn);
|
|
2252
2247
|
}
|
|
2253
|
-
dispatchAuthEvent('signIn_failure',
|
|
2254
|
-
dispatchAuthEvent('cognitoHostedUI_failure',
|
|
2255
|
-
dispatchAuthEvent('customState_failure',
|
|
2248
|
+
dispatchAuthEvent('signIn_failure', err_3, "The OAuth response flow failed");
|
|
2249
|
+
dispatchAuthEvent('cognitoHostedUI_failure', err_3, "A failure occurred when returning to the Cognito Hosted UI");
|
|
2250
|
+
dispatchAuthEvent('customState_failure', err_3, "A failure occurred when returning state");
|
|
2256
2251
|
return [3 /*break*/, 7];
|
|
2257
2252
|
case 7: return [3 /*break*/, 9];
|
|
2258
2253
|
case 8:
|