@azure/msal-common 11.0.0 → 12.1.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.d.ts +12 -2
- package/dist/authority/Authority.d.ts.map +1 -1
- package/dist/authority/Authority.js +34 -4
- package/dist/authority/Authority.js.map +1 -1
- package/dist/authority/AuthorityFactory.d.ts.map +1 -1
- package/dist/authority/AuthorityFactory.js +4 -3
- package/dist/authority/AuthorityFactory.js.map +1 -1
- package/dist/authority/AuthorityMetadata.js +1 -1
- package/dist/authority/AuthorityOptions.js +1 -1
- package/dist/authority/AuthorityType.d.ts +2 -1
- package/dist/authority/AuthorityType.d.ts.map +1 -1
- package/dist/authority/AuthorityType.js +2 -1
- package/dist/authority/AuthorityType.js.map +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 +631 -478
- 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 +2 -19
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.js +5 -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.1.0 2023-04-18 */
|
|
2
2
|
'use strict';
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -108,6 +108,9 @@ var Constants = {
|
|
|
108
108
|
DSTS: "dstsv2",
|
|
109
109
|
// Default AAD Instance Discovery Endpoint
|
|
110
110
|
AAD_INSTANCE_DISCOVERY_ENDPT: "https://login.microsoftonline.com/common/discovery/instance?api-version=1.1&authorization_endpoint=",
|
|
111
|
+
// CIAM URL
|
|
112
|
+
CIAM_AUTH_URL: ".ciamlogin.com",
|
|
113
|
+
AAD_TENANT_DOMAIN_SUFFIX: ".onmicrosoft.com",
|
|
111
114
|
// Resource delimiter - used for certain cache entries
|
|
112
115
|
RESOURCE_DELIM: "|",
|
|
113
116
|
// Placeholder for non-existent account ids/objects
|
|
@@ -278,13 +281,6 @@ exports.SSOTypes = void 0;
|
|
|
278
281
|
SSOTypes["ACCOUNT_ID"] = "accountIdentifier";
|
|
279
282
|
SSOTypes["HOMEACCOUNT_ID"] = "homeAccountIdentifier";
|
|
280
283
|
})(exports.SSOTypes || (exports.SSOTypes = {}));
|
|
281
|
-
/**
|
|
282
|
-
* Disallowed extra query parameters.
|
|
283
|
-
*/
|
|
284
|
-
[
|
|
285
|
-
exports.SSOTypes.SID,
|
|
286
|
-
exports.SSOTypes.LOGIN_HINT
|
|
287
|
-
];
|
|
288
284
|
/**
|
|
289
285
|
* allowed values for codeVerifier
|
|
290
286
|
*/
|
|
@@ -351,22 +347,6 @@ exports.CredentialType = void 0;
|
|
|
351
347
|
CredentialType["ACCESS_TOKEN_WITH_AUTH_SCHEME"] = "AccessToken_With_AuthScheme";
|
|
352
348
|
CredentialType["REFRESH_TOKEN"] = "RefreshToken";
|
|
353
349
|
})(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
350
|
/**
|
|
371
351
|
* Combine all cache types
|
|
372
352
|
*/
|
|
@@ -1443,7 +1423,7 @@ var Logger = /** @class */ (function () {
|
|
|
1443
1423
|
|
|
1444
1424
|
/* eslint-disable header/header */
|
|
1445
1425
|
var name = "@azure/msal-common";
|
|
1446
|
-
var version = "
|
|
1426
|
+
var version = "12.1.0";
|
|
1447
1427
|
|
|
1448
1428
|
/*
|
|
1449
1429
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -1465,181 +1445,6 @@ exports.AzureCloudInstance = void 0;
|
|
|
1465
1445
|
AzureCloudInstance["AzureUsGovernment"] = "https://login.microsoftonline.us";
|
|
1466
1446
|
})(exports.AzureCloudInstance || (exports.AzureCloudInstance = {}));
|
|
1467
1447
|
|
|
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
1448
|
/*
|
|
1644
1449
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
1645
1450
|
* Licensed under the MIT License.
|
|
@@ -1924,6 +1729,21 @@ var ScopeSet = /** @class */ (function () {
|
|
|
1924
1729
|
var inputScopes = scopeString.split(" ");
|
|
1925
1730
|
return new ScopeSet(inputScopes);
|
|
1926
1731
|
};
|
|
1732
|
+
/**
|
|
1733
|
+
* Creates the set of scopes to search for in cache lookups
|
|
1734
|
+
* @param inputScopeString
|
|
1735
|
+
* @returns
|
|
1736
|
+
*/
|
|
1737
|
+
ScopeSet.createSearchScopes = function (inputScopeString) {
|
|
1738
|
+
var scopeSet = new ScopeSet(inputScopeString);
|
|
1739
|
+
if (!scopeSet.containsOnlyOIDCScopes()) {
|
|
1740
|
+
scopeSet.removeOIDCScopes();
|
|
1741
|
+
}
|
|
1742
|
+
else {
|
|
1743
|
+
scopeSet.removeScope(Constants.OFFLINE_ACCESS_SCOPE);
|
|
1744
|
+
}
|
|
1745
|
+
return scopeSet;
|
|
1746
|
+
};
|
|
1927
1747
|
/**
|
|
1928
1748
|
* Used to validate the scopes input parameter requested by the developer.
|
|
1929
1749
|
* @param {Array<string>} inputScopes - Developer requested permissions. Not all scopes are guaranteed to be included in the access token returned.
|
|
@@ -2123,6 +1943,7 @@ exports.AuthorityType = void 0;
|
|
|
2123
1943
|
AuthorityType[AuthorityType["Default"] = 0] = "Default";
|
|
2124
1944
|
AuthorityType[AuthorityType["Adfs"] = 1] = "Adfs";
|
|
2125
1945
|
AuthorityType[AuthorityType["Dsts"] = 2] = "Dsts";
|
|
1946
|
+
AuthorityType[AuthorityType["Ciam"] = 3] = "Ciam";
|
|
2126
1947
|
})(exports.AuthorityType || (exports.AuthorityType = {}));
|
|
2127
1948
|
|
|
2128
1949
|
/*
|
|
@@ -2420,35 +2241,59 @@ var AuthToken = /** @class */ (function () {
|
|
|
2420
2241
|
* Interface class which implement cache storage functions used by MSAL to perform validity checks, and store tokens.
|
|
2421
2242
|
*/
|
|
2422
2243
|
var CacheManager = /** @class */ (function () {
|
|
2423
|
-
function CacheManager(clientId, cryptoImpl) {
|
|
2244
|
+
function CacheManager(clientId, cryptoImpl, logger) {
|
|
2424
2245
|
this.clientId = clientId;
|
|
2425
2246
|
this.cryptoImpl = cryptoImpl;
|
|
2247
|
+
this.commonLogger = logger.clone(name, version);
|
|
2426
2248
|
}
|
|
2427
2249
|
/**
|
|
2428
2250
|
* Returns all accounts in cache
|
|
2429
2251
|
*/
|
|
2430
2252
|
CacheManager.prototype.getAllAccounts = function () {
|
|
2431
2253
|
var _this = this;
|
|
2432
|
-
var
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2254
|
+
var allAccountKeys = this.getAccountKeys();
|
|
2255
|
+
if (allAccountKeys.length < 1) {
|
|
2256
|
+
return [];
|
|
2257
|
+
}
|
|
2258
|
+
var accountEntities = allAccountKeys.reduce(function (accounts, key) {
|
|
2259
|
+
var entity = _this.getAccount(key);
|
|
2260
|
+
if (!entity) {
|
|
2261
|
+
return accounts;
|
|
2262
|
+
}
|
|
2263
|
+
accounts.push(entity);
|
|
2264
|
+
return accounts;
|
|
2265
|
+
}, []);
|
|
2266
|
+
if (accountEntities.length < 1) {
|
|
2436
2267
|
return [];
|
|
2437
2268
|
}
|
|
2438
2269
|
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;
|
|
2270
|
+
var allAccounts = accountEntities.map(function (accountEntity) {
|
|
2271
|
+
return _this.getAccountInfoFromEntity(accountEntity);
|
|
2448
2272
|
});
|
|
2449
2273
|
return allAccounts;
|
|
2450
2274
|
}
|
|
2451
2275
|
};
|
|
2276
|
+
/**
|
|
2277
|
+
* Gets accountInfo object based on provided filters
|
|
2278
|
+
*/
|
|
2279
|
+
CacheManager.prototype.getAccountInfoFilteredBy = function (accountFilter) {
|
|
2280
|
+
var allAccounts = this.getAccountsFilteredBy(accountFilter);
|
|
2281
|
+
if (allAccounts.length > 0) {
|
|
2282
|
+
return this.getAccountInfoFromEntity(allAccounts[0]);
|
|
2283
|
+
}
|
|
2284
|
+
else {
|
|
2285
|
+
return null;
|
|
2286
|
+
}
|
|
2287
|
+
};
|
|
2288
|
+
CacheManager.prototype.getAccountInfoFromEntity = function (accountEntity) {
|
|
2289
|
+
var accountInfo = accountEntity.getAccountInfo();
|
|
2290
|
+
var idToken = this.getIdToken(accountInfo);
|
|
2291
|
+
if (idToken) {
|
|
2292
|
+
accountInfo.idToken = idToken.secret;
|
|
2293
|
+
accountInfo.idTokenClaims = new AuthToken(idToken.secret, this.cryptoImpl).claims;
|
|
2294
|
+
}
|
|
2295
|
+
return accountInfo;
|
|
2296
|
+
};
|
|
2452
2297
|
/**
|
|
2453
2298
|
* saves a cache record
|
|
2454
2299
|
* @param cacheRecord
|
|
@@ -2490,12 +2335,12 @@ var CacheManager = /** @class */ (function () {
|
|
|
2490
2335
|
*/
|
|
2491
2336
|
CacheManager.prototype.saveAccessToken = function (credential) {
|
|
2492
2337
|
return __awaiter(this, void 0, void 0, function () {
|
|
2493
|
-
var
|
|
2338
|
+
var accessTokenFilter, tokenKeys, currentScopes, removedAccessTokens;
|
|
2494
2339
|
var _this = this;
|
|
2495
2340
|
return __generator(this, function (_a) {
|
|
2496
2341
|
switch (_a.label) {
|
|
2497
2342
|
case 0:
|
|
2498
|
-
|
|
2343
|
+
accessTokenFilter = {
|
|
2499
2344
|
clientId: credential.clientId,
|
|
2500
2345
|
credentialType: credential.credentialType,
|
|
2501
2346
|
environment: credential.environment,
|
|
@@ -2503,22 +2348,25 @@ var CacheManager = /** @class */ (function () {
|
|
|
2503
2348
|
realm: credential.realm,
|
|
2504
2349
|
tokenType: credential.tokenType,
|
|
2505
2350
|
requestedClaimsHash: credential.requestedClaimsHash
|
|
2506
|
-
}
|
|
2351
|
+
};
|
|
2352
|
+
tokenKeys = this.getTokenKeys();
|
|
2507
2353
|
currentScopes = ScopeSet.fromString(credential.target);
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2354
|
+
removedAccessTokens = [];
|
|
2355
|
+
tokenKeys.accessToken.forEach(function (key) {
|
|
2356
|
+
if (!_this.accessTokenKeyMatchesFilter(key, accessTokenFilter, false)) {
|
|
2357
|
+
return;
|
|
2358
|
+
}
|
|
2359
|
+
var tokenEntity = _this.getAccessTokenCredential(key);
|
|
2360
|
+
if (tokenEntity && _this.credentialMatchesFilter(tokenEntity, accessTokenFilter)) {
|
|
2361
|
+
var tokenScopeSet = ScopeSet.fromString(tokenEntity.target);
|
|
2362
|
+
if (tokenScopeSet.intersectingScopeSets(currentScopes)) {
|
|
2363
|
+
removedAccessTokens.push(_this.removeAccessToken(key));
|
|
2364
|
+
}
|
|
2515
2365
|
}
|
|
2516
2366
|
});
|
|
2517
|
-
return [4 /*yield*/, Promise.all(
|
|
2367
|
+
return [4 /*yield*/, Promise.all(removedAccessTokens)];
|
|
2518
2368
|
case 1:
|
|
2519
2369
|
_a.sent();
|
|
2520
|
-
_a.label = 2;
|
|
2521
|
-
case 2:
|
|
2522
2370
|
this.setAccessTokenCredential(credential);
|
|
2523
2371
|
return [2 /*return*/];
|
|
2524
2372
|
}
|
|
@@ -2533,149 +2381,151 @@ var CacheManager = /** @class */ (function () {
|
|
|
2533
2381
|
* @param realm
|
|
2534
2382
|
*/
|
|
2535
2383
|
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
2384
|
var _this = this;
|
|
2547
|
-
var
|
|
2548
|
-
var matchingAccounts =
|
|
2549
|
-
|
|
2385
|
+
var allAccountKeys = this.getAccountKeys();
|
|
2386
|
+
var matchingAccounts = [];
|
|
2387
|
+
allAccountKeys.forEach(function (cacheKey) {
|
|
2388
|
+
if (!_this.isAccountKey(cacheKey, accountFilter.homeAccountId, accountFilter.realm)) {
|
|
2389
|
+
// Don't parse value if the key doesn't match the account filters
|
|
2390
|
+
return;
|
|
2391
|
+
}
|
|
2550
2392
|
var entity = _this.getAccount(cacheKey);
|
|
2551
2393
|
if (!entity) {
|
|
2552
2394
|
return;
|
|
2553
2395
|
}
|
|
2554
|
-
if (!!homeAccountId && !_this.matchHomeAccountId(entity, homeAccountId)) {
|
|
2396
|
+
if (!!accountFilter.homeAccountId && !_this.matchHomeAccountId(entity, accountFilter.homeAccountId)) {
|
|
2555
2397
|
return;
|
|
2556
2398
|
}
|
|
2557
|
-
if (!!
|
|
2399
|
+
if (!!accountFilter.localAccountId && !_this.matchLocalAccountId(entity, accountFilter.localAccountId)) {
|
|
2400
|
+
return;
|
|
2401
|
+
}
|
|
2402
|
+
if (!!accountFilter.username && !_this.matchUsername(entity, accountFilter.username)) {
|
|
2403
|
+
return;
|
|
2404
|
+
}
|
|
2405
|
+
if (!!accountFilter.environment && !_this.matchEnvironment(entity, accountFilter.environment)) {
|
|
2558
2406
|
return;
|
|
2559
2407
|
}
|
|
2560
|
-
if (!!realm && !_this.matchRealm(entity, realm)) {
|
|
2408
|
+
if (!!accountFilter.realm && !_this.matchRealm(entity, accountFilter.realm)) {
|
|
2561
2409
|
return;
|
|
2562
2410
|
}
|
|
2563
|
-
if (!!nativeAccountId && !_this.matchNativeAccountId(entity, nativeAccountId)) {
|
|
2411
|
+
if (!!accountFilter.nativeAccountId && !_this.matchNativeAccountId(entity, accountFilter.nativeAccountId)) {
|
|
2564
2412
|
return;
|
|
2565
2413
|
}
|
|
2566
|
-
matchingAccounts
|
|
2414
|
+
matchingAccounts.push(entity);
|
|
2567
2415
|
});
|
|
2568
2416
|
return matchingAccounts;
|
|
2569
2417
|
};
|
|
2570
2418
|
/**
|
|
2571
|
-
*
|
|
2419
|
+
* Returns true if the given key matches our account key schema. Also matches homeAccountId and/or tenantId if provided
|
|
2420
|
+
* @param key
|
|
2572
2421
|
* @param homeAccountId
|
|
2573
|
-
* @param
|
|
2574
|
-
* @
|
|
2575
|
-
* @param clientId
|
|
2576
|
-
* @param realm
|
|
2577
|
-
* @param target
|
|
2422
|
+
* @param tenantId
|
|
2423
|
+
* @returns
|
|
2578
2424
|
*/
|
|
2579
|
-
CacheManager.prototype.
|
|
2580
|
-
|
|
2425
|
+
CacheManager.prototype.isAccountKey = function (key, homeAccountId, tenantId) {
|
|
2426
|
+
if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 3) {
|
|
2427
|
+
// Account cache keys contain 3 items separated by '-' (each item may also contain '-')
|
|
2428
|
+
return false;
|
|
2429
|
+
}
|
|
2430
|
+
if (homeAccountId && !key.toLowerCase().includes(homeAccountId.toLowerCase())) {
|
|
2431
|
+
return false;
|
|
2432
|
+
}
|
|
2433
|
+
if (tenantId && !key.toLowerCase().includes(tenantId.toLowerCase())) {
|
|
2434
|
+
return false;
|
|
2435
|
+
}
|
|
2436
|
+
// Do not check environment as aliasing can cause false negatives
|
|
2437
|
+
return true;
|
|
2581
2438
|
};
|
|
2582
2439
|
/**
|
|
2583
|
-
*
|
|
2584
|
-
* @param
|
|
2585
|
-
* @param environment
|
|
2586
|
-
* @param credentialType
|
|
2587
|
-
* @param clientId
|
|
2588
|
-
* @param realm
|
|
2589
|
-
* @param target
|
|
2590
|
-
* @param userAssertionHash
|
|
2591
|
-
* @param tokenType
|
|
2440
|
+
* Returns true if the given key matches our credential key schema.
|
|
2441
|
+
* @param key
|
|
2592
2442
|
*/
|
|
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;
|
|
2633
|
-
}
|
|
2634
|
-
if (!!familyId && !_this.matchFamilyId(entity, familyId)) {
|
|
2635
|
-
return;
|
|
2443
|
+
CacheManager.prototype.isCredentialKey = function (key) {
|
|
2444
|
+
if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 6) {
|
|
2445
|
+
// Credential cache keys contain 6 items separated by '-' (each item may also contain '-')
|
|
2446
|
+
return false;
|
|
2447
|
+
}
|
|
2448
|
+
var lowerCaseKey = key.toLowerCase();
|
|
2449
|
+
// Credential keys must indicate what credential type they represent
|
|
2450
|
+
if (lowerCaseKey.indexOf(exports.CredentialType.ID_TOKEN.toLowerCase()) === -1 &&
|
|
2451
|
+
lowerCaseKey.indexOf(exports.CredentialType.ACCESS_TOKEN.toLowerCase()) === -1 &&
|
|
2452
|
+
lowerCaseKey.indexOf(exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()) === -1 &&
|
|
2453
|
+
lowerCaseKey.indexOf(exports.CredentialType.REFRESH_TOKEN.toLowerCase()) === -1) {
|
|
2454
|
+
return false;
|
|
2455
|
+
}
|
|
2456
|
+
if (lowerCaseKey.indexOf(exports.CredentialType.REFRESH_TOKEN.toLowerCase()) > -1) {
|
|
2457
|
+
// Refresh tokens must contain the client id or family id
|
|
2458
|
+
var clientIdValidation = "" + exports.CredentialType.REFRESH_TOKEN + Separators.CACHE_KEY_SEPARATOR + this.clientId + Separators.CACHE_KEY_SEPARATOR;
|
|
2459
|
+
var familyIdValidation = "" + exports.CredentialType.REFRESH_TOKEN + Separators.CACHE_KEY_SEPARATOR + THE_FAMILY_ID + Separators.CACHE_KEY_SEPARATOR;
|
|
2460
|
+
if (lowerCaseKey.indexOf(clientIdValidation.toLowerCase()) === -1 && lowerCaseKey.indexOf(familyIdValidation.toLowerCase()) === -1) {
|
|
2461
|
+
return false;
|
|
2636
2462
|
}
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2463
|
+
}
|
|
2464
|
+
else if (lowerCaseKey.indexOf(this.clientId.toLowerCase()) === -1) {
|
|
2465
|
+
// Tokens must contain the clientId
|
|
2466
|
+
return false;
|
|
2467
|
+
}
|
|
2468
|
+
return true;
|
|
2469
|
+
};
|
|
2470
|
+
/**
|
|
2471
|
+
* Returns whether or not the given credential entity matches the filter
|
|
2472
|
+
* @param entity
|
|
2473
|
+
* @param filter
|
|
2474
|
+
* @returns
|
|
2475
|
+
*/
|
|
2476
|
+
CacheManager.prototype.credentialMatchesFilter = function (entity, filter) {
|
|
2477
|
+
if (!!filter.clientId && !this.matchClientId(entity, filter.clientId)) {
|
|
2478
|
+
return false;
|
|
2479
|
+
}
|
|
2480
|
+
if (!!filter.userAssertionHash && !this.matchUserAssertionHash(entity, filter.userAssertionHash)) {
|
|
2481
|
+
return false;
|
|
2482
|
+
}
|
|
2483
|
+
/*
|
|
2484
|
+
* homeAccountId can be undefined, and we want to filter out cached items that have a homeAccountId of ""
|
|
2485
|
+
* because we don't want a client_credential request to return a cached token that has a homeAccountId
|
|
2486
|
+
*/
|
|
2487
|
+
if ((typeof filter.homeAccountId === "string") && !this.matchHomeAccountId(entity, filter.homeAccountId)) {
|
|
2488
|
+
return false;
|
|
2489
|
+
}
|
|
2490
|
+
if (!!filter.environment && !this.matchEnvironment(entity, filter.environment)) {
|
|
2491
|
+
return false;
|
|
2492
|
+
}
|
|
2493
|
+
if (!!filter.realm && !this.matchRealm(entity, filter.realm)) {
|
|
2494
|
+
return false;
|
|
2495
|
+
}
|
|
2496
|
+
if (!!filter.credentialType && !this.matchCredentialType(entity, filter.credentialType)) {
|
|
2497
|
+
return false;
|
|
2498
|
+
}
|
|
2499
|
+
if (!!filter.familyId && !this.matchFamilyId(entity, filter.familyId)) {
|
|
2500
|
+
return false;
|
|
2501
|
+
}
|
|
2502
|
+
/*
|
|
2503
|
+
* idTokens do not have "target", target specific refreshTokens do exist for some types of authentication
|
|
2504
|
+
* Resource specific refresh tokens case will be added when the support is deemed necessary
|
|
2505
|
+
*/
|
|
2506
|
+
if (!!filter.target && !this.matchTarget(entity, filter.target)) {
|
|
2507
|
+
return false;
|
|
2508
|
+
}
|
|
2509
|
+
// If request OR cached entity has requested Claims Hash, check if they match
|
|
2510
|
+
if (filter.requestedClaimsHash || entity.requestedClaimsHash) {
|
|
2511
|
+
// Don't match if either is undefined or they are different
|
|
2512
|
+
if (entity.requestedClaimsHash !== filter.requestedClaimsHash) {
|
|
2513
|
+
return false;
|
|
2643
2514
|
}
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
}
|
|
2515
|
+
}
|
|
2516
|
+
// Access Token with Auth Scheme specific matching
|
|
2517
|
+
if (entity.credentialType === exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME) {
|
|
2518
|
+
if (!!filter.tokenType && !this.matchTokenType(entity, filter.tokenType)) {
|
|
2519
|
+
return false;
|
|
2650
2520
|
}
|
|
2651
|
-
//
|
|
2652
|
-
if (
|
|
2653
|
-
if (
|
|
2654
|
-
return;
|
|
2521
|
+
// KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
|
|
2522
|
+
if (filter.tokenType === exports.AuthenticationScheme.SSH) {
|
|
2523
|
+
if (filter.keyId && !this.matchKeyId(entity, filter.keyId)) {
|
|
2524
|
+
return false;
|
|
2655
2525
|
}
|
|
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
|
-
}
|
|
2661
|
-
}
|
|
2662
|
-
}
|
|
2663
|
-
// At this point, the entity matches the request, update cache key if key schema has changed
|
|
2664
|
-
var updatedCacheKey = _this.updateCredentialCacheKey(cacheKey, entity);
|
|
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
2526
|
}
|
|
2677
|
-
}
|
|
2678
|
-
return
|
|
2527
|
+
}
|
|
2528
|
+
return true;
|
|
2679
2529
|
};
|
|
2680
2530
|
/**
|
|
2681
2531
|
* retrieve appMetadata matching all provided filters; if no filter is set, get all appMetadata
|
|
@@ -2743,30 +2593,26 @@ var CacheManager = /** @class */ (function () {
|
|
|
2743
2593
|
*/
|
|
2744
2594
|
CacheManager.prototype.removeAllAccounts = function () {
|
|
2745
2595
|
return __awaiter(this, void 0, void 0, function () {
|
|
2746
|
-
var
|
|
2596
|
+
var allAccountKeys, removedAccounts;
|
|
2747
2597
|
var _this = this;
|
|
2748
2598
|
return __generator(this, function (_a) {
|
|
2749
2599
|
switch (_a.label) {
|
|
2750
2600
|
case 0:
|
|
2751
|
-
|
|
2601
|
+
allAccountKeys = this.getAccountKeys();
|
|
2752
2602
|
removedAccounts = [];
|
|
2753
|
-
|
|
2754
|
-
var entity = _this.getAccount(cacheKey);
|
|
2755
|
-
if (!entity) {
|
|
2756
|
-
return;
|
|
2757
|
-
}
|
|
2603
|
+
allAccountKeys.forEach(function (cacheKey) {
|
|
2758
2604
|
removedAccounts.push(_this.removeAccount(cacheKey));
|
|
2759
2605
|
});
|
|
2760
2606
|
return [4 /*yield*/, Promise.all(removedAccounts)];
|
|
2761
2607
|
case 1:
|
|
2762
2608
|
_a.sent();
|
|
2763
|
-
return [2 /*return
|
|
2609
|
+
return [2 /*return*/];
|
|
2764
2610
|
}
|
|
2765
2611
|
});
|
|
2766
2612
|
});
|
|
2767
2613
|
};
|
|
2768
2614
|
/**
|
|
2769
|
-
*
|
|
2615
|
+
* Removes the account and related tokens for a given account key
|
|
2770
2616
|
* @param account
|
|
2771
2617
|
*/
|
|
2772
2618
|
CacheManager.prototype.removeAccount = function (accountKey) {
|
|
@@ -2780,7 +2626,10 @@ var CacheManager = /** @class */ (function () {
|
|
|
2780
2626
|
throw ClientAuthError.createNoAccountFoundError();
|
|
2781
2627
|
}
|
|
2782
2628
|
return [4 /*yield*/, this.removeAccountContext(account)];
|
|
2783
|
-
case 1:
|
|
2629
|
+
case 1:
|
|
2630
|
+
_a.sent();
|
|
2631
|
+
this.removeItem(accountKey);
|
|
2632
|
+
return [2 /*return*/];
|
|
2784
2633
|
}
|
|
2785
2634
|
});
|
|
2786
2635
|
});
|
|
@@ -2791,29 +2640,33 @@ var CacheManager = /** @class */ (function () {
|
|
|
2791
2640
|
*/
|
|
2792
2641
|
CacheManager.prototype.removeAccountContext = function (account) {
|
|
2793
2642
|
return __awaiter(this, void 0, void 0, function () {
|
|
2794
|
-
var
|
|
2643
|
+
var allTokenKeys, accountId, removedCredentials;
|
|
2795
2644
|
var _this = this;
|
|
2796
2645
|
return __generator(this, function (_a) {
|
|
2797
2646
|
switch (_a.label) {
|
|
2798
2647
|
case 0:
|
|
2799
|
-
|
|
2648
|
+
allTokenKeys = this.getTokenKeys();
|
|
2800
2649
|
accountId = account.generateAccountId();
|
|
2801
2650
|
removedCredentials = [];
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
if (credType === Constants.NOT_DEFINED) {
|
|
2806
|
-
return;
|
|
2651
|
+
allTokenKeys.idToken.forEach(function (key) {
|
|
2652
|
+
if (key.indexOf(accountId) === 0) {
|
|
2653
|
+
_this.removeIdToken(key);
|
|
2807
2654
|
}
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2655
|
+
});
|
|
2656
|
+
allTokenKeys.accessToken.forEach(function (key) {
|
|
2657
|
+
if (key.indexOf(accountId) === 0) {
|
|
2658
|
+
removedCredentials.push(_this.removeAccessToken(key));
|
|
2659
|
+
}
|
|
2660
|
+
});
|
|
2661
|
+
allTokenKeys.refreshToken.forEach(function (key) {
|
|
2662
|
+
if (key.indexOf(accountId) === 0) {
|
|
2663
|
+
_this.removeRefreshToken(key);
|
|
2811
2664
|
}
|
|
2812
2665
|
});
|
|
2813
2666
|
return [4 /*yield*/, Promise.all(removedCredentials)];
|
|
2814
2667
|
case 1:
|
|
2815
2668
|
_a.sent();
|
|
2816
|
-
return [2 /*return
|
|
2669
|
+
return [2 /*return*/];
|
|
2817
2670
|
}
|
|
2818
2671
|
});
|
|
2819
2672
|
});
|
|
@@ -2822,13 +2675,16 @@ var CacheManager = /** @class */ (function () {
|
|
|
2822
2675
|
* returns a boolean if the given credential is removed
|
|
2823
2676
|
* @param credential
|
|
2824
2677
|
*/
|
|
2825
|
-
CacheManager.prototype.
|
|
2678
|
+
CacheManager.prototype.removeAccessToken = function (key) {
|
|
2826
2679
|
return __awaiter(this, void 0, void 0, function () {
|
|
2827
|
-
var
|
|
2680
|
+
var credential, accessTokenWithAuthSchemeEntity, kid;
|
|
2828
2681
|
return __generator(this, function (_a) {
|
|
2829
2682
|
switch (_a.label) {
|
|
2830
2683
|
case 0:
|
|
2831
|
-
|
|
2684
|
+
credential = this.getAccessTokenCredential(key);
|
|
2685
|
+
if (!credential) {
|
|
2686
|
+
return [2 /*return*/];
|
|
2687
|
+
}
|
|
2832
2688
|
if (!(credential.credentialType.toLowerCase() === exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase())) return [3 /*break*/, 4];
|
|
2833
2689
|
if (!(credential.tokenType === exports.AuthenticationScheme.POP)) return [3 /*break*/, 4];
|
|
2834
2690
|
accessTokenWithAuthSchemeEntity = credential;
|
|
@@ -2844,7 +2700,7 @@ var CacheManager = /** @class */ (function () {
|
|
|
2844
2700
|
case 3:
|
|
2845
2701
|
_a.sent();
|
|
2846
2702
|
throw ClientAuthError.createBindingKeyNotRemovedError();
|
|
2847
|
-
case 4: return [2 /*return*/, this.removeItem(key
|
|
2703
|
+
case 4: return [2 /*return*/, this.removeItem(key)];
|
|
2848
2704
|
}
|
|
2849
2705
|
});
|
|
2850
2706
|
});
|
|
@@ -2857,7 +2713,7 @@ var CacheManager = /** @class */ (function () {
|
|
|
2857
2713
|
var allCacheKeys = this.getKeys();
|
|
2858
2714
|
allCacheKeys.forEach(function (cacheKey) {
|
|
2859
2715
|
if (_this.isAppMetadata(cacheKey)) {
|
|
2860
|
-
_this.removeItem(cacheKey
|
|
2716
|
+
_this.removeItem(cacheKey);
|
|
2861
2717
|
}
|
|
2862
2718
|
});
|
|
2863
2719
|
return true;
|
|
@@ -2870,12 +2726,13 @@ var CacheManager = /** @class */ (function () {
|
|
|
2870
2726
|
* @param environment
|
|
2871
2727
|
* @param authScheme
|
|
2872
2728
|
*/
|
|
2873
|
-
CacheManager.prototype.readCacheRecord = function (account,
|
|
2729
|
+
CacheManager.prototype.readCacheRecord = function (account, request, environment) {
|
|
2730
|
+
var tokenKeys = this.getTokenKeys();
|
|
2874
2731
|
var cachedAccount = this.readAccountFromCache(account);
|
|
2875
|
-
var cachedIdToken = this.
|
|
2876
|
-
var cachedAccessToken = this.
|
|
2877
|
-
var cachedRefreshToken = this.
|
|
2878
|
-
var cachedAppMetadata = this.readAppMetadataFromCache(environment
|
|
2732
|
+
var cachedIdToken = this.getIdToken(account, tokenKeys);
|
|
2733
|
+
var cachedAccessToken = this.getAccessToken(account, request, tokenKeys);
|
|
2734
|
+
var cachedRefreshToken = this.getRefreshToken(account, false, tokenKeys);
|
|
2735
|
+
var cachedAppMetadata = this.readAppMetadataFromCache(environment);
|
|
2879
2736
|
if (cachedAccount && cachedIdToken) {
|
|
2880
2737
|
cachedAccount.idTokenClaims = new AuthToken(cachedIdToken.secret, this.cryptoImpl).claims;
|
|
2881
2738
|
}
|
|
@@ -2896,49 +2753,81 @@ var CacheManager = /** @class */ (function () {
|
|
|
2896
2753
|
return this.getAccount(accountKey);
|
|
2897
2754
|
};
|
|
2898
2755
|
/**
|
|
2899
|
-
* Retrieve
|
|
2900
|
-
* @param
|
|
2901
|
-
* @
|
|
2756
|
+
* Retrieve IdTokenEntity from cache
|
|
2757
|
+
* @param clientId
|
|
2758
|
+
* @param account
|
|
2759
|
+
* @param inputRealm
|
|
2760
|
+
*/
|
|
2761
|
+
CacheManager.prototype.getIdToken = function (account, tokenKeys) {
|
|
2762
|
+
this.commonLogger.trace("CacheManager - getIdToken called");
|
|
2763
|
+
var idTokenFilter = {
|
|
2764
|
+
homeAccountId: account.homeAccountId,
|
|
2765
|
+
environment: account.environment,
|
|
2766
|
+
credentialType: exports.CredentialType.ID_TOKEN,
|
|
2767
|
+
clientId: this.clientId,
|
|
2768
|
+
realm: account.tenantId,
|
|
2769
|
+
};
|
|
2770
|
+
var idTokens = this.getIdTokensByFilter(idTokenFilter, tokenKeys);
|
|
2771
|
+
var numIdTokens = idTokens.length;
|
|
2772
|
+
if (numIdTokens < 1) {
|
|
2773
|
+
this.commonLogger.info("CacheManager:getIdToken - No token found");
|
|
2774
|
+
return null;
|
|
2775
|
+
}
|
|
2776
|
+
else if (numIdTokens > 1) {
|
|
2777
|
+
throw ClientAuthError.createMultipleMatchingTokensInCacheError();
|
|
2778
|
+
}
|
|
2779
|
+
this.commonLogger.info("CacheManager:getIdToken - Returning id token");
|
|
2780
|
+
return idTokens[0];
|
|
2781
|
+
};
|
|
2782
|
+
/**
|
|
2783
|
+
* Gets all idTokens matching the given filter
|
|
2784
|
+
* @param filter
|
|
2785
|
+
* @returns
|
|
2786
|
+
*/
|
|
2787
|
+
CacheManager.prototype.getIdTokensByFilter = function (filter, tokenKeys) {
|
|
2788
|
+
var _this = this;
|
|
2789
|
+
var idTokenKeys = tokenKeys && tokenKeys.idToken || this.getTokenKeys().idToken;
|
|
2790
|
+
var idTokens = [];
|
|
2791
|
+
idTokenKeys.forEach(function (key) {
|
|
2792
|
+
if (!_this.idTokenKeyMatchesFilter(key, __assign({ clientId: _this.clientId }, filter))) {
|
|
2793
|
+
return;
|
|
2794
|
+
}
|
|
2795
|
+
var idToken = _this.getIdTokenCredential(key);
|
|
2796
|
+
if (idToken && _this.credentialMatchesFilter(idToken, filter)) {
|
|
2797
|
+
idTokens.push(idToken);
|
|
2798
|
+
}
|
|
2799
|
+
});
|
|
2800
|
+
return idTokens;
|
|
2801
|
+
};
|
|
2802
|
+
/**
|
|
2803
|
+
* Validate the cache key against filter before retrieving and parsing cache value
|
|
2804
|
+
* @param key
|
|
2805
|
+
* @param filter
|
|
2806
|
+
* @returns
|
|
2807
|
+
*/
|
|
2808
|
+
CacheManager.prototype.idTokenKeyMatchesFilter = function (inputKey, filter) {
|
|
2809
|
+
var key = inputKey.toLowerCase();
|
|
2810
|
+
if (filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {
|
|
2811
|
+
return false;
|
|
2812
|
+
}
|
|
2813
|
+
if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
|
|
2814
|
+
return false;
|
|
2815
|
+
}
|
|
2816
|
+
return true;
|
|
2817
|
+
};
|
|
2818
|
+
/**
|
|
2819
|
+
* Removes idToken from the cache
|
|
2820
|
+
* @param key
|
|
2902
2821
|
*/
|
|
2903
|
-
CacheManager.prototype.
|
|
2904
|
-
|
|
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];
|
|
2822
|
+
CacheManager.prototype.removeIdToken = function (key) {
|
|
2823
|
+
this.removeItem(key);
|
|
2917
2824
|
};
|
|
2918
2825
|
/**
|
|
2919
|
-
*
|
|
2920
|
-
* @param
|
|
2921
|
-
* @param account
|
|
2922
|
-
* @param inputRealm
|
|
2826
|
+
* Removes refresh token from the cache
|
|
2827
|
+
* @param key
|
|
2923
2828
|
*/
|
|
2924
|
-
CacheManager.prototype.
|
|
2925
|
-
|
|
2926
|
-
homeAccountId: account.homeAccountId,
|
|
2927
|
-
environment: account.environment,
|
|
2928
|
-
credentialType: exports.CredentialType.ID_TOKEN,
|
|
2929
|
-
clientId: clientId,
|
|
2930
|
-
realm: account.tenantId,
|
|
2931
|
-
};
|
|
2932
|
-
var credentialCache = this.getCredentialsFilteredBy(idTokenFilter);
|
|
2933
|
-
var idTokens = Object.keys(credentialCache.idTokens).map(function (key) { return credentialCache.idTokens[key]; });
|
|
2934
|
-
var numIdTokens = idTokens.length;
|
|
2935
|
-
if (numIdTokens < 1) {
|
|
2936
|
-
return null;
|
|
2937
|
-
}
|
|
2938
|
-
else if (numIdTokens > 1) {
|
|
2939
|
-
throw ClientAuthError.createMultipleMatchingTokensInCacheError();
|
|
2940
|
-
}
|
|
2941
|
-
return idTokens[0];
|
|
2829
|
+
CacheManager.prototype.removeRefreshToken = function (key) {
|
|
2830
|
+
this.removeItem(key);
|
|
2942
2831
|
};
|
|
2943
2832
|
/**
|
|
2944
2833
|
* Retrieve AccessTokenEntity from cache
|
|
@@ -2947,8 +2836,10 @@ var CacheManager = /** @class */ (function () {
|
|
|
2947
2836
|
* @param scopes
|
|
2948
2837
|
* @param authScheme
|
|
2949
2838
|
*/
|
|
2950
|
-
CacheManager.prototype.
|
|
2951
|
-
var
|
|
2839
|
+
CacheManager.prototype.getAccessToken = function (account, request, tokenKeys) {
|
|
2840
|
+
var _this = this;
|
|
2841
|
+
this.commonLogger.trace("CacheManager - getAccessToken called");
|
|
2842
|
+
var scopes = ScopeSet.createSearchScopes(request.scopes);
|
|
2952
2843
|
var authScheme = request.authenticationScheme || exports.AuthenticationScheme.BEARER;
|
|
2953
2844
|
/*
|
|
2954
2845
|
* Distinguish between Bearer and PoP/SSH token cache types
|
|
@@ -2959,55 +2850,156 @@ var CacheManager = /** @class */ (function () {
|
|
|
2959
2850
|
homeAccountId: account.homeAccountId,
|
|
2960
2851
|
environment: account.environment,
|
|
2961
2852
|
credentialType: credentialType,
|
|
2962
|
-
clientId: clientId,
|
|
2853
|
+
clientId: this.clientId,
|
|
2963
2854
|
realm: account.tenantId,
|
|
2964
|
-
target: scopes
|
|
2855
|
+
target: scopes,
|
|
2965
2856
|
tokenType: authScheme,
|
|
2966
2857
|
keyId: request.sshKid,
|
|
2967
2858
|
requestedClaimsHash: request.requestedClaimsHash,
|
|
2968
2859
|
};
|
|
2969
|
-
var
|
|
2970
|
-
var accessTokens =
|
|
2860
|
+
var accessTokenKeys = tokenKeys && tokenKeys.accessToken || this.getTokenKeys().accessToken;
|
|
2861
|
+
var accessTokens = [];
|
|
2862
|
+
accessTokenKeys.forEach(function (key) {
|
|
2863
|
+
// Validate key
|
|
2864
|
+
if (_this.accessTokenKeyMatchesFilter(key, accessTokenFilter, true)) {
|
|
2865
|
+
var accessToken = _this.getAccessTokenCredential(key);
|
|
2866
|
+
// Validate value
|
|
2867
|
+
if (accessToken && _this.credentialMatchesFilter(accessToken, accessTokenFilter)) {
|
|
2868
|
+
accessTokens.push(accessToken);
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
});
|
|
2971
2872
|
var numAccessTokens = accessTokens.length;
|
|
2972
2873
|
if (numAccessTokens < 1) {
|
|
2874
|
+
this.commonLogger.info("CacheManager:getAccessToken - No token found");
|
|
2973
2875
|
return null;
|
|
2974
2876
|
}
|
|
2975
2877
|
else if (numAccessTokens > 1) {
|
|
2976
2878
|
throw ClientAuthError.createMultipleMatchingTokensInCacheError();
|
|
2977
2879
|
}
|
|
2880
|
+
this.commonLogger.info("CacheManager:getAccessToken - Returning access token");
|
|
2978
2881
|
return accessTokens[0];
|
|
2979
2882
|
};
|
|
2883
|
+
/**
|
|
2884
|
+
* Validate the cache key against filter before retrieving and parsing cache value
|
|
2885
|
+
* @param key
|
|
2886
|
+
* @param filter
|
|
2887
|
+
* @param keyMustContainAllScopes
|
|
2888
|
+
* @returns
|
|
2889
|
+
*/
|
|
2890
|
+
CacheManager.prototype.accessTokenKeyMatchesFilter = function (inputKey, filter, keyMustContainAllScopes) {
|
|
2891
|
+
var key = inputKey.toLowerCase();
|
|
2892
|
+
if (filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {
|
|
2893
|
+
return false;
|
|
2894
|
+
}
|
|
2895
|
+
if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
|
|
2896
|
+
return false;
|
|
2897
|
+
}
|
|
2898
|
+
if (filter.realm && key.indexOf(filter.realm.toLowerCase()) === -1) {
|
|
2899
|
+
return false;
|
|
2900
|
+
}
|
|
2901
|
+
if (filter.requestedClaimsHash && key.indexOf(filter.requestedClaimsHash.toLowerCase()) === -1) {
|
|
2902
|
+
return false;
|
|
2903
|
+
}
|
|
2904
|
+
if (filter.target) {
|
|
2905
|
+
var scopes = filter.target.asArray();
|
|
2906
|
+
for (var i = 0; i < scopes.length; i++) {
|
|
2907
|
+
if (keyMustContainAllScopes && !key.includes(scopes[i].toLowerCase())) {
|
|
2908
|
+
// When performing a cache lookup a missing scope would be a cache miss
|
|
2909
|
+
return false;
|
|
2910
|
+
}
|
|
2911
|
+
else if (!keyMustContainAllScopes && key.includes(scopes[i].toLowerCase())) {
|
|
2912
|
+
// When performing a cache write, any token with a subset of requested scopes should be replaced
|
|
2913
|
+
return true;
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
return true;
|
|
2918
|
+
};
|
|
2919
|
+
/**
|
|
2920
|
+
* Gets all access tokens matching the filter
|
|
2921
|
+
* @param filter
|
|
2922
|
+
* @returns
|
|
2923
|
+
*/
|
|
2924
|
+
CacheManager.prototype.getAccessTokensByFilter = function (filter) {
|
|
2925
|
+
var _this = this;
|
|
2926
|
+
var tokenKeys = this.getTokenKeys();
|
|
2927
|
+
var accessTokens = [];
|
|
2928
|
+
tokenKeys.accessToken.forEach(function (key) {
|
|
2929
|
+
if (!_this.accessTokenKeyMatchesFilter(key, filter, true)) {
|
|
2930
|
+
return;
|
|
2931
|
+
}
|
|
2932
|
+
var accessToken = _this.getAccessTokenCredential(key);
|
|
2933
|
+
if (accessToken && _this.credentialMatchesFilter(accessToken, filter)) {
|
|
2934
|
+
accessTokens.push(accessToken);
|
|
2935
|
+
}
|
|
2936
|
+
});
|
|
2937
|
+
return accessTokens;
|
|
2938
|
+
};
|
|
2980
2939
|
/**
|
|
2981
2940
|
* Helper to retrieve the appropriate refresh token from cache
|
|
2982
2941
|
* @param clientId
|
|
2983
2942
|
* @param account
|
|
2984
2943
|
* @param familyRT
|
|
2985
2944
|
*/
|
|
2986
|
-
CacheManager.prototype.
|
|
2945
|
+
CacheManager.prototype.getRefreshToken = function (account, familyRT, tokenKeys) {
|
|
2946
|
+
var _this = this;
|
|
2947
|
+
this.commonLogger.trace("CacheManager - getRefreshToken called");
|
|
2987
2948
|
var id = familyRT ? THE_FAMILY_ID : undefined;
|
|
2988
2949
|
var refreshTokenFilter = {
|
|
2989
2950
|
homeAccountId: account.homeAccountId,
|
|
2990
2951
|
environment: account.environment,
|
|
2991
2952
|
credentialType: exports.CredentialType.REFRESH_TOKEN,
|
|
2992
|
-
clientId: clientId,
|
|
2953
|
+
clientId: this.clientId,
|
|
2993
2954
|
familyId: id,
|
|
2994
2955
|
};
|
|
2995
|
-
var
|
|
2996
|
-
var refreshTokens =
|
|
2956
|
+
var refreshTokenKeys = tokenKeys && tokenKeys.refreshToken || this.getTokenKeys().refreshToken;
|
|
2957
|
+
var refreshTokens = [];
|
|
2958
|
+
refreshTokenKeys.forEach(function (key) {
|
|
2959
|
+
// Validate key
|
|
2960
|
+
if (_this.refreshTokenKeyMatchesFilter(key, refreshTokenFilter)) {
|
|
2961
|
+
var refreshToken = _this.getRefreshTokenCredential(key);
|
|
2962
|
+
// Validate value
|
|
2963
|
+
if (refreshToken && _this.credentialMatchesFilter(refreshToken, refreshTokenFilter)) {
|
|
2964
|
+
refreshTokens.push(refreshToken);
|
|
2965
|
+
}
|
|
2966
|
+
}
|
|
2967
|
+
});
|
|
2997
2968
|
var numRefreshTokens = refreshTokens.length;
|
|
2998
2969
|
if (numRefreshTokens < 1) {
|
|
2970
|
+
this.commonLogger.info("CacheManager:getRefreshToken - No refresh token found.");
|
|
2999
2971
|
return null;
|
|
3000
2972
|
}
|
|
3001
2973
|
// address the else case after remove functions address environment aliases
|
|
2974
|
+
this.commonLogger.info("CacheManager:getRefreshToken - returning refresh token");
|
|
3002
2975
|
return refreshTokens[0];
|
|
3003
2976
|
};
|
|
2977
|
+
/**
|
|
2978
|
+
* Validate the cache key against filter before retrieving and parsing cache value
|
|
2979
|
+
* @param key
|
|
2980
|
+
* @param filter
|
|
2981
|
+
*/
|
|
2982
|
+
CacheManager.prototype.refreshTokenKeyMatchesFilter = function (inputKey, filter) {
|
|
2983
|
+
var key = inputKey.toLowerCase();
|
|
2984
|
+
if (filter.familyId && key.indexOf(filter.familyId.toLowerCase()) === -1) {
|
|
2985
|
+
return false;
|
|
2986
|
+
}
|
|
2987
|
+
// If familyId is used, clientId is not in the key
|
|
2988
|
+
if (!filter.familyId && filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {
|
|
2989
|
+
return false;
|
|
2990
|
+
}
|
|
2991
|
+
if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
|
|
2992
|
+
return false;
|
|
2993
|
+
}
|
|
2994
|
+
return true;
|
|
2995
|
+
};
|
|
3004
2996
|
/**
|
|
3005
2997
|
* Retrieve AppMetadataEntity from cache
|
|
3006
2998
|
*/
|
|
3007
|
-
CacheManager.prototype.readAppMetadataFromCache = function (environment
|
|
2999
|
+
CacheManager.prototype.readAppMetadataFromCache = function (environment) {
|
|
3008
3000
|
var appMetadataFilter = {
|
|
3009
3001
|
environment: environment,
|
|
3010
|
-
clientId: clientId,
|
|
3002
|
+
clientId: this.clientId,
|
|
3011
3003
|
};
|
|
3012
3004
|
var appMetadata = this.getAppMetadataFilteredBy(appMetadataFilter);
|
|
3013
3005
|
var appMetadataEntries = Object.keys(appMetadata).map(function (key) { return appMetadata[key]; });
|
|
@@ -3025,8 +3017,8 @@ var CacheManager = /** @class */ (function () {
|
|
|
3025
3017
|
* @param environment
|
|
3026
3018
|
* @param clientId
|
|
3027
3019
|
*/
|
|
3028
|
-
CacheManager.prototype.isAppMetadataFOCI = function (environment
|
|
3029
|
-
var appMetadata = this.readAppMetadataFromCache(environment
|
|
3020
|
+
CacheManager.prototype.isAppMetadataFOCI = function (environment) {
|
|
3021
|
+
var appMetadata = this.readAppMetadataFromCache(environment);
|
|
3030
3022
|
return !!(appMetadata && appMetadata.familyId === THE_FAMILY_ID);
|
|
3031
3023
|
};
|
|
3032
3024
|
/**
|
|
@@ -3037,6 +3029,24 @@ var CacheManager = /** @class */ (function () {
|
|
|
3037
3029
|
CacheManager.prototype.matchHomeAccountId = function (entity, homeAccountId) {
|
|
3038
3030
|
return !!((typeof entity.homeAccountId === "string") && (homeAccountId === entity.homeAccountId));
|
|
3039
3031
|
};
|
|
3032
|
+
/**
|
|
3033
|
+
* helper to match account ids
|
|
3034
|
+
* @param entity
|
|
3035
|
+
* @param localAccountId
|
|
3036
|
+
* @returns
|
|
3037
|
+
*/
|
|
3038
|
+
CacheManager.prototype.matchLocalAccountId = function (entity, localAccountId) {
|
|
3039
|
+
return !!((typeof entity.localAccountId === "string") && (localAccountId === entity.localAccountId));
|
|
3040
|
+
};
|
|
3041
|
+
/**
|
|
3042
|
+
* helper to match usernames
|
|
3043
|
+
* @param entity
|
|
3044
|
+
* @param username
|
|
3045
|
+
* @returns
|
|
3046
|
+
*/
|
|
3047
|
+
CacheManager.prototype.matchUsername = function (entity, username) {
|
|
3048
|
+
return !!((typeof entity.username === "string") && (username.toLowerCase() === entity.username.toLowerCase()));
|
|
3049
|
+
};
|
|
3040
3050
|
/**
|
|
3041
3051
|
* helper to match assertion
|
|
3042
3052
|
* @param value
|
|
@@ -3109,14 +3119,7 @@ var CacheManager = /** @class */ (function () {
|
|
|
3109
3119
|
return false;
|
|
3110
3120
|
}
|
|
3111
3121
|
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);
|
|
3122
|
+
return entityScopeSet.containsScopeSet(target);
|
|
3120
3123
|
};
|
|
3121
3124
|
/**
|
|
3122
3125
|
* Returns true if the credential's tokenType or Authentication Scheme matches the one in the request, false otherwise
|
|
@@ -3154,27 +3157,6 @@ var CacheManager = /** @class */ (function () {
|
|
|
3154
3157
|
CacheManager.prototype.generateAuthorityMetadataCacheKey = function (authority) {
|
|
3155
3158
|
return AUTHORITY_METADATA_CONSTANTS.CACHE_KEY + "-" + this.clientId + "-" + authority;
|
|
3156
3159
|
};
|
|
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
3160
|
/**
|
|
3179
3161
|
* Helper to convert serialized data to object
|
|
3180
3162
|
* @param obj
|
|
@@ -3273,6 +3255,14 @@ var DefaultStorageClass = /** @class */ (function (_super) {
|
|
|
3273
3255
|
var notImplErr = "Storage interface - getKeys() has not been implemented for the cacheStorage interface.";
|
|
3274
3256
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
3275
3257
|
};
|
|
3258
|
+
DefaultStorageClass.prototype.getAccountKeys = function () {
|
|
3259
|
+
var notImplErr = "Storage interface - getAccountKeys() has not been implemented for the cacheStorage interface.";
|
|
3260
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
3261
|
+
};
|
|
3262
|
+
DefaultStorageClass.prototype.getTokenKeys = function () {
|
|
3263
|
+
var notImplErr = "Storage interface - getTokenKeys() has not been implemented for the cacheStorage interface.";
|
|
3264
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
3265
|
+
};
|
|
3276
3266
|
DefaultStorageClass.prototype.clear = function () {
|
|
3277
3267
|
return __awaiter(this, void 0, void 0, function () {
|
|
3278
3268
|
var notImplErr;
|
|
@@ -3361,7 +3351,7 @@ function buildClientConfiguration(_a) {
|
|
|
3361
3351
|
authOptions: buildAuthOptions(userAuthOptions),
|
|
3362
3352
|
systemOptions: __assign(__assign({}, DEFAULT_SYSTEM_OPTIONS), userSystemOptions),
|
|
3363
3353
|
loggerOptions: loggerOptions,
|
|
3364
|
-
storageInterface: storageImplementation || new DefaultStorageClass(userAuthOptions.clientId, DEFAULT_CRYPTO_IMPLEMENTATION),
|
|
3354
|
+
storageInterface: storageImplementation || new DefaultStorageClass(userAuthOptions.clientId, DEFAULT_CRYPTO_IMPLEMENTATION, new Logger(loggerOptions)),
|
|
3365
3355
|
networkInterface: networkImplementation || DEFAULT_NETWORK_IMPLEMENTATION,
|
|
3366
3356
|
cryptoInterface: cryptoImplementation || DEFAULT_CRYPTO_IMPLEMENTATION,
|
|
3367
3357
|
clientCredentials: clientCredentials || DEFAULT_CLIENT_CREDENTIALS,
|
|
@@ -3423,7 +3413,7 @@ var ThrottlingUtils = /** @class */ (function () {
|
|
|
3423
3413
|
var value = cacheManager.getThrottlingCache(key);
|
|
3424
3414
|
if (value) {
|
|
3425
3415
|
if (value.throttleTime < Date.now()) {
|
|
3426
|
-
cacheManager.removeItem(key
|
|
3416
|
+
cacheManager.removeItem(key);
|
|
3427
3417
|
return;
|
|
3428
3418
|
}
|
|
3429
3419
|
throw new ServerError(((_a = value.errorCodes) === null || _a === void 0 ? void 0 : _a.join(" ")) || Constants.EMPTY_STRING, value.errorMessage, value.subError);
|
|
@@ -3487,7 +3477,7 @@ var ThrottlingUtils = /** @class */ (function () {
|
|
|
3487
3477
|
sshKid: request.sshKid
|
|
3488
3478
|
};
|
|
3489
3479
|
var key = this.generateThrottlingStorageKey(thumbprint);
|
|
3490
|
-
|
|
3480
|
+
cacheManager.removeItem(key);
|
|
3491
3481
|
};
|
|
3492
3482
|
return ThrottlingUtils;
|
|
3493
3483
|
}());
|
|
@@ -4114,6 +4104,142 @@ var BaseClient = /** @class */ (function () {
|
|
|
4114
4104
|
return BaseClient;
|
|
4115
4105
|
}());
|
|
4116
4106
|
|
|
4107
|
+
/*
|
|
4108
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4109
|
+
* Licensed under the MIT License.
|
|
4110
|
+
*/
|
|
4111
|
+
/**
|
|
4112
|
+
* Base type for credentials to be stored in the cache: eg: ACCESS_TOKEN, ID_TOKEN etc
|
|
4113
|
+
*
|
|
4114
|
+
* Key:Value Schema:
|
|
4115
|
+
*
|
|
4116
|
+
* Key: <home_account_id*>-<environment>-<credential_type>-<client_id>-<realm*>-<target*>-<requestedClaims*>-<scheme*>
|
|
4117
|
+
*
|
|
4118
|
+
* Value Schema:
|
|
4119
|
+
* {
|
|
4120
|
+
* homeAccountId: home account identifier for the auth scheme,
|
|
4121
|
+
* environment: entity that issued the token, represented as a full host
|
|
4122
|
+
* credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
|
|
4123
|
+
* clientId: client ID of the application
|
|
4124
|
+
* secret: Actual credential as a string
|
|
4125
|
+
* familyId: Family ID identifier, usually only used for refresh tokens
|
|
4126
|
+
* realm: Full tenant or organizational identifier that the account belongs to
|
|
4127
|
+
* target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
|
|
4128
|
+
* tokenType: Matches the authentication scheme for which the token was issued (i.e. Bearer or pop)
|
|
4129
|
+
* requestedClaimsHash: Matches the SHA 256 hash of the claims object included in the token request
|
|
4130
|
+
* userAssertionHash: Matches the SHA 256 hash of the obo_assertion for the OBO flow
|
|
4131
|
+
* }
|
|
4132
|
+
*/
|
|
4133
|
+
var CredentialEntity = /** @class */ (function () {
|
|
4134
|
+
function CredentialEntity() {
|
|
4135
|
+
}
|
|
4136
|
+
/**
|
|
4137
|
+
* Generate Account Id key component as per the schema: <home_account_id>-<environment>
|
|
4138
|
+
*/
|
|
4139
|
+
CredentialEntity.prototype.generateAccountId = function () {
|
|
4140
|
+
return CredentialEntity.generateAccountIdForCacheKey(this.homeAccountId, this.environment);
|
|
4141
|
+
};
|
|
4142
|
+
/**
|
|
4143
|
+
* Generate Credential Id key component as per the schema: <credential_type>-<client_id>-<realm>
|
|
4144
|
+
*/
|
|
4145
|
+
CredentialEntity.prototype.generateCredentialId = function () {
|
|
4146
|
+
return CredentialEntity.generateCredentialIdForCacheKey(this.credentialType, this.clientId, this.realm, this.familyId);
|
|
4147
|
+
};
|
|
4148
|
+
/**
|
|
4149
|
+
* Generate target key component as per schema: <target>
|
|
4150
|
+
*/
|
|
4151
|
+
CredentialEntity.prototype.generateTarget = function () {
|
|
4152
|
+
return CredentialEntity.generateTargetForCacheKey(this.target);
|
|
4153
|
+
};
|
|
4154
|
+
/**
|
|
4155
|
+
* generates credential key
|
|
4156
|
+
*/
|
|
4157
|
+
CredentialEntity.prototype.generateCredentialKey = function () {
|
|
4158
|
+
return CredentialEntity.generateCredentialCacheKey(this.homeAccountId, this.environment, this.credentialType, this.clientId, this.realm, this.target, this.familyId, this.tokenType, this.requestedClaimsHash);
|
|
4159
|
+
};
|
|
4160
|
+
/**
|
|
4161
|
+
* returns the type of the cache (in this case credential)
|
|
4162
|
+
*/
|
|
4163
|
+
CredentialEntity.prototype.generateType = function () {
|
|
4164
|
+
switch (this.credentialType) {
|
|
4165
|
+
case exports.CredentialType.ID_TOKEN:
|
|
4166
|
+
return exports.CacheType.ID_TOKEN;
|
|
4167
|
+
case exports.CredentialType.ACCESS_TOKEN:
|
|
4168
|
+
case exports.CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
|
|
4169
|
+
return exports.CacheType.ACCESS_TOKEN;
|
|
4170
|
+
case exports.CredentialType.REFRESH_TOKEN:
|
|
4171
|
+
return exports.CacheType.REFRESH_TOKEN;
|
|
4172
|
+
default: {
|
|
4173
|
+
throw ClientAuthError.createUnexpectedCredentialTypeError();
|
|
4174
|
+
}
|
|
4175
|
+
}
|
|
4176
|
+
};
|
|
4177
|
+
/**
|
|
4178
|
+
* generates credential key
|
|
4179
|
+
* <home_account_id*>-\<environment>-<credential_type>-<client_id>-<realm\*>-<target\*>-<scheme\*>
|
|
4180
|
+
*/
|
|
4181
|
+
CredentialEntity.generateCredentialCacheKey = function (homeAccountId, environment, credentialType, clientId, realm, target, familyId, tokenType, requestedClaimsHash) {
|
|
4182
|
+
var credentialKey = [
|
|
4183
|
+
this.generateAccountIdForCacheKey(homeAccountId, environment),
|
|
4184
|
+
this.generateCredentialIdForCacheKey(credentialType, clientId, realm, familyId),
|
|
4185
|
+
this.generateTargetForCacheKey(target),
|
|
4186
|
+
this.generateClaimsHashForCacheKey(requestedClaimsHash),
|
|
4187
|
+
this.generateSchemeForCacheKey(tokenType)
|
|
4188
|
+
];
|
|
4189
|
+
return credentialKey.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
|
|
4190
|
+
};
|
|
4191
|
+
/**
|
|
4192
|
+
* generates Account Id for keys
|
|
4193
|
+
* @param homeAccountId
|
|
4194
|
+
* @param environment
|
|
4195
|
+
*/
|
|
4196
|
+
CredentialEntity.generateAccountIdForCacheKey = function (homeAccountId, environment) {
|
|
4197
|
+
var accountId = [homeAccountId, environment];
|
|
4198
|
+
return accountId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
|
|
4199
|
+
};
|
|
4200
|
+
/**
|
|
4201
|
+
* Generates Credential Id for keys
|
|
4202
|
+
* @param credentialType
|
|
4203
|
+
* @param realm
|
|
4204
|
+
* @param clientId
|
|
4205
|
+
* @param familyId
|
|
4206
|
+
*/
|
|
4207
|
+
CredentialEntity.generateCredentialIdForCacheKey = function (credentialType, clientId, realm, familyId) {
|
|
4208
|
+
var clientOrFamilyId = credentialType === exports.CredentialType.REFRESH_TOKEN
|
|
4209
|
+
? familyId || clientId
|
|
4210
|
+
: clientId;
|
|
4211
|
+
var credentialId = [
|
|
4212
|
+
credentialType,
|
|
4213
|
+
clientOrFamilyId,
|
|
4214
|
+
realm || Constants.EMPTY_STRING,
|
|
4215
|
+
];
|
|
4216
|
+
return credentialId.join(Separators.CACHE_KEY_SEPARATOR).toLowerCase();
|
|
4217
|
+
};
|
|
4218
|
+
/**
|
|
4219
|
+
* Generate target key component as per schema: <target>
|
|
4220
|
+
*/
|
|
4221
|
+
CredentialEntity.generateTargetForCacheKey = function (scopes) {
|
|
4222
|
+
return (scopes || Constants.EMPTY_STRING).toLowerCase();
|
|
4223
|
+
};
|
|
4224
|
+
/**
|
|
4225
|
+
* Generate requested claims key component as per schema: <requestedClaims>
|
|
4226
|
+
*/
|
|
4227
|
+
CredentialEntity.generateClaimsHashForCacheKey = function (requestedClaimsHash) {
|
|
4228
|
+
return (requestedClaimsHash || Constants.EMPTY_STRING).toLowerCase();
|
|
4229
|
+
};
|
|
4230
|
+
/**
|
|
4231
|
+
* Generate scheme key componenet as per schema: <scheme>
|
|
4232
|
+
*/
|
|
4233
|
+
CredentialEntity.generateSchemeForCacheKey = function (tokenType) {
|
|
4234
|
+
/*
|
|
4235
|
+
* PoP Tokens and SSH certs include scheme in cache key
|
|
4236
|
+
* Cast to lowercase to handle "bearer" from ADFS
|
|
4237
|
+
*/
|
|
4238
|
+
return (tokenType && tokenType.toLowerCase() !== exports.AuthenticationScheme.BEARER.toLowerCase()) ? tokenType.toLowerCase() : Constants.EMPTY_STRING;
|
|
4239
|
+
};
|
|
4240
|
+
return CredentialEntity;
|
|
4241
|
+
}());
|
|
4242
|
+
|
|
4117
4243
|
/*
|
|
4118
4244
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4119
4245
|
* Licensed under the MIT License.
|
|
@@ -6307,7 +6433,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
|
|
|
6307
6433
|
if (!request.account) {
|
|
6308
6434
|
throw ClientAuthError.createNoAccountInSilentRequestError();
|
|
6309
6435
|
}
|
|
6310
|
-
isFOCI = this.cacheManager.isAppMetadataFOCI(request.account.environment
|
|
6436
|
+
isFOCI = this.cacheManager.isAppMetadataFOCI(request.account.environment);
|
|
6311
6437
|
// if the app is part of the family, retrive a Family refresh token if present and make a refreshTokenRequest
|
|
6312
6438
|
if (isFOCI) {
|
|
6313
6439
|
try {
|
|
@@ -6346,7 +6472,7 @@ var RefreshTokenClient = /** @class */ (function (_super) {
|
|
|
6346
6472
|
(_a = this.performanceClient) === null || _a === void 0 ? void 0 : _a.addQueueMeasurement(exports.PerformanceEvents.RefreshTokenClientAcquireTokenWithCachedRefreshToken, request.correlationId);
|
|
6347
6473
|
atsMeasurement = (_b = this.performanceClient) === null || _b === void 0 ? void 0 : _b.startMeasurement(exports.PerformanceEvents.RefreshTokenClientAcquireTokenWithCachedRefreshToken, request.correlationId);
|
|
6348
6474
|
this.logger.verbose("RefreshTokenClientAcquireTokenWithCachedRefreshToken called", request.correlationId);
|
|
6349
|
-
refreshToken = this.cacheManager.
|
|
6475
|
+
refreshToken = this.cacheManager.getRefreshToken(request.account, foci);
|
|
6350
6476
|
if (!refreshToken) {
|
|
6351
6477
|
atsMeasurement === null || atsMeasurement === void 0 ? void 0 : atsMeasurement.discardMeasurement();
|
|
6352
6478
|
throw InteractionRequiredAuthError.createNoTokensFoundError();
|
|
@@ -6573,7 +6699,6 @@ var ClientCredentialClient = /** @class */ (function (_super) {
|
|
|
6573
6699
|
};
|
|
6574
6700
|
/**
|
|
6575
6701
|
* Reads access token from the cache
|
|
6576
|
-
* TODO: Move this call to cacheManager instead
|
|
6577
6702
|
*/
|
|
6578
6703
|
ClientCredentialClient.prototype.readAccessTokenFromCache = function () {
|
|
6579
6704
|
var accessTokenFilter = {
|
|
@@ -6582,10 +6707,9 @@ var ClientCredentialClient = /** @class */ (function (_super) {
|
|
|
6582
6707
|
credentialType: exports.CredentialType.ACCESS_TOKEN,
|
|
6583
6708
|
clientId: this.config.authOptions.clientId,
|
|
6584
6709
|
realm: this.authority.tenant,
|
|
6585
|
-
target: this.scopeSet.
|
|
6710
|
+
target: ScopeSet.createSearchScopes(this.scopeSet.asArray())
|
|
6586
6711
|
};
|
|
6587
|
-
var
|
|
6588
|
-
var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
|
|
6712
|
+
var accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
|
|
6589
6713
|
if (accessTokens.length < 1) {
|
|
6590
6714
|
return null;
|
|
6591
6715
|
}
|
|
@@ -6766,7 +6890,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
|
|
|
6766
6890
|
this.logger.info("OnbehalfofFlow:getCachedAuthenticationResult - Cached access token is expired or will expire within " + this.config.systemOptions.tokenRenewalOffsetSeconds + " seconds.");
|
|
6767
6891
|
throw ClientAuthError.createRefreshRequiredError();
|
|
6768
6892
|
}
|
|
6769
|
-
cachedIdToken = this.readIdTokenFromCacheForOBO(
|
|
6893
|
+
cachedIdToken = this.readIdTokenFromCacheForOBO(cachedAccessToken.homeAccountId);
|
|
6770
6894
|
cachedAccount = null;
|
|
6771
6895
|
if (cachedIdToken) {
|
|
6772
6896
|
idTokenObject = new AuthToken(cachedIdToken.secret, this.config.cryptoInterface);
|
|
@@ -6801,7 +6925,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
|
|
|
6801
6925
|
* Certain use cases of OBO flow do not expect an idToken in the cache/or from the service
|
|
6802
6926
|
* @param request
|
|
6803
6927
|
*/
|
|
6804
|
-
OnBehalfOfClient.prototype.readIdTokenFromCacheForOBO = function (
|
|
6928
|
+
OnBehalfOfClient.prototype.readIdTokenFromCacheForOBO = function (atHomeAccountId) {
|
|
6805
6929
|
var idTokenFilter = {
|
|
6806
6930
|
homeAccountId: atHomeAccountId,
|
|
6807
6931
|
environment: this.authority.canonicalAuthorityUrlComponents.HostNameAndPort,
|
|
@@ -6809,8 +6933,7 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
|
|
|
6809
6933
|
clientId: this.config.authOptions.clientId,
|
|
6810
6934
|
realm: this.authority.tenant
|
|
6811
6935
|
};
|
|
6812
|
-
var
|
|
6813
|
-
var idTokens = Object.keys(credentialCache.idTokens).map(function (key) { return credentialCache.idTokens[key]; });
|
|
6936
|
+
var idTokens = this.cacheManager.getIdTokensByFilter(idTokenFilter);
|
|
6814
6937
|
// When acquiring a token on behalf of an application, there might not be an id token in the cache
|
|
6815
6938
|
if (idTokens.length < 1) {
|
|
6816
6939
|
return null;
|
|
@@ -6833,14 +6956,13 @@ var OnBehalfOfClient = /** @class */ (function (_super) {
|
|
|
6833
6956
|
var accessTokenFilter = {
|
|
6834
6957
|
credentialType: credentialType,
|
|
6835
6958
|
clientId: clientId,
|
|
6836
|
-
target: this.scopeSet.
|
|
6959
|
+
target: ScopeSet.createSearchScopes(this.scopeSet.asArray()),
|
|
6837
6960
|
tokenType: authScheme,
|
|
6838
6961
|
keyId: request.sshKid,
|
|
6839
6962
|
requestedClaimsHash: request.requestedClaimsHash,
|
|
6840
6963
|
userAssertionHash: this.userAssertionHash
|
|
6841
6964
|
};
|
|
6842
|
-
var
|
|
6843
|
-
var accessTokens = Object.keys(credentialCache.accessTokens).map(function (key) { return credentialCache.accessTokens[key]; });
|
|
6965
|
+
var accessTokens = this.cacheManager.getAccessTokensByFilter(accessTokenFilter);
|
|
6844
6966
|
var numAccessTokens = accessTokens.length;
|
|
6845
6967
|
if (numAccessTokens < 1) {
|
|
6846
6968
|
return null;
|
|
@@ -6989,7 +7111,7 @@ var SilentFlowClient = /** @class */ (function (_super) {
|
|
|
6989
7111
|
throw ClientAuthError.createNoAccountInSilentRequestError();
|
|
6990
7112
|
}
|
|
6991
7113
|
environment = request.authority || this.authority.getPreferredCache();
|
|
6992
|
-
cacheRecord = this.cacheManager.readCacheRecord(request.account,
|
|
7114
|
+
cacheRecord = this.cacheManager.readCacheRecord(request.account, request, environment);
|
|
6993
7115
|
if (!cacheRecord.accessToken) {
|
|
6994
7116
|
// Must refresh due to non-existent access_token.
|
|
6995
7117
|
(_b = this.serverTelemetryManager) === null || _b === void 0 ? void 0 : _b.setCacheOutcome(CacheOutcome.NO_CACHED_ACCESS_TOKEN);
|
|
@@ -7442,6 +7564,10 @@ var Authority = /** @class */ (function () {
|
|
|
7442
7564
|
Object.defineProperty(Authority.prototype, "authorityType", {
|
|
7443
7565
|
// See above for AuthorityType
|
|
7444
7566
|
get: function () {
|
|
7567
|
+
// CIAM auth url pattern is being standardized as: <tenant>.ciamlogin.com
|
|
7568
|
+
if (this.canonicalAuthorityUrlComponents.HostNameAndPort.endsWith(Constants.CIAM_AUTH_URL)) {
|
|
7569
|
+
return exports.AuthorityType.Ciam;
|
|
7570
|
+
}
|
|
7445
7571
|
var pathSegments = this.canonicalAuthorityUrlComponents.PathSegments;
|
|
7446
7572
|
if (pathSegments.length) {
|
|
7447
7573
|
switch (pathSegments[0].toLowerCase()) {
|
|
@@ -7729,7 +7855,6 @@ var Authority = /** @class */ (function () {
|
|
|
7729
7855
|
// No need to update
|
|
7730
7856
|
return [2 /*return*/, AuthorityMetadataSource.CACHE];
|
|
7731
7857
|
}
|
|
7732
|
-
harcodedMetadata = this.getEndpointMetadataFromHardcodedValues();
|
|
7733
7858
|
(_b = this.performanceClient) === null || _b === void 0 ? void 0 : _b.setPreQueueTime(exports.PerformanceEvents.AuthorityGetEndpointMetadataFromNetwork, this.correlationId);
|
|
7734
7859
|
return [4 /*yield*/, this.getEndpointMetadataFromNetwork()];
|
|
7735
7860
|
case 1:
|
|
@@ -7745,6 +7870,7 @@ var Authority = /** @class */ (function () {
|
|
|
7745
7870
|
metadataEntity.updateEndpointMetadata(metadata, true);
|
|
7746
7871
|
return [2 /*return*/, AuthorityMetadataSource.NETWORK];
|
|
7747
7872
|
case 4:
|
|
7873
|
+
harcodedMetadata = this.getEndpointMetadataFromHardcodedValues();
|
|
7748
7874
|
if (!(harcodedMetadata && !this.authorityOptions.skipAuthorityMetadataCache)) return [3 /*break*/, 7];
|
|
7749
7875
|
if (!((_e = this.authorityOptions.azureRegionConfiguration) === null || _e === void 0 ? void 0 : _e.azureRegion)) return [3 /*break*/, 6];
|
|
7750
7876
|
(_f = this.performanceClient) === null || _f === void 0 ? void 0 : _f.setPreQueueTime(exports.PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation, this.correlationId);
|
|
@@ -7869,8 +7995,8 @@ var Authority = /** @class */ (function () {
|
|
|
7869
7995
|
/**
|
|
7870
7996
|
* Updates the AuthorityMetadataEntity with new aliases, preferred_network and preferred_cache
|
|
7871
7997
|
* and returns where the information was retrieved from
|
|
7872
|
-
* @param
|
|
7873
|
-
* @
|
|
7998
|
+
* @param metadataEntity
|
|
7999
|
+
* @returns AuthorityMetadataSource
|
|
7874
8000
|
*/
|
|
7875
8001
|
Authority.prototype.updateCloudDiscoveryMetadata = function (metadataEntity) {
|
|
7876
8002
|
var _a, _b;
|
|
@@ -7880,6 +8006,7 @@ var Authority = /** @class */ (function () {
|
|
|
7880
8006
|
switch (_c.label) {
|
|
7881
8007
|
case 0:
|
|
7882
8008
|
(_a = this.performanceClient) === null || _a === void 0 ? void 0 : _a.addQueueMeasurement(exports.PerformanceEvents.AuthorityUpdateCloudDiscoveryMetadata, this.correlationId);
|
|
8009
|
+
// attempt to read metadata from the config
|
|
7883
8010
|
this.logger.verbose("Attempting to get cloud discovery metadata in the config");
|
|
7884
8011
|
this.logger.verbosePii("Known Authorities: " + (this.authorityOptions.knownAuthorities || Constants.NOT_APPLICABLE));
|
|
7885
8012
|
this.logger.verbosePii("Authority Metadata: " + (this.authorityOptions.authorityMetadata || Constants.NOT_APPLICABLE));
|
|
@@ -7929,6 +8056,11 @@ var Authority = /** @class */ (function () {
|
|
|
7929
8056
|
* Parse cloudDiscoveryMetadata config or check knownAuthorities
|
|
7930
8057
|
*/
|
|
7931
8058
|
Authority.prototype.getCloudDiscoveryMetadataFromConfig = function () {
|
|
8059
|
+
// CIAM does not support cloud discovery metadata
|
|
8060
|
+
if (this.authorityType === exports.AuthorityType.Ciam) {
|
|
8061
|
+
this.logger.verbose("CIAM authorities do not support cloud discovery metadata, generate the aliases from authority host.");
|
|
8062
|
+
return Authority.createCloudDiscoveryMetadataFromHost(this.hostnameAndPort);
|
|
8063
|
+
}
|
|
7932
8064
|
// Check if network response was provided in config
|
|
7933
8065
|
if (this.authorityOptions.cloudDiscoveryMetadata) {
|
|
7934
8066
|
this.logger.verbose("The cloud discovery metadata has been provided as a network response, in the config.");
|
|
@@ -8148,6 +8280,26 @@ var Authority = /** @class */ (function () {
|
|
|
8148
8280
|
}
|
|
8149
8281
|
return metadata;
|
|
8150
8282
|
};
|
|
8283
|
+
/**
|
|
8284
|
+
* Transform CIAM_AUTHORIY as per the below rules:
|
|
8285
|
+
* If no path segments found and it is a CIAM authority (hostname ends with .ciamlogin.com), then transform it
|
|
8286
|
+
*
|
|
8287
|
+
* NOTE: The transformation path should go away once STS supports CIAM with the format: `tenantIdorDomain.ciamlogin.com`
|
|
8288
|
+
* `ciamlogin.com` can also change in the future and we should accommodate the same
|
|
8289
|
+
*
|
|
8290
|
+
* @param authority
|
|
8291
|
+
*/
|
|
8292
|
+
Authority.transformCIAMAuthority = function (authority) {
|
|
8293
|
+
var ciamAuthority = authority;
|
|
8294
|
+
var authorityUrl = new UrlString(authority);
|
|
8295
|
+
var authorityUrlComponents = authorityUrl.getUrlComponents();
|
|
8296
|
+
// check if transformation is needed
|
|
8297
|
+
if (authorityUrlComponents.PathSegments.length === 0 && (authorityUrlComponents.HostNameAndPort.endsWith(Constants.CIAM_AUTH_URL))) {
|
|
8298
|
+
var tenantIdOrDomain = authorityUrlComponents.HostNameAndPort.split(".")[0];
|
|
8299
|
+
ciamAuthority = "" + ciamAuthority + tenantIdOrDomain + Constants.AAD_TENANT_DOMAIN_SUFFIX;
|
|
8300
|
+
}
|
|
8301
|
+
return ciamAuthority;
|
|
8302
|
+
};
|
|
8151
8303
|
return Authority;
|
|
8152
8304
|
}());
|
|
8153
8305
|
|
|
@@ -8170,12 +8322,13 @@ var AuthorityFactory = /** @class */ (function () {
|
|
|
8170
8322
|
*/
|
|
8171
8323
|
AuthorityFactory.createDiscoveredInstance = function (authorityUri, networkClient, cacheManager, authorityOptions, logger, performanceClient, correlationId) {
|
|
8172
8324
|
return __awaiter(this, void 0, void 0, function () {
|
|
8173
|
-
var acquireTokenAuthority, e_1;
|
|
8325
|
+
var authorityUriFinal, acquireTokenAuthority, e_1;
|
|
8174
8326
|
return __generator(this, function (_a) {
|
|
8175
8327
|
switch (_a.label) {
|
|
8176
8328
|
case 0:
|
|
8177
8329
|
performanceClient === null || performanceClient === void 0 ? void 0 : performanceClient.addQueueMeasurement(exports.PerformanceEvents.AuthorityFactoryCreateDiscoveredInstance, correlationId);
|
|
8178
|
-
|
|
8330
|
+
authorityUriFinal = Authority.transformCIAMAuthority(authorityUri);
|
|
8331
|
+
acquireTokenAuthority = AuthorityFactory.createInstance(authorityUriFinal, networkClient, cacheManager, authorityOptions, logger, performanceClient, correlationId);
|
|
8179
8332
|
_a.label = 1;
|
|
8180
8333
|
case 1:
|
|
8181
8334
|
_a.trys.push([1, 3, , 4]);
|