@azure/msal-common 11.0.0 → 12.0.0
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/dist/_virtual/_tslib.js +1 -1
- package/dist/account/AuthToken.js +1 -1
- package/dist/account/CcsCredential.js +1 -1
- package/dist/account/ClientInfo.js +1 -1
- package/dist/account/TokenClaims.d.ts +5 -0
- package/dist/account/TokenClaims.d.ts.map +1 -1
- package/dist/authority/Authority.js +1 -1
- package/dist/authority/AuthorityFactory.js +1 -1
- package/dist/authority/AuthorityMetadata.js +1 -1
- package/dist/authority/AuthorityOptions.js +1 -1
- package/dist/authority/AuthorityType.js +1 -1
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.js +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
- package/dist/authority/OpenIdConfigResponse.js +1 -1
- package/dist/authority/ProtocolMode.js +1 -1
- package/dist/authority/RegionDiscovery.js +1 -1
- package/dist/cache/CacheManager.d.ts +102 -51
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +414 -245
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.js +1 -1
- package/dist/cache/entities/AccountEntity.js +1 -1
- package/dist/cache/entities/AppMetadataEntity.js +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.js +1 -1
- package/dist/cache/entities/CacheRecord.js +1 -1
- package/dist/cache/entities/CredentialEntity.d.ts +0 -11
- package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
- package/dist/cache/entities/CredentialEntity.js +3 -42
- package/dist/cache/entities/CredentialEntity.js.map +1 -1
- package/dist/cache/entities/IdTokenEntity.js +1 -1
- package/dist/cache/entities/RefreshTokenEntity.js +1 -1
- package/dist/cache/entities/ServerTelemetryEntity.js +1 -1
- package/dist/cache/entities/ThrottlingEntity.js +1 -1
- package/dist/cache/interface/ICacheManager.d.ts +26 -17
- package/dist/cache/interface/ICacheManager.d.ts.map +1 -1
- package/dist/cache/persistence/TokenCacheContext.js +1 -1
- package/dist/cache/utils/CacheTypes.d.ts +9 -6
- package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.js +1 -1
- package/dist/client/BaseClient.js +1 -1
- package/dist/client/ClientCredentialClient.d.ts +0 -1
- package/dist/client/ClientCredentialClient.d.ts.map +1 -1
- package/dist/client/ClientCredentialClient.js +3 -5
- package/dist/client/ClientCredentialClient.js.map +1 -1
- package/dist/client/DeviceCodeClient.js +1 -1
- package/dist/client/OnBehalfOfClient.d.ts.map +1 -1
- package/dist/client/OnBehalfOfClient.js +6 -8
- package/dist/client/OnBehalfOfClient.js.map +1 -1
- package/dist/client/RefreshTokenClient.js +3 -3
- package/dist/client/RefreshTokenClient.js.map +1 -1
- package/dist/client/SilentFlowClient.js +2 -2
- package/dist/client/SilentFlowClient.js.map +1 -1
- package/dist/client/UsernamePasswordClient.js +1 -1
- package/dist/config/ClientConfiguration.d.ts.map +1 -1
- package/dist/config/ClientConfiguration.js +3 -3
- package/dist/config/ClientConfiguration.js.map +1 -1
- package/dist/crypto/ICrypto.js +1 -1
- package/dist/crypto/JoseHeader.js +1 -1
- package/dist/crypto/PopTokenGenerator.js +1 -1
- package/dist/error/AuthError.js +1 -1
- package/dist/error/ClientAuthError.js +1 -1
- package/dist/error/ClientConfigurationError.js +1 -1
- package/dist/error/InteractionRequiredAuthError.js +1 -1
- package/dist/error/JoseHeaderError.js +1 -1
- package/dist/error/ServerError.js +1 -1
- package/dist/index.cjs.js +576 -451
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/logger/Logger.js +1 -1
- package/dist/network/INetworkModule.js +1 -1
- package/dist/network/NetworkManager.js +1 -1
- package/dist/network/ThrottlingUtils.d.ts +1 -1
- package/dist/network/ThrottlingUtils.d.ts.map +1 -1
- package/dist/network/ThrottlingUtils.js +4 -4
- package/dist/network/ThrottlingUtils.js.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.js +2 -2
- package/dist/packageMetadata.js.map +1 -1
- package/dist/request/AuthenticationHeaderParser.js +1 -1
- package/dist/request/RequestParameterBuilder.js +1 -1
- package/dist/request/RequestValidator.js +1 -1
- package/dist/request/ScopeSet.d.ts +6 -0
- package/dist/request/ScopeSet.d.ts.map +1 -1
- package/dist/request/ScopeSet.js +17 -2
- package/dist/request/ScopeSet.js.map +1 -1
- package/dist/response/ResponseHandler.js +1 -1
- package/dist/telemetry/performance/PerformanceClient.js +1 -1
- package/dist/telemetry/performance/PerformanceEvent.js +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.js +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.js +1 -1
- package/dist/url/UrlString.js +1 -1
- package/dist/utils/Constants.d.ts +0 -15
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.js +2 -18
- package/dist/utils/Constants.js.map +1 -1
- package/dist/utils/ProtocolUtils.js +1 -1
- package/dist/utils/StringUtils.js +1 -1
- package/dist/utils/TimeUtils.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @azure/msal-common
|
|
1
|
+
/*! @azure/msal-common v12.0.0 2023-04-03 */
|
|
2
2
|
'use strict';
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -351,22 +351,6 @@ exports.CredentialType = void 0;
|
|
|
351
351
|
CredentialType["ACCESS_TOKEN_WITH_AUTH_SCHEME"] = "AccessToken_With_AuthScheme";
|
|
352
352
|
CredentialType["REFRESH_TOKEN"] = "RefreshToken";
|
|
353
353
|
})(exports.CredentialType || (exports.CredentialType = {}));
|
|
354
|
-
/**
|
|
355
|
-
* Credential Type stored in the cache
|
|
356
|
-
*/
|
|
357
|
-
exports.CacheSchemaType = void 0;
|
|
358
|
-
(function (CacheSchemaType) {
|
|
359
|
-
CacheSchemaType["ACCOUNT"] = "Account";
|
|
360
|
-
CacheSchemaType["CREDENTIAL"] = "Credential";
|
|
361
|
-
CacheSchemaType["ID_TOKEN"] = "IdToken";
|
|
362
|
-
CacheSchemaType["ACCESS_TOKEN"] = "AccessToken";
|
|
363
|
-
CacheSchemaType["REFRESH_TOKEN"] = "RefreshToken";
|
|
364
|
-
CacheSchemaType["APP_METADATA"] = "AppMetadata";
|
|
365
|
-
CacheSchemaType["TEMPORARY"] = "TempCache";
|
|
366
|
-
CacheSchemaType["TELEMETRY"] = "Telemetry";
|
|
367
|
-
CacheSchemaType["UNDEFINED"] = "Undefined";
|
|
368
|
-
CacheSchemaType["THROTTLING"] = "Throttling";
|
|
369
|
-
})(exports.CacheSchemaType || (exports.CacheSchemaType = {}));
|
|
370
354
|
/**
|
|
371
355
|
* Combine all cache types
|
|
372
356
|
*/
|
|
@@ -1443,7 +1427,7 @@ var Logger = /** @class */ (function () {
|
|
|
1443
1427
|
|
|
1444
1428
|
/* eslint-disable header/header */
|
|
1445
1429
|
var name = "@azure/msal-common";
|
|
1446
|
-
var version = "
|
|
1430
|
+
var version = "12.0.0";
|
|
1447
1431
|
|
|
1448
1432
|
/*
|
|
1449
1433
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -1465,181 +1449,6 @@ exports.AzureCloudInstance = void 0;
|
|
|
1465
1449
|
AzureCloudInstance["AzureUsGovernment"] = "https://login.microsoftonline.us";
|
|
1466
1450
|
})(exports.AzureCloudInstance || (exports.AzureCloudInstance = {}));
|
|
1467
1451
|
|
|
1468
|
-
/*
|
|
1469
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
1470
|
-
* Licensed under the MIT License.
|
|
1471
|
-
*/
|
|
1472
|
-
/**
|
|
1473
|
-
* Base type for credentials to be stored in the cache: eg: ACCESS_TOKEN, ID_TOKEN etc
|
|
1474
|
-
*
|
|
1475
|
-
* Key:Value Schema:
|
|
1476
|
-
*
|
|
1477
|
-
* Key: <home_account_id*>-<environment>-<credential_type>-<client_id>-<realm*>-<target*>-<requestedClaims*>-<scheme*>
|
|
1478
|
-
*
|
|
1479
|
-
* Value Schema:
|
|
1480
|
-
* {
|
|
1481
|
-
* homeAccountId: home account identifier for the auth scheme,
|
|
1482
|
-
* environment: entity that issued the token, represented as a full host
|
|
1483
|
-
* credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
|
|
1484
|
-
* clientId: client ID of the application
|
|
1485
|
-
* secret: Actual credential as a string
|
|
1486
|
-
* familyId: Family ID identifier, usually only used for refresh tokens
|
|
1487
|
-
* realm: Full tenant or organizational identifier that the account belongs to
|
|
1488
|
-
* target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
|
|
1489
|
-
* tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)
|
|
1490
|
-
* requestedClaimsHash: Matches the SHA 256 hash of the claims object included in the token request
|
|
1491
|
-
* userAssertionHash: Matches the SHA 256 hash of the obo_assertion for the OBO flow
|
|
1492
|
-
* }
|
|
1493
|
-
*/
|
|
1494
|
-
var CredentialEntity = /** @class */ (function () {
|
|
1495
|
-
function CredentialEntity() {
|
|
1496
|
-
}
|
|
1497
|
-
/**
|
|
1498
|
-
* Initializes a map with credential {CredentialType} regular expressions.
|
|
1499
|
-
*/
|
|
1500
|
-
CredentialEntity._initRegex = function () {
|
|
1501
|
-
var separator = Separators.CACHE_KEY_SEPARATOR;
|
|
1502
|
-
CredentialEntity.credentialRegexMap = new Map();
|
|
1503
|
-
for (var _i = 0, _a = Object.keys(exports.CredentialType); _i < _a.length; _i++) {
|
|
1504
|
-
var credKey = _a[_i];
|
|
1505
|
-
var credVal = exports.CredentialType[credKey].toLowerCase();
|
|
1506
|
-
try {
|
|
1507
|
-
// Verify credential type is preceded by a valid host name (environment) using lookbehind
|
|
1508
|
-
CredentialEntity.credentialRegexMap.set(exports.CredentialType[credKey], new RegExp("(?<=" + separator + CredentialEntity.credentialDomainRegex + ")" + separator + credVal + separator));
|
|
1509
|
-
}
|
|
1510
|
-
catch (err) {
|
|
1511
|
-
// Lookbehind is not supported (Safari or older versions of IE) - removing it
|
|
1512
|
-
CredentialEntity.credentialRegexMap.set(exports.CredentialType[credKey], new RegExp("" + separator + CredentialEntity.credentialDomainRegex + separator + credVal + separator));
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
};
|
|
1516
|
-
/**
|
|
1517
|
-
* Generate Account Id key component as per the schema: <home_account_id>-<environment>
|
|
1518
|
-
*/
|
|
1519
|
-
CredentialEntity.prototype.generateAccountId = function () {
|
|
1520
|
-
return CredentialEntity.generateAccountIdForCacheKey(this.homeAccountId, this.environment);
|
|
1521
|
-
};
|
|
1522
|
-
/**
|
|
1523
|
-
* Generate Credential Id key component as per the schema: <credential_type>-<client_id>-<realm>
|
|
1524
|
-
*/
|
|
1525
|
-
CredentialEntity.prototype.generateCredentialId = function () {
|
|
1526
|
-
return CredentialEntity.generateCredentialIdForCacheKey(this.credentialType, this.clientId, this.realm, this.familyId);
|
|
1527
|
-
};
|
|
1528
|
-
/**
|
|
1529
|
-
* Generate target key component as per schema: <target>
|
|
1530
|
-
*/
|
|
1531
|
-
CredentialEntity.prototype.generateTarget = function () {
|
|
1532
|
-
return CredentialEntity.generateTargetForCacheKey(this.target);
|
|
1533
|
-
};
|
|
1534
|
-
/**
|
|
1535
|
-
* generates credential key
|
|
1536
|
-
*/
|
|
1537
|
-
CredentialEntity.prototype.generateCredentialKey = function () {
|
|
1538
|
-
return CredentialEntity.generateCredentialCacheKey(this.homeAccountId, this.environment, this.credentialType, this.clientId, this.realm, this.target, this.familyId, this.tokenType, this.requestedClaimsHash);
|
|
1539
|
-
};
|
|
1540
|
-
/**
|
|
1541
|
-
* returns the type of the cache (in this case credential)
|
|
1542
|
-
*/
|
|
1543
|
-
CredentialEntity.prototype.generateType = function () {
|
|
1544
|
-
switch (this.credentialType) {
|
|
1545
|
-
case exports.CredentialType.ID_TOKEN:
|
|
1546
|
-
return exports.CacheType.ID_TOKEN;
|
|
1547
|
-
case exports.CredentialType.ACCESS_TOKEN:
|
|
1548
|
-
case exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
|
|
1549
|
-
return exports.CacheType.ACCESS_TOKEN;
|
|
1550
|
-
case exports.CredentialType.REFRESH_TOKEN:
|
|
1551
|
-
return exports.CacheType.REFRESH_TOKEN;
|
|
1552
|
-
default: {
|
|
1553
|
-
throw ClientAuthError.createUnexpectedCredentialTypeError();
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
};
|
|
1557
|
-
/**
|
|
1558
|
-
* helper function to return `CredentialType`
|
|
1559
|
-
* @param key
|
|
1560
|
-
*/
|
|
1561
|
-
CredentialEntity.getCredentialType = function (key) {
|
|
1562
|
-
var _a;
|
|
1563
|
-
for (var _i = 0, _b = Object.keys(exports.CredentialType); _i < _b.length; _i++) {
|
|
1564
|
-
var credKey = _b[_i];
|
|
1565
|
-
if ((_a = this.credentialRegexMap.get(exports.CredentialType[credKey])) === null || _a === void 0 ? void 0 : _a.test(key.toLowerCase())) {
|
|
1566
|
-
return exports.CredentialType[credKey];
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
return Constants.NOT_DEFINED;
|
|
1570
|
-
};
|
|
1571
|
-
/**
|
|
1572
|
-
* generates credential key
|
|
1573
|
-
* <home_account_id*>-\<environment>-<credential_type>-<client_id>-<realm\*>-<target\*>-<scheme\*>
|
|
1574
|
-
*/
|
|
1575
|
-
CredentialEntity.generateCredentialCacheKey = function (homeAccountId, environment, credentialType, clientId, realm, target, familyId, tokenType, requestedClaimsHash) {
|
|
1576
|
-
var credentialKey = [
|
|
1577
|
-
this.generateAccountIdForCacheKey(homeAccountId, environment),
|
|
1578
|
-
this.generateCredentialIdForCacheKey(credentialType, clientId, realm, familyId),
|
|
1579
|
-
this.generateTargetForCacheKey(target),
|
|
1580
|
-
this.generateClaimsHashForCacheKey(requestedClaimsHash),
|
|
1581
|
-
this.generateSchemeForCacheKey(tokenType)
|
|
1582
|
-
];
|
|
1583
|
-
return credentialKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
|
|
1584
|
-
};
|
|
1585
|
-
/**
|
|
1586
|
-
* generates Account Id for keys
|
|
1587
|
-
* @param homeAccountId
|
|
1588
|
-
* @param environment
|
|
1589
|
-
*/
|
|
1590
|
-
CredentialEntity.generateAccountIdForCacheKey = function (homeAccountId, environment) {
|
|
1591
|
-
var accountId = [homeAccountId, environment];
|
|
1592
|
-
return accountId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
|
|
1593
|
-
};
|
|
1594
|
-
/**
|
|
1595
|
-
* Generates Credential Id for keys
|
|
1596
|
-
* @param credentialType
|
|
1597
|
-
* @param realm
|
|
1598
|
-
* @param clientId
|
|
1599
|
-
* @param familyId
|
|
1600
|
-
*/
|
|
1601
|
-
CredentialEntity.generateCredentialIdForCacheKey = function (credentialType, clientId, realm, familyId) {
|
|
1602
|
-
var clientOrFamilyId = credentialType === exports.CredentialType.REFRESH_TOKEN
|
|
1603
|
-
? familyId || clientId
|
|
1604
|
-
: clientId;
|
|
1605
|
-
var credentialId = [
|
|
1606
|
-
credentialType,
|
|
1607
|
-
clientOrFamilyId,
|
|
1608
|
-
realm || Constants.EMPTY_STRING,
|
|
1609
|
-
];
|
|
1610
|
-
return credentialId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
|
|
1611
|
-
};
|
|
1612
|
-
/**
|
|
1613
|
-
* Generate target key component as per schema: <target>
|
|
1614
|
-
*/
|
|
1615
|
-
CredentialEntity.generateTargetForCacheKey = function (scopes) {
|
|
1616
|
-
return (scopes || Constants.EMPTY_STRING).toLowerCase();
|
|
1617
|
-
};
|
|
1618
|
-
/**
|
|
1619
|
-
* Generate requested claims key component as per schema: <requestedClaims>
|
|
1620
|
-
*/
|
|
1621
|
-
CredentialEntity.generateClaimsHashForCacheKey = function (requestedClaimsHash) {
|
|
1622
|
-
return (requestedClaimsHash || Constants.EMPTY_STRING).toLowerCase();
|
|
1623
|
-
};
|
|
1624
|
-
/**
|
|
1625
|
-
* Generate scheme key componenet as per schema: <scheme>
|
|
1626
|
-
*/
|
|
1627
|
-
CredentialEntity.generateSchemeForCacheKey = function (tokenType) {
|
|
1628
|
-
/*
|
|
1629
|
-
* PoP Tokens and SSH certs include scheme in cache key
|
|
1630
|
-
* Cast to lowercase to handle "bearer" from ADFS
|
|
1631
|
-
*/
|
|
1632
|
-
return (tokenType && tokenType.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : Constants.EMPTY_STRING;
|
|
1633
|
-
};
|
|
1634
|
-
/*
|
|
1635
|
-
* Match host names like "login.microsoftonline.com", "https://accounts.google.com:4000", https://localhost:5000,
|
|
1636
|
-
* "login.microsoftonline.com/common", "login.microsoftonline.com:4000/common", etc
|
|
1637
|
-
*/
|
|
1638
|
-
CredentialEntity.credentialDomainRegex = "(https?:\\/\\/)?((([\\w-]+\\.)*([\\w-]{1,63})(\\.(\\w{2,63})))|(localhost))(\\:[0-9]{4,5})?(\\/[\\w-]+)?";
|
|
1639
|
-
return CredentialEntity;
|
|
1640
|
-
}());
|
|
1641
|
-
CredentialEntity._initRegex();
|
|
1642
|
-
|
|
1643
1452
|
/*
|
|
1644
1453
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
1645
1454
|
* Licensed under the MIT License.
|
|
@@ -1924,6 +1733,21 @@ var ScopeSet = /** @class */ (function () {
|
|
|
1924
1733
|
var inputScopes = scopeString.split(" ");
|
|
1925
1734
|
return new ScopeSet(inputScopes);
|
|
1926
1735
|
};
|
|
1736
|
+
/**
|
|
1737
|
+
* Creates the set of scopes to search for in cache lookups
|
|
1738
|
+
* @param inputScopeString
|
|
1739
|
+
* @returns
|
|
1740
|
+
*/
|
|
1741
|
+
ScopeSet.createSearchScopes = function (inputScopeString) {
|
|
1742
|
+
var scopeSet = new ScopeSet(inputScopeString);
|
|
1743
|
+
if (!scopeSet.containsOnlyOIDCScopes()) {
|
|
1744
|
+
scopeSet.removeOIDCScopes();
|
|
1745
|
+
}
|
|
1746
|
+
else {
|
|
1747
|
+
scopeSet.removeScope(Constants.OFFLINE_ACCESS_SCOPE);
|
|
1748
|
+
}
|
|
1749
|
+
return scopeSet;
|
|
1750
|
+
};
|
|
1927
1751
|
/**
|
|
1928
1752
|
* Used to validate the scopes input parameter requested by the developer.
|
|
1929
1753
|
* @param {Array<string>} inputScopes - Developer requested permissions. Not all scopes are guaranteed to be included in the access token returned.
|
|
@@ -2420,35 +2244,59 @@ var AuthToken = /** @class */ (function () {
|
|
|
2420
2244
|
* Interface class which implement cache storage functions used by MSAL to perform validity checks, and store tokens.
|
|
2421
2245
|
*/
|
|
2422
2246
|
var CacheManager = /** @class */ (function () {
|
|
2423
|
-
function CacheManager(clientId, cryptoImpl) {
|
|
2247
|
+
function CacheManager(clientId, cryptoImpl, logger) {
|
|
2424
2248
|
this.clientId = clientId;
|
|
2425
2249
|
this.cryptoImpl = cryptoImpl;
|
|
2250
|
+
this.commonLogger = logger.clone(name, version);
|
|
2426
2251
|
}
|
|
2427
2252
|
/**
|
|
2428
2253
|
* Returns all accounts in cache
|
|
2429
2254
|
*/
|
|
2430
2255
|
CacheManager.prototype.getAllAccounts = function () {
|
|
2431
2256
|
var _this = this;
|
|
2432
|
-
var
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2257
|
+
var allAccountKeys = this.getAccountKeys();
|
|
2258
|
+
if (allAccountKeys.length < 1) {
|
|
2259
|
+
return [];
|
|
2260
|
+
}
|
|
2261
|
+
var accountEntities = allAccountKeys.reduce(function (accounts, key) {
|
|
2262
|
+
var entity = _this.getAccount(key);
|
|
2263
|
+
if (!entity) {
|
|
2264
|
+
return accounts;
|
|
2265
|
+
}
|
|
2266
|
+
accounts.push(entity);
|
|
2267
|
+
return accounts;
|
|
2268
|
+
}, []);
|
|
2269
|
+
if (accountEntities.length < 1) {
|
|
2436
2270
|
return [];
|
|
2437
2271
|
}
|
|
2438
2272
|
else {
|
|
2439
|
-
var allAccounts =
|
|
2440
|
-
|
|
2441
|
-
var accountInfo = accountEntity.getAccountInfo();
|
|
2442
|
-
var idToken = _this.readIdTokenFromCache(_this.clientId, accountInfo);
|
|
2443
|
-
if (idToken && !accountInfo.idTokenClaims) {
|
|
2444
|
-
accountInfo.idToken = idToken.secret;
|
|
2445
|
-
accountInfo.idTokenClaims = new AuthToken(idToken.secret, _this.cryptoImpl).claims;
|
|
2446
|
-
}
|
|
2447
|
-
return accountInfo;
|
|
2273
|
+
var allAccounts = accountEntities.map(function (accountEntity) {
|
|
2274
|
+
return _this.getAccountInfoFromEntity(accountEntity);
|
|
2448
2275
|
});
|
|
2449
2276
|
return allAccounts;
|
|
2450
2277
|
}
|
|
2451
2278
|
};
|
|
2279
|
+
/**
|
|
2280
|
+
* Gets accountInfo object based on provided filters
|
|
2281
|
+
*/
|
|
2282
|
+
CacheManager.prototype.getAccountInfoFilteredBy = function (accountFilter) {
|
|
2283
|
+
var allAccounts = this.getAccountsFilteredBy(accountFilter);
|
|
2284
|
+
if (allAccounts.length > 0) {
|
|
2285
|
+
return this.getAccountInfoFromEntity(allAccounts[0]);
|
|
2286
|
+
}
|
|
2287
|
+
else {
|
|
2288
|
+
return null;
|
|
2289
|
+
}
|
|
2290
|
+
};
|
|
2291
|
+
CacheManager.prototype.getAccountInfoFromEntity = function (accountEntity) {
|
|
2292
|
+
var accountInfo = accountEntity.getAccountInfo();
|
|
2293
|
+
var idToken = this.getIdToken(accountInfo);
|
|
2294
|
+
if (idToken) {
|
|
2295
|
+
accountInfo.idToken = idToken.secret;
|
|
2296
|
+
accountInfo.idTokenClaims = new AuthToken(idToken.secret, this.cryptoImpl).claims;
|
|
2297
|
+
}
|
|
2298
|
+
return accountInfo;
|
|
2299
|
+
};
|
|
2452
2300
|
/**
|
|
2453
2301
|
* saves a cache record
|
|
2454
2302
|
* @param cacheRecord
|
|
@@ -2490,12 +2338,12 @@ var CacheManager = /** @class */ (function () {
|
|
|
2490
2338
|
*/
|
|
2491
2339
|
CacheManager.prototype.saveAccessToken = function (credential) {
|
|
2492
2340
|
return __awaiter(this, void 0, void 0, function () {
|
|
2493
|
-
var
|
|
2341
|
+
var accessTokenFilter, tokenKeys, currentScopes, removedAccessTokens;
|
|
2494
2342
|
var _this = this;
|
|
2495
2343
|
return __generator(this, function (_a) {
|
|
2496
2344
|
switch (_a.label) {
|
|
2497
2345
|
case 0:
|
|
2498
|
-
|
|
2346
|
+
accessTokenFilter = {
|
|
2499
2347
|
clientId: credential.clientId,
|
|
2500
2348
|
credentialType: credential.credentialType,
|
|
2501
2349
|
environment: credential.environment,
|
|
@@ -2503,22 +2351,25 @@ var CacheManager = /** @class */ (function () {
|
|
|
2503
2351
|
realm: credential.realm,
|
|
2504
2352
|
tokenType: credential.tokenType,
|
|
2505
2353
|
requestedClaimsHash: credential.requestedClaimsHash
|
|
2506
|
-
}
|
|
2354
|
+
};
|
|
2355
|
+
tokenKeys = this.getTokenKeys();
|
|
2507
2356
|
currentScopes = ScopeSet.fromString(credential.target);
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2357
|
+
removedAccessTokens = [];
|
|
2358
|
+
tokenKeys.accessToken.forEach(function (key) {
|
|
2359
|
+
if (!_this.accessTokenKeyMatchesFilter(key, accessTokenFilter, false)) {
|
|
2360
|
+
return;
|
|
2361
|
+
}
|
|
2362
|
+
var tokenEntity = _this.getAccessTokenCredential(key);
|
|
2363
|
+
if (tokenEntity && _this.credentialMatchesFilter(tokenEntity, accessTokenFilter)) {
|
|
2364
|
+
var tokenScopeSet = ScopeSet.fromString(tokenEntity.target);
|
|
2365
|
+
if (tokenScopeSet.intersectingScopeSets(currentScopes)) {
|
|
2366
|
+
removedAccessTokens.push(_this.removeAccessToken(key));
|
|
2367
|
+
}
|
|
2515
2368
|
}
|
|
2516
2369
|
});
|
|
2517
|
-
return [4 /*yield*/, Promise.all(
|
|
2370
|
+
return [4 /*yield*/, Promise.all(removedAccessTokens)];
|
|
2518
2371
|
case 1:
|
|
2519
2372
|
_a.sent();
|
|
2520
|
-
_a.label = 2;
|
|
2521
|
-
case 2:
|
|
2522
2373
|
this.setAccessTokenCredential(credential);
|
|
2523
2374
|
return [2 /*return*/];
|
|
2524
2375
|
}
|
|
@@ -2533,149 +2384,151 @@ var CacheManager = /** @class */ (function () {
|
|
|
2533
2384
|
* @param realm
|
|
2534
2385
|
*/
|
|
2535
2386
|
CacheManager.prototype.getAccountsFilteredBy = function (accountFilter) {
|
|
2536
|
-
return this.getAccountsFilteredByInternal(accountFilter ? accountFilter.homeAccountId : Constants.EMPTY_STRING, accountFilter ? accountFilter.environment : Constants.EMPTY_STRING, accountFilter ? accountFilter.realm : Constants.EMPTY_STRING, accountFilter ? accountFilter.nativeAccountId : Constants.EMPTY_STRING);
|
|
2537
|
-
};
|
|
2538
|
-
/**
|
|
2539
|
-
* retrieve accounts matching all provided filters; if no filter is set, get all accounts
|
|
2540
|
-
* not checking for casing as keys are all generated in lower case, remember to convert to lower case if object properties are compared
|
|
2541
|
-
* @param homeAccountId
|
|
2542
|
-
* @param environment
|
|
2543
|
-
* @param realm
|
|
2544
|
-
*/
|
|
2545
|
-
CacheManager.prototype.getAccountsFilteredByInternal = function (homeAccountId, environment, realm, nativeAccountId) {
|
|
2546
2387
|
var _this = this;
|
|
2547
|
-
var
|
|
2548
|
-
var matchingAccounts =
|
|
2549
|
-
|
|
2388
|
+
var allAccountKeys = this.getAccountKeys();
|
|
2389
|
+
var matchingAccounts = [];
|
|
2390
|
+
allAccountKeys.forEach(function (cacheKey) {
|
|
2391
|
+
if (!_this.isAccountKey(cacheKey, accountFilter.homeAccountId, accountFilter.realm)) {
|
|
2392
|
+
// Don't parse value if the key doesn't match the account filters
|
|
2393
|
+
return;
|
|
2394
|
+
}
|
|
2550
2395
|
var entity = _this.getAccount(cacheKey);
|
|
2551
2396
|
if (!entity) {
|
|
2552
2397
|
return;
|
|
2553
2398
|
}
|
|
2554
|
-
if (!!homeAccountId && !_this.matchHomeAccountId(entity, homeAccountId)) {
|
|
2399
|
+
if (!!accountFilter.homeAccountId && !_this.matchHomeAccountId(entity, accountFilter.homeAccountId)) {
|
|
2555
2400
|
return;
|
|
2556
2401
|
}
|
|
2557
|
-
if (!!
|
|
2402
|
+
if (!!accountFilter.localAccountId && !_this.matchLocalAccountId(entity, accountFilter.localAccountId)) {
|
|
2403
|
+
return;
|
|
2404
|
+
}
|
|
2405
|
+
if (!!accountFilter.username && !_this.matchUsername(entity, accountFilter.username)) {
|
|
2558
2406
|
return;
|
|
2559
2407
|
}
|
|
2560
|
-
if (!!
|
|
2408
|
+
if (!!accountFilter.environment && !_this.matchEnvironment(entity, accountFilter.environment)) {
|
|
2561
2409
|
return;
|
|
2562
2410
|
}
|
|
2563
|
-
if (!!
|
|
2411
|
+
if (!!accountFilter.realm && !_this.matchRealm(entity, accountFilter.realm)) {
|
|
2564
2412
|
return;
|
|
2565
2413
|
}
|
|
2566
|
-
|
|
2414
|
+
if (!!accountFilter.nativeAccountId && !_this.matchNativeAccountId(entity, accountFilter.nativeAccountId)) {
|
|
2415
|
+
return;
|
|
2416
|
+
}
|
|
2417
|
+
matchingAccounts.push(entity);
|
|
2567
2418
|
});
|
|
2568
2419
|
return matchingAccounts;
|
|
2569
2420
|
};
|
|
2570
2421
|
/**
|
|
2571
|
-
*
|
|
2422
|
+
* Returns true if the given key matches our account key schema. Also matches homeAccountId and/or tenantId if provided
|
|
2423
|
+
* @param key
|
|
2572
2424
|
* @param homeAccountId
|
|
2573
|
-
* @param
|
|
2574
|
-
* @
|
|
2575
|
-
* @param clientId
|
|
2576
|
-
* @param realm
|
|
2577
|
-
* @param target
|
|
2425
|
+
* @param tenantId
|
|
2426
|
+
* @returns
|
|
2578
2427
|
*/
|
|
2579
|
-
CacheManager.prototype.
|
|
2580
|
-
|
|
2428
|
+
CacheManager.prototype.isAccountKey = function (key, homeAccountId, tenantId) {
|
|
2429
|
+
if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 3) {
|
|
2430
|
+
// Account cache keys contain 3 items separated by '-' (each item may also contain '-')
|
|
2431
|
+
return false;
|
|
2432
|
+
}
|
|
2433
|
+
if (homeAccountId && !key.toLowerCase().includes(homeAccountId.toLowerCase())) {
|
|
2434
|
+
return false;
|
|
2435
|
+
}
|
|
2436
|
+
if (tenantId && !key.toLowerCase().includes(tenantId.toLowerCase())) {
|
|
2437
|
+
return false;
|
|
2438
|
+
}
|
|
2439
|
+
// Do not check environment as aliasing can cause false negatives
|
|
2440
|
+
return true;
|
|
2581
2441
|
};
|
|
2582
2442
|
/**
|
|
2583
|
-
*
|
|
2584
|
-
* @param
|
|
2585
|
-
* @param environment
|
|
2586
|
-
* @param credentialType
|
|
2587
|
-
* @param clientId
|
|
2588
|
-
* @param realm
|
|
2589
|
-
* @param target
|
|
2590
|
-
* @param userAssertionHash
|
|
2591
|
-
* @param tokenType
|
|
2443
|
+
* Returns true if the given key matches our credential key schema.
|
|
2444
|
+
* @param key
|
|
2592
2445
|
*/
|
|
2593
|
-
CacheManager.prototype.
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
//
|
|
2608
|
-
var
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
if (!!userAssertionHash && !_this.matchUserAssertionHash(entity, userAssertionHash)) {
|
|
2613
|
-
return;
|
|
2614
|
-
}
|
|
2615
|
-
/*
|
|
2616
|
-
* homeAccountId can undefined, and we want to filter out cached items that have a homeAccountId of ""
|
|
2617
|
-
* because we don't want a client_credential request to return a cached token that has a homeAccountId
|
|
2618
|
-
*/
|
|
2619
|
-
if ((typeof homeAccountId === "string") && !_this.matchHomeAccountId(entity, homeAccountId)) {
|
|
2620
|
-
return;
|
|
2621
|
-
}
|
|
2622
|
-
if (!!environment && !_this.matchEnvironment(entity, environment)) {
|
|
2623
|
-
return;
|
|
2624
|
-
}
|
|
2625
|
-
if (!!realm && !_this.matchRealm(entity, realm)) {
|
|
2626
|
-
return;
|
|
2627
|
-
}
|
|
2628
|
-
if (!!credentialType && !_this.matchCredentialType(entity, credentialType)) {
|
|
2629
|
-
return;
|
|
2630
|
-
}
|
|
2631
|
-
if (!!clientId && !_this.matchClientId(entity, clientId)) {
|
|
2632
|
-
return;
|
|
2446
|
+
CacheManager.prototype.isCredentialKey = function (key) {
|
|
2447
|
+
if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 6) {
|
|
2448
|
+
// Credential cache keys contain 6 items separated by '-' (each item may also contain '-')
|
|
2449
|
+
return false;
|
|
2450
|
+
}
|
|
2451
|
+
var lowerCaseKey = key.toLowerCase();
|
|
2452
|
+
// Credential keys must indicate what credential type they represent
|
|
2453
|
+
if (lowerCaseKey.indexOf(exports.CredentialType.ID_TOKEN.toLowerCase()) === -1 &&
|
|
2454
|
+
lowerCaseKey.indexOf(exports.CredentialType.ACCESS_TOKEN.toLowerCase()) === -1 &&
|
|
2455
|
+
lowerCaseKey.indexOf(exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()) === -1 &&
|
|
2456
|
+
lowerCaseKey.indexOf(exports.CredentialType.REFRESH_TOKEN.toLowerCase()) === -1) {
|
|
2457
|
+
return false;
|
|
2458
|
+
}
|
|
2459
|
+
if (lowerCaseKey.indexOf(exports.CredentialType.REFRESH_TOKEN.toLowerCase()) > -1) {
|
|
2460
|
+
// Refresh tokens must contain the client id or family id
|
|
2461
|
+
var clientIdValidation = "" + exports.CredentialType.REFRESH_TOKEN + Separators.CACHE_KEY_SEPARATOR + this.clientId + Separators.CACHE_KEY_SEPARATOR;
|
|
2462
|
+
var familyIdValidation = "" + exports.CredentialType.REFRESH_TOKEN + Separators.CACHE_KEY_SEPARATOR + THE_FAMILY_ID + Separators.CACHE_KEY_SEPARATOR;
|
|
2463
|
+
if (lowerCaseKey.indexOf(clientIdValidation.toLowerCase()) === -1 && lowerCaseKey.indexOf(familyIdValidation.toLowerCase()) === -1) {
|
|
2464
|
+
return false;
|
|
2633
2465
|
}
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2466
|
+
}
|
|
2467
|
+
else if (lowerCaseKey.indexOf(this.clientId.toLowerCase()) === -1) {
|
|
2468
|
+
// Tokens must contain the clientId
|
|
2469
|
+
return false;
|
|
2470
|
+
}
|
|
2471
|
+
return true;
|
|
2472
|
+
};
|
|
2473
|
+
/**
|
|
2474
|
+
* Returns whether or not the given credential entity matches the filter
|
|
2475
|
+
* @param entity
|
|
2476
|
+
* @param filter
|
|
2477
|
+
* @returns
|
|
2478
|
+
*/
|
|
2479
|
+
CacheManager.prototype.credentialMatchesFilter = function (entity, filter) {
|
|
2480
|
+
if (!!filter.clientId && !this.matchClientId(entity, filter.clientId)) {
|
|
2481
|
+
return false;
|
|
2482
|
+
}
|
|
2483
|
+
if (!!filter.userAssertionHash && !this.matchUserAssertionHash(entity, filter.userAssertionHash)) {
|
|
2484
|
+
return false;
|
|
2485
|
+
}
|
|
2486
|
+
/*
|
|
2487
|
+
* homeAccountId can be undefined, and we want to filter out cached items that have a homeAccountId of ""
|
|
2488
|
+
* because we don't want a client_credential request to return a cached token that has a homeAccountId
|
|
2489
|
+
*/
|
|
2490
|
+
if ((typeof filter.homeAccountId === "string") && !this.matchHomeAccountId(entity, filter.homeAccountId)) {
|
|
2491
|
+
return false;
|
|
2492
|
+
}
|
|
2493
|
+
if (!!filter.environment && !this.matchEnvironment(entity, filter.environment)) {
|
|
2494
|
+
return false;
|
|
2495
|
+
}
|
|
2496
|
+
if (!!filter.realm && !this.matchRealm(entity, filter.realm)) {
|
|
2497
|
+
return false;
|
|
2498
|
+
}
|
|
2499
|
+
if (!!filter.credentialType && !this.matchCredentialType(entity, filter.credentialType)) {
|
|
2500
|
+
return false;
|
|
2501
|
+
}
|
|
2502
|
+
if (!!filter.familyId && !this.matchFamilyId(entity, filter.familyId)) {
|
|
2503
|
+
return false;
|
|
2504
|
+
}
|
|
2505
|
+
/*
|
|
2506
|
+
* idTokens do not have "target", target specific refreshTokens do exist for some types of authentication
|
|
2507
|
+
* Resource specific refresh tokens case will be added when the support is deemed necessary
|
|
2508
|
+
*/
|
|
2509
|
+
if (!!filter.target && !this.matchTarget(entity, filter.target)) {
|
|
2510
|
+
return false;
|
|
2511
|
+
}
|
|
2512
|
+
// If request OR cached entity has requested Claims Hash, check if they match
|
|
2513
|
+
if (filter.requestedClaimsHash || entity.requestedClaimsHash) {
|
|
2514
|
+
// Don't match if either is undefined or they are different
|
|
2515
|
+
if (entity.requestedClaimsHash !== filter.requestedClaimsHash) {
|
|
2516
|
+
return false;
|
|
2643
2517
|
}
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
}
|
|
2518
|
+
}
|
|
2519
|
+
// Access Token with Auth Scheme specific matching
|
|
2520
|
+
if (entity.credentialType === exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME) {
|
|
2521
|
+
if (!!filter.tokenType && !this.matchTokenType(entity, filter.tokenType)) {
|
|
2522
|
+
return false;
|
|
2650
2523
|
}
|
|
2651
|
-
//
|
|
2652
|
-
if (
|
|
2653
|
-
if (
|
|
2654
|
-
return;
|
|
2655
|
-
}
|
|
2656
|
-
// KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
|
|
2657
|
-
if (tokenType === exports.AuthenticationScheme.SSH) {
|
|
2658
|
-
if (keyId && !_this.matchKeyId(entity, keyId)) {
|
|
2659
|
-
return;
|
|
2660
|
-
}
|
|
2524
|
+
// KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
|
|
2525
|
+
if (filter.tokenType === exports.AuthenticationScheme.SSH) {
|
|
2526
|
+
if (filter.keyId && !this.matchKeyId(entity, filter.keyId)) {
|
|
2527
|
+
return false;
|
|
2661
2528
|
}
|
|
2662
2529
|
}
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
switch (credType) {
|
|
2666
|
-
case exports.CredentialType.ID_TOKEN:
|
|
2667
|
-
matchingCredentials.idTokens[updatedCacheKey] = entity;
|
|
2668
|
-
break;
|
|
2669
|
-
case exports.CredentialType.ACCESS_TOKEN:
|
|
2670
|
-
case exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
|
|
2671
|
-
matchingCredentials.accessTokens[updatedCacheKey] = entity;
|
|
2672
|
-
break;
|
|
2673
|
-
case exports.CredentialType.REFRESH_TOKEN:
|
|
2674
|
-
matchingCredentials.refreshTokens[updatedCacheKey] = entity;
|
|
2675
|
-
break;
|
|
2676
|
-
}
|
|
2677
|
-
});
|
|
2678
|
-
return matchingCredentials;
|
|
2530
|
+
}
|
|
2531
|
+
return true;
|
|
2679
2532
|
};
|
|
2680
2533
|
/**
|
|
2681
2534
|
* retrieve appMetadata matching all provided filters; if no filter is set, get all appMetadata
|
|
@@ -2743,30 +2596,26 @@ var CacheManager = /** @class */ (function () {
|
|
|
2743
2596
|
*/
|
|
2744
2597
|
CacheManager.prototype.removeAllAccounts = function () {
|
|
2745
2598
|
return __awaiter(this, void 0, void 0, function () {
|
|
2746
|
-
var
|
|
2599
|
+
var allAccountKeys, removedAccounts;
|
|
2747
2600
|
var _this = this;
|
|
2748
2601
|
return __generator(this, function (_a) {
|
|
2749
2602
|
switch (_a.label) {
|
|
2750
2603
|
case 0:
|
|
2751
|
-
|
|
2604
|
+
allAccountKeys = this.getAccountKeys();
|
|
2752
2605
|
removedAccounts = [];
|
|
2753
|
-
|
|
2754
|
-
var entity = _this.getAccount(cacheKey);
|
|
2755
|
-
if (!entity) {
|
|
2756
|
-
return;
|
|
2757
|
-
}
|
|
2606
|
+
allAccountKeys.forEach(function (cacheKey) {
|
|
2758
2607
|
removedAccounts.push(_this.removeAccount(cacheKey));
|
|
2759
2608
|
});
|
|
2760
2609
|
return [4 /*yield*/, Promise.all(removedAccounts)];
|
|
2761
2610
|
case 1:
|
|
2762
2611
|
_a.sent();
|
|
2763
|
-
return [2 /*return
|
|
2612
|
+
return [2 /*return*/];
|
|
2764
2613
|
}
|
|
2765
2614
|
});
|
|
2766
2615
|
});
|
|
2767
2616
|
};
|
|
2768
2617
|
/**
|
|
2769
|
-
*
|
|
2618
|
+
* Removes the account and related tokens for a given account key
|
|
2770
2619
|
* @param account
|
|
2771
2620
|
*/
|
|
2772
2621
|
CacheManager.prototype.removeAccount = function (accountKey) {
|
|
@@ -2780,7 +2629,10 @@ var CacheManager = /** @class */ (function () {
|
|
|
2780
2629
|
throw ClientAuthError.createNoAccountFoundError();
|
|
2781
2630
|
}
|
|
2782
2631
|
return [4 /*yield*/, this.removeAccountContext(account)];
|
|
2783
|
-
case 1:
|
|
2632
|
+
case 1:
|
|
2633
|
+
_a.sent();
|
|
2634
|
+
this.removeItem(accountKey);
|
|
2635
|
+
return [2 /*return*/];
|
|
2784
2636
|
}
|
|
2785
2637
|
});
|
|
2786
2638
|
});
|
|
@@ -2791,29 +2643,33 @@ var CacheManager = /** @class */ (function () {
|
|
|
2791
2643
|
*/
|
|
2792
2644
|
CacheManager.prototype.removeAccountContext = function (account) {
|
|
2793
2645
|
return __awaiter(this, void 0, void 0, function () {
|
|
2794
|
-
var
|
|
2646
|
+
var allTokenKeys, accountId, removedCredentials;
|
|
2795
2647
|
var _this = this;
|
|
2796
2648
|
return __generator(this, function (_a) {
|
|
2797
2649
|
switch (_a.label) {
|
|
2798
2650
|
case 0:
|
|
2799
|
-
|
|
2651
|
+
allTokenKeys = this.getTokenKeys();
|
|
2800
2652
|
accountId = account.generateAccountId();
|
|
2801
2653
|
removedCredentials = [];
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
if (credType === Constants.NOT_DEFINED) {
|
|
2806
|
-
return;
|
|
2654
|
+
allTokenKeys.idToken.forEach(function (key) {
|
|
2655
|
+
if (key.indexOf(accountId) === 0) {
|
|
2656
|
+
_this.removeIdToken(key);
|
|
2807
2657
|
}
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2658
|
+
});
|
|
2659
|
+
allTokenKeys.accessToken.forEach(function (key) {
|
|
2660
|
+
if (key.indexOf(accountId) === 0) {
|
|
2661
|
+
removedCredentials.push(_this.removeAccessToken(key));
|
|
2662
|
+
}
|
|
2663
|
+
});
|
|
2664
|
+
allTokenKeys.refreshToken.forEach(function (key) {
|
|
2665
|
+
if (key.indexOf(accountId) === 0) {
|
|
2666
|
+
_this.removeRefreshToken(key);
|
|
2811
2667
|
}
|
|
2812
2668
|
});
|
|
2813
2669
|
return [4 /*yield*/, Promise.all(removedCredentials)];
|
|
2814
2670
|
case 1:
|
|
2815
2671
|
_a.sent();
|
|
2816
|
-
return [2 /*return
|
|
2672
|
+
return [2 /*return*/];
|
|
2817
2673
|
}
|
|
2818
2674
|
});
|
|
2819
2675
|
});
|
|
@@ -2822,13 +2678,16 @@ var CacheManager = /** @class */ (function () {
|
|
|
2822
2678
|
* returns a boolean if the given credential is removed
|
|
2823
2679
|
* @param credential
|
|
2824
2680
|
*/
|
|
2825
|
-
CacheManager.prototype.
|
|
2681
|
+
CacheManager.prototype.removeAccessToken = function (key) {
|
|
2826
2682
|
return __awaiter(this, void 0, void 0, function () {
|
|
2827
|
-
var
|
|
2683
|
+
var credential, accessTokenWithAuthSchemeEntity, kid;
|
|
2828
2684
|
return __generator(this, function (_a) {
|
|
2829
2685
|
switch (_a.label) {
|
|
2830
2686
|
case 0:
|
|
2831
|
-
|
|
2687
|
+
credential = this.getAccessTokenCredential(key);
|
|
2688
|
+
if (!credential) {
|
|
2689
|
+
return [2 /*return*/];
|
|
2690
|
+
}
|
|
2832
2691
|
if (!(credential.credentialType.toLowerCase() === exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase())) return [3 /*break*/, 4];
|
|
2833
2692
|
if (!(credential.tokenType === exports.AuthenticationScheme.POP)) return [3 /*break*/, 4];
|
|
2834
2693
|
accessTokenWithAuthSchemeEntity = credential;
|
|
@@ -2844,7 +2703,7 @@ var CacheManager = /** @class */ (function () {
|
|
|
2844
2703
|
case 3:
|
|
2845
2704
|
_a.sent();
|
|
2846
2705
|
throw ClientAuthError.createBindingKeyNotRemovedError();
|
|
2847
|
-
case 4: return [2 /*return*/, this.removeItem(key
|
|
2706
|
+
case 4: return [2 /*return*/, this.removeItem(key)];
|
|
2848
2707
|
}
|
|
2849
2708
|
});
|
|
2850
2709
|
});
|
|
@@ -2857,7 +2716,7 @@ var CacheManager = /** @class */ (function () {
|
|
|
2857
2716
|
var allCacheKeys = this.getKeys();
|
|
2858
2717
|
allCacheKeys.forEach(function (cacheKey) {
|
|
2859
2718
|
if (_this.isAppMetadata(cacheKey)) {
|
|
2860
|
-
_this.removeItem(cacheKey
|
|
2719
|
+
_this.removeItem(cacheKey);
|
|
2861
2720
|
}
|
|
2862
2721
|
});
|
|
2863
2722
|
return true;
|
|
@@ -2870,12 +2729,13 @@ var CacheManager = /** @class */ (function () {
|
|
|
2870
2729
|
* @param environment
|
|
2871
2730
|
* @param authScheme
|
|
2872
2731
|
*/
|
|
2873
|
-
CacheManager.prototype.readCacheRecord = function (account,
|
|
2732
|
+
CacheManager.prototype.readCacheRecord = function (account, request, environment) {
|
|
2733
|
+
var tokenKeys = this.getTokenKeys();
|
|
2874
2734
|
var cachedAccount = this.readAccountFromCache(account);
|
|
2875
|
-
var cachedIdToken = this.
|
|
2876
|
-
var cachedAccessToken = this.
|
|
2877
|
-
var cachedRefreshToken = this.
|
|
2878
|
-
var cachedAppMetadata = this.readAppMetadataFromCache(environment
|
|
2735
|
+
var cachedIdToken = this.getIdToken(account, tokenKeys);
|
|
2736
|
+
var cachedAccessToken = this.getAccessToken(account, request, tokenKeys);
|
|
2737
|
+
var cachedRefreshToken = this.getRefreshToken(account, false, tokenKeys);
|
|
2738
|
+
var cachedAppMetadata = this.readAppMetadataFromCache(environment);
|
|
2879
2739
|
if (cachedAccount && cachedIdToken) {
|
|
2880
2740
|
cachedAccount.idTokenClaims = new AuthToken(cachedIdToken.secret, this.cryptoImpl).claims;
|
|
2881
2741
|
}
|
|
@@ -2895,51 +2755,83 @@ var CacheManager = /** @class */ (function () {
|
|
|
2895
2755
|
var accountKey = AccountEntity.generateAccountCacheKey(account);
|
|
2896
2756
|
return this.getAccount(accountKey);
|
|
2897
2757
|
};
|
|
2898
|
-
/**
|
|
2899
|
-
* Retrieve AccountEntity from cache
|
|
2900
|
-
* @param nativeAccountId
|
|
2901
|
-
* @returns AccountEntity or Null
|
|
2902
|
-
*/
|
|
2903
|
-
CacheManager.prototype.readAccountFromCacheWithNativeAccountId = function (nativeAccountId) {
|
|
2904
|
-
// fetch account from memory
|
|
2905
|
-
var accountFilter = {
|
|
2906
|
-
nativeAccountId: nativeAccountId
|
|
2907
|
-
};
|
|
2908
|
-
var accountCache = this.getAccountsFilteredBy(accountFilter);
|
|
2909
|
-
var accounts = Object.keys(accountCache).map(function (key) { return accountCache[key]; });
|
|
2910
|
-
if (accounts.length < 1) {
|
|
2911
|
-
return null;
|
|
2912
|
-
}
|
|
2913
|
-
else if (accounts.length > 1) {
|
|
2914
|
-
throw ClientAuthError.createMultipleMatchingAccountsInCacheError();
|
|
2915
|
-
}
|
|
2916
|
-
return accounts[0];
|
|
2917
|
-
};
|
|
2918
2758
|
/**
|
|
2919
2759
|
* Retrieve IdTokenEntity from cache
|
|
2920
2760
|
* @param clientId
|
|
2921
2761
|
* @param account
|
|
2922
2762
|
* @param inputRealm
|
|
2923
2763
|
*/
|
|
2924
|
-
CacheManager.prototype.
|
|
2764
|
+
CacheManager.prototype.getIdToken = function (account, tokenKeys) {
|
|
2765
|
+
this.commonLogger.trace("CacheManager - getIdToken called");
|
|
2925
2766
|
var idTokenFilter = {
|
|
2926
2767
|
homeAccountId: account.homeAccountId,
|
|
2927
2768
|
environment: account.environment,
|
|
2928
2769
|
credentialType: exports.CredentialType.ID_TOKEN,
|
|
2929
|
-
clientId: clientId,
|
|
2770
|
+
clientId: this.clientId,
|
|
2930
2771
|
realm: account.tenantId,
|
|
2931
2772
|
};
|
|
2932
|
-
var
|
|
2933
|
-
var idTokens = Object.keys(credentialCache.idTokens).map(function (key) { return credentialCache.idTokens[key]; });
|
|
2773
|
+
var idTokens = this.getIdTokensByFilter(idTokenFilter, tokenKeys);
|
|
2934
2774
|
var numIdTokens = idTokens.length;
|
|
2935
2775
|
if (numIdTokens < 1) {
|
|
2776
|
+
this.commonLogger.info("CacheManager:getIdToken - No token found");
|
|
2936
2777
|
return null;
|
|
2937
2778
|
}
|
|
2938
2779
|
else if (numIdTokens > 1) {
|
|
2939
2780
|
throw ClientAuthError.createMultipleMatchingTokensInCacheError();
|
|
2940
2781
|
}
|
|
2782
|
+
this.commonLogger.info("CacheManager:getIdToken - Returning id token");
|
|
2941
2783
|
return idTokens[0];
|
|
2942
2784
|
};
|
|
2785
|
+
/**
|
|
2786
|
+
* Gets all idTokens matching the given filter
|
|
2787
|
+
* @param filter
|
|
2788
|
+
* @returns
|
|
2789
|
+
*/
|
|
2790
|
+
CacheManager.prototype.getIdTokensByFilter = function (filter, tokenKeys) {
|
|
2791
|
+
var _this = this;
|
|
2792
|
+
var idTokenKeys = tokenKeys && tokenKeys.idToken || this.getTokenKeys().idToken;
|
|
2793
|
+
var idTokens = [];
|
|
2794
|
+
idTokenKeys.forEach(function (key) {
|
|
2795
|
+
if (!_this.idTokenKeyMatchesFilter(key, __assign({ clientId: _this.clientId }, filter))) {
|
|
2796
|
+
return;
|
|
2797
|
+
}
|
|
2798
|
+
var idToken = _this.getIdTokenCredential(key);
|
|
2799
|
+
if (idToken && _this.credentialMatchesFilter(idToken, filter)) {
|
|
2800
|
+
idTokens.push(idToken);
|
|
2801
|
+
}
|
|
2802
|
+
});
|
|
2803
|
+
return idTokens;
|
|
2804
|
+
};
|
|
2805
|
+
/**
|
|
2806
|
+
* Validate the cache key against filter before retrieving and parsing cache value
|
|
2807
|
+
* @param key
|
|
2808
|
+
* @param filter
|
|
2809
|
+
* @returns
|
|
2810
|
+
*/
|
|
2811
|
+
CacheManager.prototype.idTokenKeyMatchesFilter = function (inputKey, filter) {
|
|
2812
|
+
var key = inputKey.toLowerCase();
|
|
2813
|
+
if (filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {
|
|
2814
|
+
return false;
|
|
2815
|
+
}
|
|
2816
|
+
if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
|
|
2817
|
+
return false;
|
|
2818
|
+
}
|
|
2819
|
+
return true;
|
|
2820
|
+
};
|
|
2821
|
+
/**
|
|
2822
|
+
* Removes idToken from the cache
|
|
2823
|
+
* @param key
|
|
2824
|
+
*/
|
|
2825
|
+
CacheManager.prototype.removeIdToken = function (key) {
|
|
2826
|
+
this.removeItem(key);
|
|
2827
|
+
};
|
|
2828
|
+
/**
|
|
2829
|
+
* Removes refresh token from the cache
|
|
2830
|
+
* @param key
|
|
2831
|
+
*/
|
|
2832
|
+
CacheManager.prototype.removeRefreshToken = function (key) {
|
|
2833
|
+
this.removeItem(key);
|
|
2834
|
+
};
|
|
2943
2835
|
/**
|
|
2944
2836
|
* Retrieve AccessTokenEntity from cache
|
|
2945
2837
|
* @param clientId
|
|
@@ -2947,8 +2839,10 @@ var CacheManager = /** @class */ (function () {
|
|
|
2947
2839
|
* @param scopes
|
|
2948
2840
|
* @param authScheme
|
|
2949
2841
|
*/
|
|
2950
|
-
CacheManager.prototype.
|
|
2951
|
-
var
|
|
2842
|
+
CacheManager.prototype.getAccessToken = function (account, request, tokenKeys) {
|
|
2843
|
+
var _this = this;
|
|
2844
|
+
this.commonLogger.trace("CacheManager - getAccessToken called");
|
|
2845
|
+
var scopes = ScopeSet.createSearchScopes(request.scopes);
|
|
2952
2846
|
var authScheme = request.authenticationScheme || exports.AuthenticationScheme.BEARER;
|
|
2953
2847
|
/*
|
|
2954
2848
|
* Distinguish between Bearer and PoP/SSH token cache types
|
|
@@ -2959,55 +2853,156 @@ var CacheManager = /** @class */ (function () {
|
|
|
2959
2853
|
homeAccountId: account.homeAccountId,
|
|
2960
2854
|
environment: account.environment,
|
|
2961
2855
|
credentialType: credentialType,
|
|
2962
|
-
clientId: clientId,
|
|
2856
|
+
clientId: this.clientId,
|
|
2963
2857
|
realm: account.tenantId,
|
|
2964
|
-
target: scopes
|
|
2858
|
+
target: scopes,
|
|
2965
2859
|
tokenType: authScheme,
|
|
2966
2860
|
keyId: request.sshKid,
|
|
2967
2861
|
requestedClaimsHash: request.requestedClaimsHash,
|
|
2968
2862
|
};
|
|
2969
|
-
var
|
|
2970
|
-
var accessTokens =
|
|
2863
|
+
var accessTokenKeys = tokenKeys && tokenKeys.accessToken || this.getTokenKeys().accessToken;
|
|
2864
|
+
var accessTokens = [];
|
|
2865
|
+
accessTokenKeys.forEach(function (key) {
|
|
2866
|
+
// Validate key
|
|
2867
|
+
if (_this.accessTokenKeyMatchesFilter(key, accessTokenFilter, true)) {
|
|
2868
|
+
var accessToken = _this.getAccessTokenCredential(key);
|
|
2869
|
+
// Validate value
|
|
2870
|
+
if (accessToken && _this.credentialMatchesFilter(accessToken, accessTokenFilter)) {
|
|
2871
|
+
accessTokens.push(accessToken);
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
});
|
|
2971
2875
|
var numAccessTokens = accessTokens.length;
|
|
2972
2876
|
if (numAccessTokens < 1) {
|
|
2877
|
+
this.commonLogger.info("CacheManager:getAccessToken - No token found");
|
|
2973
2878
|
return null;
|
|
2974
2879
|
}
|
|
2975
2880
|
else if (numAccessTokens > 1) {
|
|
2976
2881
|
throw ClientAuthError.createMultipleMatchingTokensInCacheError();
|
|
2977
2882
|
}
|
|
2883
|
+
this.commonLogger.info("CacheManager:getAccessToken - Returning access token");
|
|
2978
2884
|
return accessTokens[0];
|
|
2979
2885
|
};
|
|
2886
|
+
/**
|
|
2887
|
+
* Validate the cache key against filter before retrieving and parsing cache value
|
|
2888
|
+
* @param key
|
|
2889
|
+
* @param filter
|
|
2890
|
+
* @param keyMustContainAllScopes
|
|
2891
|
+
* @returns
|
|
2892
|
+
*/
|
|
2893
|
+
CacheManager.prototype.accessTokenKeyMatchesFilter = function (inputKey, filter, keyMustContainAllScopes) {
|
|
2894
|
+
var key = inputKey.toLowerCase();
|
|
2895
|
+
if (filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {
|
|
2896
|
+
return false;
|
|
2897
|
+
}
|
|
2898
|
+
if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
|
|
2899
|
+
return false;
|
|
2900
|
+
}
|
|
2901
|
+
if (filter.realm && key.indexOf(filter.realm.toLowerCase()) === -1) {
|
|
2902
|
+
return false;
|
|
2903
|
+
}
|
|
2904
|
+
if (filter.requestedClaimsHash && key.indexOf(filter.requestedClaimsHash.toLowerCase()) === -1) {
|
|
2905
|
+
return false;
|
|
2906
|
+
}
|
|
2907
|
+
if (filter.target) {
|
|
2908
|
+
var scopes = filter.target.asArray();
|
|
2909
|
+
for (var i = 0; i < scopes.length; i++) {
|
|
2910
|
+
if (keyMustContainAllScopes && !key.includes(scopes[i].toLowerCase())) {
|
|
2911
|
+
// When performing a cache lookup a missing scope would be a cache miss
|
|
2912
|
+
return false;
|
|
2913
|
+
}
|
|
2914
|
+
else if (!keyMustContainAllScopes && key.includes(scopes[i].toLowerCase())) {
|
|
2915
|
+
// When performing a cache write, any token with a subset of requested scopes should be replaced
|
|
2916
|
+
return true;
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
return true;
|
|
2921
|
+
};
|
|
2922
|
+
/**
|
|
2923
|
+
* Gets all access tokens matching the filter
|
|
2924
|
+
* @param filter
|
|
2925
|
+
* @returns
|
|
2926
|
+
*/
|
|
2927
|
+
CacheManager.prototype.getAccessTokensByFilter = function (filter) {
|
|
2928
|
+
var _this = this;
|
|
2929
|
+
var tokenKeys = this.getTokenKeys();
|
|
2930
|
+
var accessTokens = [];
|
|
2931
|
+
tokenKeys.accessToken.forEach(function (key) {
|
|
2932
|
+
if (!_this.accessTokenKeyMatchesFilter(key, filter, true)) {
|
|
2933
|
+
return;
|
|
2934
|
+
}
|
|
2935
|
+
var accessToken = _this.getAccessTokenCredential(key);
|
|
2936
|
+
if (accessToken && _this.credentialMatchesFilter(accessToken, filter)) {
|
|
2937
|
+
accessTokens.push(accessToken);
|
|
2938
|
+
}
|
|
2939
|
+
});
|
|
2940
|
+
return accessTokens;
|
|
2941
|
+
};
|
|
2980
2942
|
/**
|
|
2981
2943
|
* Helper to retrieve the appropriate refresh token from cache
|
|
2982
2944
|
* @param clientId
|
|
2983
2945
|
* @param account
|
|
2984
2946
|
* @param familyRT
|
|
2985
2947
|
*/
|
|
2986
|
-
CacheManager.prototype.
|
|
2948
|
+
CacheManager.prototype.getRefreshToken = function (account, familyRT, tokenKeys) {
|
|
2949
|
+
var _this = this;
|
|
2950
|
+
this.commonLogger.trace("CacheManager - getRefreshToken called");
|
|
2987
2951
|
var id = familyRT ? THE_FAMILY_ID : undefined;
|
|
2988
2952
|
var refreshTokenFilter = {
|
|
2989
2953
|
homeAccountId: account.homeAccountId,
|
|
2990
2954
|
environment: account.environment,
|
|
2991
2955
|
credentialType: exports.CredentialType.REFRESH_TOKEN,
|
|
2992
|
-
clientId: clientId,
|
|
2956
|
+
clientId: this.clientId,
|
|
2993
2957
|
familyId: id,
|
|
2994
2958
|
};
|
|
2995
|
-
var
|
|
2996
|
-
var refreshTokens =
|
|
2959
|
+
var refreshTokenKeys = tokenKeys && tokenKeys.refreshToken || this.getTokenKeys().refreshToken;
|
|
2960
|
+
var refreshTokens = [];
|
|
2961
|
+
refreshTokenKeys.forEach(function (key) {
|
|
2962
|
+
// Validate key
|
|
2963
|
+
if (_this.refreshTokenKeyMatchesFilter(key, refreshTokenFilter)) {
|
|
2964
|
+
var refreshToken = _this.getRefreshTokenCredential(key);
|
|
2965
|
+
// Validate value
|
|
2966
|
+
if (refreshToken && _this.credentialMatchesFilter(refreshToken, refreshTokenFilter)) {
|
|
2967
|
+
refreshTokens.push(refreshToken);
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
});
|
|
2997
2971
|
var numRefreshTokens = refreshTokens.length;
|
|
2998
2972
|
if (numRefreshTokens < 1) {
|
|
2973
|
+
this.commonLogger.info("CacheManager:getRefreshToken - No refresh token found.");
|
|
2999
2974
|
return null;
|
|
3000
2975
|
}
|
|
3001
2976
|
// address the else case after remove functions address environment aliases
|
|
2977
|
+
this.commonLogger.info("CacheManager:getRefreshToken - returning refresh token");
|
|
3002
2978
|
return refreshTokens[0];
|
|
3003
2979
|
};
|
|
2980
|
+
/**
|
|
2981
|
+
* Validate the cache key against filter before retrieving and parsing cache value
|
|
2982
|
+
* @param key
|
|
2983
|
+
* @param filter
|
|
2984
|
+
*/
|
|
2985
|
+
CacheManager.prototype.refreshTokenKeyMatchesFilter = function (inputKey, filter) {
|
|
2986
|
+
var key = inputKey.toLowerCase();
|
|
2987
|
+
if (filter.familyId && key.indexOf(filter.familyId.toLowerCase()) === -1) {
|
|
2988
|
+
return false;
|
|
2989
|
+
}
|
|
2990
|
+
// If familyId is used, clientId is not in the key
|
|
2991
|
+
if (!filter.familyId && filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {
|
|
2992
|
+
return false;
|
|
2993
|
+
}
|
|
2994
|
+
if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
|
|
2995
|
+
return false;
|
|
2996
|
+
}
|
|
2997
|
+
return true;
|
|
2998
|
+
};
|
|
3004
2999
|
/**
|
|
3005
3000
|
* Retrieve AppMetadataEntity from cache
|
|
3006
3001
|
*/
|
|
3007
|
-
CacheManager.prototype.readAppMetadataFromCache = function (environment
|
|
3002
|
+
CacheManager.prototype.readAppMetadataFromCache = function (environment) {
|
|
3008
3003
|
var appMetadataFilter = {
|
|
3009
3004
|
environment: environment,
|
|
3010
|
-
clientId: clientId,
|
|
3005
|
+
clientId: this.clientId,
|
|
3011
3006
|
};
|
|
3012
3007
|
var appMetadata = this.getAppMetadataFilteredBy(appMetadataFilter);
|
|
3013
3008
|
var appMetadataEntries = Object.keys(appMetadata).map(function (key) { return appMetadata[key]; });
|
|
@@ -3025,8 +3020,8 @@ var CacheManager = /** @class */ (function () {
|
|
|
3025
3020
|
* @param environment
|
|
3026
3021
|
* @param clientId
|
|
3027
3022
|
*/
|
|
3028
|
-
CacheManager.prototype.isAppMetadataFOCI = function (environment
|
|
3029
|
-
var appMetadata = this.readAppMetadataFromCache(environment
|
|
3023
|
+
CacheManager.prototype.isAppMetadataFOCI = function (environment) {
|
|
3024
|
+
var appMetadata = this.readAppMetadataFromCache(environment);
|
|
3030
3025
|
return !!(appMetadata && appMetadata.familyId === THE_FAMILY_ID);
|
|
3031
3026
|
};
|
|
3032
3027
|
/**
|
|
@@ -3037,6 +3032,24 @@ var CacheManager = /** @class */ (function () {
|
|
|
3037
3032
|
CacheManager.prototype.matchHomeAccountId = function (entity, homeAccountId) {
|
|
3038
3033
|
return !!((typeof entity.homeAccountId === "string") && (homeAccountId === entity.homeAccountId));
|
|
3039
3034
|
};
|
|
3035
|
+
/**
|
|
3036
|
+
* helper to match account ids
|
|
3037
|
+
* @param entity
|
|
3038
|
+
* @param localAccountId
|
|
3039
|
+
* @returns
|
|
3040
|
+
*/
|
|
3041
|
+
CacheManager.prototype.matchLocalAccountId = function (entity, localAccountId) {
|
|
3042
|
+
return !!((typeof entity.localAccountId === "string") && (localAccountId === entity.localAccountId));
|
|
3043
|
+
};
|
|
3044
|
+
/**
|
|
3045
|
+
* helper to match usernames
|
|
3046
|
+
* @param entity
|
|
3047
|
+
* @param username
|
|
3048
|
+
* @returns
|
|
3049
|
+
*/
|
|
3050
|
+
CacheManager.prototype.matchUsername = function (entity, username) {
|
|
3051
|
+
return !!((typeof entity.username === "string") && (username.toLowerCase() === entity.username.toLowerCase()));
|
|
3052
|
+
};
|
|
3040
3053
|
/**
|
|
3041
3054
|
* helper to match assertion
|
|
3042
3055
|
* @param value
|
|
@@ -3109,14 +3122,7 @@ var CacheManager = /** @class */ (function () {
|
|
|
3109
3122
|
return false;
|
|
3110
3123
|
}
|
|
3111
3124
|
var entityScopeSet = ScopeSet.fromString(entity.target);
|
|
3112
|
-
|
|
3113
|
-
if (!requestTargetScopeSet.containsOnlyOIDCScopes()) {
|
|
3114
|
-
requestTargetScopeSet.removeOIDCScopes(); // ignore OIDC scopes
|
|
3115
|
-
}
|
|
3116
|
-
else {
|
|
3117
|
-
requestTargetScopeSet.removeScope(Constants.OFFLINE_ACCESS_SCOPE);
|
|
3118
|
-
}
|
|
3119
|
-
return entityScopeSet.containsScopeSet(requestTargetScopeSet);
|
|
3125
|
+
return entityScopeSet.containsScopeSet(target);
|
|
3120
3126
|
};
|
|
3121
3127
|
/**
|
|
3122
3128
|
* Returns true if the credential's tokenType or Authentication Scheme matches the one in the request, false otherwise
|
|
@@ -3154,27 +3160,6 @@ var CacheManager = /** @class */ (function () {
|
|
|
3154
3160
|
CacheManager.prototype.generateAuthorityMetadataCacheKey = function (authority) {
|
|
3155
3161
|
return AUTHORITY_METADATA_CONSTANTS.CACHE_KEY + "-" + this.clientId + "-" + authority;
|
|
3156
3162
|
};
|
|
3157
|
-
/**
|
|
3158
|
-
* Returns the specific credential (IdToken/AccessToken/RefreshToken) from the cache
|
|
3159
|
-
* @param key
|
|
3160
|
-
* @param credType
|
|
3161
|
-
*/
|
|
3162
|
-
CacheManager.prototype.getSpecificCredential = function (key, credType) {
|
|
3163
|
-
switch (credType) {
|
|
3164
|
-
case exports.CredentialType.ID_TOKEN: {
|
|
3165
|
-
return this.getIdTokenCredential(key);
|
|
3166
|
-
}
|
|
3167
|
-
case exports.CredentialType.ACCESS_TOKEN:
|
|
3168
|
-
case exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME: {
|
|
3169
|
-
return this.getAccessTokenCredential(key);
|
|
3170
|
-
}
|
|
3171
|
-
case exports.CredentialType.REFRESH_TOKEN: {
|
|
3172
|
-
return this.getRefreshTokenCredential(key);
|
|
3173
|
-
}
|
|
3174
|
-
default:
|
|
3175
|
-
return null;
|
|
3176
|
-
}
|
|
3177
|
-
};
|
|
3178
3163
|
/**
|
|
3179
3164
|
* Helper to convert serialized data to object
|
|
3180
3165
|
* @param obj
|
|
@@ -3273,6 +3258,14 @@ var DefaultStorageClass = /** @class */ (function (_super) {
|
|
|
3273
3258
|
var notImplErr = "Storage interface - getKeys() has not been implemented for the cacheStorage interface.";
|
|
3274
3259
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
3275
3260
|
};
|
|
3261
|
+
DefaultStorageClass.prototype.getAccountKeys = function () {
|
|
3262
|
+
var notImplErr = "Storage interface - getAccountKeys() has not been implemented for the cacheStorage interface.";
|
|
3263
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
3264
|
+
};
|
|
3265
|
+
DefaultStorageClass.prototype.getTokenKeys = function () {
|
|
3266
|
+
var notImplErr = "Storage interface - getTokenKeys() has not been implemented for the cacheStorage interface.";
|
|
3267
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
3268
|
+
};
|
|
3276
3269
|
DefaultStorageClass.prototype.clear = function () {
|
|
3277
3270
|
return __awaiter(this, void 0, void 0, function () {
|
|
3278
3271
|
var notImplErr;
|
|
@@ -3361,7 +3354,7 @@ function buildClientConfiguration(_a) {
|
|
|
3361
3354
|
authOptions: buildAuthOptions(userAuthOptions),
|
|
3362
3355
|
systemOptions: __assign(__assign({}, DEFAULT_SYSTEM_OPTIONS), userSystemOptions),
|
|
3363
3356
|
loggerOptions: loggerOptions,
|
|
3364
|
-
storageInterface: storageImplementation || new DefaultStorageClass(userAuthOptions.clientId, DEFAULT_CRYPTO_IMPLEMENTATION),
|
|
3357
|
+
storageInterface: storageImplementation || new DefaultStorageClass(userAuthOptions.clientId, DEFAULT_CRYPTO_IMPLEMENTATION, new Logger(loggerOptions)),
|
|
3365
3358
|
networkInterface: networkImplementation || DEFAULT_NETWORK_IMPLEMENTATION,
|
|
3366
3359
|
cryptoInterface: cryptoImplementation || DEFAULT_CRYPTO_IMPLEMENTATION,
|
|
3367
3360
|
clientCredentials: clientCredentials || DEFAULT_CLIENT_CREDENTIALS,
|
|
@@ -3423,7 +3416,7 @@ var ThrottlingUtils = /** @class */ (function () {
|
|
|
3423
3416
|
var value = cacheManager.getThrottlingCache(key);
|
|
3424
3417
|
if (value) {
|
|
3425
3418
|
if (value.throttleTime < Date.now()) {
|
|
3426
|
-
cacheManager.removeItem(key
|
|
3419
|
+
cacheManager.removeItem(key);
|
|
3427
3420
|
return;
|
|
3428
3421
|
}
|
|
3429
3422
|
throw new ServerError(((_a = value.errorCodes) === null || _a === void 0 ? void 0 : _a.join(" ")) || Constants.EMPTY_STRING, value.errorMessage, value.subError);
|
|
@@ -3487,7 +3480,7 @@ var ThrottlingUtils = /** @class */ (function () {
|
|
|
3487
3480
|
sshKid: request.sshKid
|
|
3488
3481
|
};
|
|
3489
3482
|
var key = this.generateThrottlingStorageKey(thumbprint);
|
|
3490
|
-
|
|
3483
|
+
cacheManager.removeItem(key);
|
|
3491
3484
|
};
|
|
3492
3485
|
return ThrottlingUtils;
|
|
3493
3486
|
}());
|
|
@@ -4114,6 +4107,142 @@ var BaseClient = /** @class */ (function () {
|
|
|
4114
4107
|
return BaseClient;
|
|
4115
4108
|
}());
|
|
4116
4109
|
|
|
4110
|
+
/*
|
|
4111
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4112
|
+
* Licensed under the MIT License.
|
|
4113
|
+
*/
|
|
4114
|
+
/**
|
|
4115
|
+
* Base type for credentials to be stored in the cache: eg: ACCESS_TOKEN, ID_TOKEN etc
|
|
4116
|
+
*
|
|
4117
|
+
* Key:Value Schema:
|
|
4118
|
+
*
|
|
4119
|
+
* Key: <home_account_id*>-<environment>-<credential_type>-<client_id>-<realm*>-<target*>-<requestedClaims*>-<scheme*>
|
|
4120
|
+
*
|
|
4121
|
+
* Value Schema:
|
|
4122
|
+
* {
|
|
4123
|
+
* homeAccountId: home account identifier for the auth scheme,
|
|
4124
|
+
* environment: entity that issued the token, represented as a full host
|
|
4125
|
+
* credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
|
|
4126
|
+
* clientId: client ID of the application
|
|
4127
|
+
* secret: Actual credential as a string
|
|
4128
|
+
* familyId: Family ID identifier, usually only used for refresh tokens
|
|
4129
|
+
* realm: Full tenant or organizational identifier that the account belongs to
|
|
4130
|
+
* target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
|
|
4131
|
+
* tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)
|
|
4132
|
+
* requestedClaimsHash: Matches the SHA 256 hash of the claims object included in the token request
|
|
4133
|
+
* userAssertionHash: Matches the SHA 256 hash of the obo_assertion for the OBO flow
|
|
4134
|
+
* }
|
|
4135
|
+
*/
|
|
4136
|
+
var CredentialEntity = /** @class */ (function () {
|
|
4137
|
+
function CredentialEntity() {
|
|
4138
|
+
}
|
|
4139
|
+
/**
|
|
4140
|
+
* Generate Account Id key component as per the schema: <home_account_id>-<environment>
|
|
4141
|
+
*/
|
|
4142
|
+
CredentialEntity.prototype.generateAccountId = function () {
|
|
4143
|
+
return CredentialEntity.generateAccountIdForCacheKey(this.homeAccountId, this.environment);
|
|
4144
|
+
};
|
|
4145
|
+
/**
|
|
4146
|
+
* Generate Credential Id key component as per the schema: <credential_type>-<client_id>-<realm>
|
|
4147
|
+
*/
|
|
4148
|
+
CredentialEntity.prototype.generateCredentialId = function () {
|
|
4149
|
+
return CredentialEntity.generateCredentialIdForCacheKey(this.credentialType, this.clientId, this.realm, this.familyId);
|
|
4150
|
+
};
|
|
4151
|
+
/**
|
|
4152
|
+
* Generate target key component as per schema: <target>
|
|
4153
|
+
*/
|
|
4154
|
+
CredentialEntity.prototype.generateTarget = function () {
|
|
4155
|
+
return CredentialEntity.generateTargetForCacheKey(this.target);
|
|
4156
|
+
};
|
|
4157
|
+
/**
|
|
4158
|
+
* generates credential key
|
|
4159
|
+
*/
|
|
4160
|
+
CredentialEntity.prototype.generateCredentialKey = function () {
|
|
4161
|
+
return CredentialEntity.generateCredentialCacheKey(this.homeAccountId, this.environment, this.credentialType, this.clientId, this.realm, this.target, this.familyId, this.tokenType, this.requestedClaimsHash);
|
|
4162
|
+
};
|
|
4163
|
+
/**
|
|
4164
|
+
* returns the type of the cache (in this case credential)
|
|
4165
|
+
*/
|
|
4166
|
+
CredentialEntity.prototype.generateType = function () {
|
|
4167
|
+
switch (this.credentialType) {
|
|
4168
|
+
case exports.CredentialType.ID_TOKEN:
|
|
4169
|
+
return exports.CacheType.ID_TOKEN;
|
|
4170
|
+
case exports.CredentialType.ACCESS_TOKEN:
|
|
4171
|
+
case exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
|
|
4172
|
+
return exports.CacheType.ACCESS_TOKEN;
|
|
4173
|
+
case exports.CredentialType.REFRESH_TOKEN:
|
|
4174
|
+
return exports.CacheType.REFRESH_TOKEN;
|
|
4175
|
+
default: {
|
|
4176
|
+
throw ClientAuthError.createUnexpectedCredentialTypeError();
|
|
4177
|
+
}
|
|
4178
|
+
}
|
|
4179
|
+
};
|
|
4180
|
+
/**
|
|
4181
|
+
* generates credential key
|
|
4182
|
+
* <home_account_id*>-\<environment>-<credential_type>-<client_id>-<realm\*>-<target\*>-<scheme\*>
|
|
4183
|
+
*/
|
|
4184
|
+
CredentialEntity.generateCredentialCacheKey = function (homeAccountId, environment, credentialType, clientId, realm, target, familyId, tokenType, requestedClaimsHash) {
|
|
4185
|
+
var credentialKey = [
|
|
4186
|
+
this.generateAccountIdForCacheKey(homeAccountId, environment),
|
|
4187
|
+
this.generateCredentialIdForCacheKey(credentialType, clientId, realm, familyId),
|
|
4188
|
+
this.generateTargetForCacheKey(target),
|
|
4189
|
+
this.generateClaimsHashForCacheKey(requestedClaimsHash),
|
|
4190
|
+
this.generateSchemeForCacheKey(tokenType)
|
|
4191
|
+
];
|
|
4192
|
+
return credentialKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
|
|
4193
|
+
};
|
|
4194
|
+
/**
|
|
4195
|
+
* generates Account Id for keys
|
|
4196
|
+
* @param homeAccountId
|
|
4197
|
+
* @param environment
|
|
4198
|
+
*/
|
|
4199
|
+
CredentialEntity.generateAccountIdForCacheKey = function (homeAccountId, environment) {
|
|
4200
|
+
var accountId = [homeAccountId, environment];
|
|
4201
|
+
return accountId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
|
|
4202
|
+
};
|
|
4203
|
+
/**
|
|
4204
|
+
* Generates Credential Id for keys
|
|
4205
|
+
* @param credentialType
|
|
4206
|
+
* @param realm
|
|
4207
|
+
* @param clientId
|
|
4208
|
+
* @param familyId
|
|
4209
|
+
*/
|
|
4210
|
+
CredentialEntity.generateCredentialIdForCacheKey = function (credentialType, clientId, realm, familyId) {
|
|
4211
|
+
var clientOrFamilyId = credentialType === exports.CredentialType.REFRESH_TOKEN
|
|
4212
|
+
? familyId || clientId
|
|
4213
|
+
: clientId;
|
|
4214
|
+
var credentialId = [
|
|
4215
|
+
credentialType,
|
|
4216
|
+
clientOrFamilyId,
|
|
4217
|
+
realm || Constants.EMPTY_STRING,
|
|
4218
|
+
];
|
|
4219
|
+
return credentialId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
|
|
4220
|
+
};
|
|
4221
|
+
/**
|
|
4222
|
+
* Generate target key component as per schema: <target>
|
|
4223
|
+
*/
|
|
4224
|
+
CredentialEntity.generateTargetForCacheKey = function (scopes) {
|
|
4225
|
+
return (scopes || Constants.EMPTY_STRING).toLowerCase();
|
|
4226
|
+
};
|
|
4227
|
+
/**
|
|
4228
|
+
* Generate requested claims key component as per schema: <requestedClaims>
|
|
4229
|
+
*/
|
|
4230
|
+
CredentialEntity.generateClaimsHashForCacheKey = function (requestedClaimsHash) {
|
|
4231
|
+
return (requestedClaimsHash || Constants.EMPTY_STRING).toLowerCase();
|
|
4232
|
+
};
|
|
4233
|
+
/**
|
|
4234
|
+
* Generate scheme key componenet as per schema: <scheme>
|
|
4235
|
+
*/
|
|
4236
|
+
CredentialEntity.generateSchemeForCacheKey = function (tokenType) {
|
|
4237
|
+
/*
|
|
4238
|
+
* PoP Tokens and SSH certs include scheme in cache key
|
|
4239
|
+
* Cast to lowercase to handle "bearer" from ADFS
|
|
4240
|
+
*/
|
|
4241
|
+
return (tokenType && tokenType.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : Constants.EMPTY_STRING;
|
|
4242
|
+
};
|
|
4243
|
+
return CredentialEntity;
|
|
4244
|
+
}());
|
|
4245
|
+
|
|
4117
4246
|
/*
|
|
4118
4247
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4119
4248
|
* Licensed under the MIT License.
|
|
@@ -6307,7 +6436,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
|
|
|
6307
6436
|
if (!request.account) {
|
|
6308
6437
|
throw ClientAuthError.createNoAccountInSilentRequestError();
|
|
6309
6438
|
}
|
|
6310
|
-
isFOCI = this.cacheManager.isAppMetadataFOCI(request.account.environment
|
|
6439
|
+
isFOCI = this.cacheManager.isAppMetadataFOCI(request.account.environment);
|
|
6311
6440
|
// if the app is part of the family, retrive a Family refresh token if present and make a refreshTokenRequest
|
|
6312
6441
|
if (isFOCI) {
|
|
6313
6442
|
try {
|
|
@@ -6346,7 +6475,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
|
|
|
6346
6475
|
(_a = this.performanceClient) === null || _a === void 0 ? void 0 : _a.addQueueMeasurement(exports.PerformanceEvents.RefreshTokenClientAcquireTokenWithCachedRefreshToken, request.correlationId);
|
|
6347
6476
|
atsMeasurement = (_b = this.performanceClient) === null || _b === void 0 ? void 0 : _b.startMeasurement(exports.PerformanceEvents.RefreshTokenClientAcquireTokenWithCachedRefreshToken, request.correlationId);
|
|
6348
6477
|
this.logger.verbose("RefreshTokenClientAcquireTokenWithCachedRefreshToken called", request.correlationId);
|
|
6349
|
-
refreshToken = this.cacheManager.
|
|
6478
|
+
refreshToken = this.cacheManager.getRefreshToken(request.account, foci);
|
|
6350
6479
|
if (!refreshToken) {
|
|
6351
6480
|
atsMeasurement === null || atsMeasurement === void 0 ? void 0 : atsMeasurement.discardMeasurement();
|
|
6352
6481
|
throw InteractionRequiredAuthError.createNoTokensFoundError();
|
|
@@ -6573,7 +6702,6 @@ var ClientCredentialClient = /** @class */ (function (_super) {
|
|
|
6573
6702
|
};
|
|
6574
6703
|
/**
|
|
6575
6704
|
* Reads access token from the cache
|
|
6576
|
-
* TODO: Move this call to cacheManager instead
|
|
6577
6705
|
*/
|
|
6578
6706
|
ClientCredentialClient.prototype.readAccessTokenFromCache = function () {
|
|
6579
6707
|
var accessTokenFilter = {
|
|
@@ -6582,10 +6710,9 @@ var ClientCredentialClient = /** @class */ (function (_super) {
|
|
|
6582
6710
|
credentialType: exports.CredentialType.ACCESS_TOKEN,
|
|
6583
6711
|
clientId: this.config.authOptions.clientId,
|
|
6584
6712
|
realm: this.authority.tenant,
|
|
6585
|
-
target: this.scopeSet.
|
|
6713
|
+
target: ScopeSet.createSearchScopes(this.scopeSet.asArray())
|
|
6586
6714
|
};
|
|
6587
|
-
var
|
|
6588
|
-
var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
|
|
6715
|
+
var accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
|
|
6589
6716
|
if (accessTokens.length < 1) {
|
|
6590
6717
|
return null;
|
|
6591
6718
|
}
|
|
@@ -6766,7 +6893,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
|
|
|
6766
6893
|
this.logger.info("OnbehalfofFlow:getCachedAuthenticationResult - Cached access token is expired or will expire within " + this.config.systemOptions.tokenRenewalOffsetSeconds + " seconds.");
|
|
6767
6894
|
throw ClientAuthError.createRefreshRequiredError();
|
|
6768
6895
|
}
|
|
6769
|
-
cachedIdToken = this.readIdTokenFromCacheForOBO(
|
|
6896
|
+
cachedIdToken = this.readIdTokenFromCacheForOBO(cachedAccessToken.homeAccountId);
|
|
6770
6897
|
cachedAccount = null;
|
|
6771
6898
|
if (cachedIdToken) {
|
|
6772
6899
|
idTokenObject = new AuthToken(cachedIdToken.secret, this.config.cryptoInterface);
|
|
@@ -6801,7 +6928,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
|
|
|
6801
6928
|
* Certain use cases of OBO flow do not expect an idToken in the cache/or from the service
|
|
6802
6929
|
* @param request
|
|
6803
6930
|
*/
|
|
6804
|
-
OnBehalfOfClient.prototype.readIdTokenFromCacheForOBO = function (
|
|
6931
|
+
OnBehalfOfClient.prototype.readIdTokenFromCacheForOBO = function (atHomeAccountId) {
|
|
6805
6932
|
var idTokenFilter = {
|
|
6806
6933
|
homeAccountId: atHomeAccountId,
|
|
6807
6934
|
environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
|
|
@@ -6809,8 +6936,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
|
|
|
6809
6936
|
clientId: this.config.authOptions.clientId,
|
|
6810
6937
|
realm: this.authority.tenant
|
|
6811
6938
|
};
|
|
6812
|
-
var
|
|
6813
|
-
var idTokens = Object.keys(credentialCache.idTokens).map(function (key) { return credentialCache.idTokens[key]; });
|
|
6939
|
+
var idTokens = this.cacheManager.getIdTokensByFilter(idTokenFilter);
|
|
6814
6940
|
// When acquiring a token on behalf of an application, there might not be an id token in the cache
|
|
6815
6941
|
if (idTokens.length < 1) {
|
|
6816
6942
|
return null;
|
|
@@ -6833,14 +6959,13 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
|
|
|
6833
6959
|
var accessTokenFilter = {
|
|
6834
6960
|
credentialType: credentialType,
|
|
6835
6961
|
clientId: clientId,
|
|
6836
|
-
target: this.scopeSet.
|
|
6962
|
+
target: ScopeSet.createSearchScopes(this.scopeSet.asArray()),
|
|
6837
6963
|
tokenType: authScheme,
|
|
6838
6964
|
keyId: request.sshKid,
|
|
6839
6965
|
requestedClaimsHash: request.requestedClaimsHash,
|
|
6840
6966
|
userAssertionHash: this.userAssertionHash
|
|
6841
6967
|
};
|
|
6842
|
-
var
|
|
6843
|
-
var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
|
|
6968
|
+
var accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
|
|
6844
6969
|
var numAccessTokens = accessTokens.length;
|
|
6845
6970
|
if (numAccessTokens < 1) {
|
|
6846
6971
|
return null;
|
|
@@ -6989,7 +7114,7 @@ var SilentFlowClient = /** @class */ (function (_super) {
|
|
|
6989
7114
|
throw ClientAuthError.createNoAccountInSilentRequestError();
|
|
6990
7115
|
}
|
|
6991
7116
|
environment = request.authority || this.authority.getPreferredCache();
|
|
6992
|
-
cacheRecord = this.cacheManager.readCacheRecord(request.account,
|
|
7117
|
+
cacheRecord = this.cacheManager.readCacheRecord(request.account, request, environment);
|
|
6993
7118
|
if (!cacheRecord.accessToken) {
|
|
6994
7119
|
// Must refresh due to non-existent access_token.
|
|
6995
7120
|
(_b = this.serverTelemetryManager) === null || _b === void 0 ? void 0 : _b.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
|