@azure/msal-common 13.0.0 → 14.0.0-alpha.1
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/LICENSE +21 -21
- package/README.md +62 -62
- package/dist/account/AccountInfo.d.ts +2 -2
- package/dist/account/AccountInfo.d.ts.map +1 -1
- package/dist/account/AuthToken.d.ts.map +1 -1
- package/dist/account/AuthToken.js +13 -14
- package/dist/account/AuthToken.js.map +1 -1
- package/dist/account/CcsCredential.d.ts +1 -1
- package/dist/account/CcsCredential.d.ts.map +1 -1
- package/dist/account/CcsCredential.js +1 -1
- package/dist/account/CcsCredential.js.map +1 -1
- package/dist/account/ClientCredentials.d.ts +2 -2
- package/dist/account/ClientCredentials.d.ts.map +1 -1
- package/dist/account/ClientInfo.d.ts +1 -1
- package/dist/account/ClientInfo.d.ts.map +1 -1
- package/dist/account/ClientInfo.js +6 -4
- package/dist/account/ClientInfo.js.map +1 -1
- package/dist/account/DecodedAuthToken.d.ts.map +1 -1
- package/dist/account/TokenClaims.d.ts +1 -1
- package/dist/account/TokenClaims.d.ts.map +1 -1
- package/dist/authority/Authority.d.ts.map +1 -1
- package/dist/authority/Authority.js +464 -546
- package/dist/authority/Authority.js.map +1 -1
- package/dist/authority/AuthorityFactory.d.ts.map +1 -1
- package/dist/authority/AuthorityFactory.js +19 -34
- package/dist/authority/AuthorityFactory.js.map +1 -1
- package/dist/authority/AuthorityMetadata.d.ts.map +1 -1
- package/dist/authority/AuthorityMetadata.js +873 -4
- package/dist/authority/AuthorityMetadata.js.map +1 -1
- package/dist/authority/AuthorityOptions.d.ts +1 -1
- package/dist/authority/AuthorityOptions.d.ts.map +1 -1
- package/dist/authority/AuthorityOptions.js +1 -1
- package/dist/authority/AuthorityOptions.js.map +1 -1
- package/dist/authority/AuthorityType.js +1 -1
- package/dist/authority/AuthorityType.js.map +1 -1
- package/dist/authority/AzureRegion.d.ts +1 -1
- package/dist/authority/AzureRegion.d.ts.map +1 -1
- package/dist/authority/AzureRegionConfiguration.d.ts +1 -1
- package/dist/authority/AzureRegionConfiguration.d.ts.map +1 -1
- package/dist/authority/CloudDiscoveryMetadata.d.ts +1 -1
- package/dist/authority/CloudDiscoveryMetadata.d.ts.map +1 -1
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.d.ts +1 -1
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.d.ts.map +1 -1
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.js +1 -1
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.js.map +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.d.ts +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.d.ts.map +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.js +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.js.map +1 -1
- package/dist/authority/ImdsOptions.d.ts +1 -1
- package/dist/authority/ImdsOptions.d.ts.map +1 -1
- package/dist/authority/OpenIdConfigResponse.d.ts +1 -1
- package/dist/authority/OpenIdConfigResponse.d.ts.map +1 -1
- package/dist/authority/OpenIdConfigResponse.js +1 -1
- package/dist/authority/OpenIdConfigResponse.js.map +1 -1
- package/dist/authority/ProtocolMode.js +1 -1
- package/dist/authority/ProtocolMode.js.map +1 -1
- package/dist/authority/RegionDiscovery.d.ts.map +1 -1
- package/dist/authority/RegionDiscovery.js +85 -107
- package/dist/authority/RegionDiscovery.js.map +1 -1
- package/dist/authority/RegionDiscoveryMetadata.d.ts +1 -1
- package/dist/authority/RegionDiscoveryMetadata.d.ts.map +1 -1
- package/dist/broker/nativeBroker/INativeBrokerPlugin.d.ts.map +1 -1
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.js +440 -475
- package/dist/cache/CacheManager.js.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.js +21 -22
- package/dist/cache/entities/AccessTokenEntity.js.map +1 -1
- package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccountEntity.js +78 -66
- package/dist/cache/entities/AccountEntity.js.map +1 -1
- package/dist/cache/entities/AppMetadataEntity.d.ts.map +1 -1
- package/dist/cache/entities/AppMetadataEntity.js +16 -17
- package/dist/cache/entities/AppMetadataEntity.js.map +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.js +22 -19
- package/dist/cache/entities/AuthorityMetadataEntity.js.map +1 -1
- package/dist/cache/entities/CacheRecord.d.ts.map +1 -1
- package/dist/cache/entities/CacheRecord.js +4 -5
- package/dist/cache/entities/CacheRecord.js.map +1 -1
- package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
- package/dist/cache/entities/CredentialEntity.js +35 -34
- package/dist/cache/entities/CredentialEntity.js.map +1 -1
- package/dist/cache/entities/IdTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/IdTokenEntity.js +8 -14
- package/dist/cache/entities/IdTokenEntity.js.map +1 -1
- package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/RefreshTokenEntity.js +8 -14
- package/dist/cache/entities/RefreshTokenEntity.js.map +1 -1
- package/dist/cache/entities/ServerTelemetryEntity.d.ts.map +1 -1
- package/dist/cache/entities/ServerTelemetryEntity.js +8 -9
- package/dist/cache/entities/ServerTelemetryEntity.js.map +1 -1
- package/dist/cache/entities/ThrottlingEntity.js +9 -11
- package/dist/cache/entities/ThrottlingEntity.js.map +1 -1
- package/dist/cache/interface/ICacheManager.d.ts.map +1 -1
- package/dist/cache/persistence/TokenCacheContext.d.ts.map +1 -1
- package/dist/cache/persistence/TokenCacheContext.js +16 -25
- package/dist/cache/persistence/TokenCacheContext.js.map +1 -1
- package/dist/cache/utils/CacheTypes.d.ts +11 -11
- package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.js +341 -384
- package/dist/client/AuthorizationCodeClient.js.map +1 -1
- package/dist/client/BaseClient.d.ts.map +1 -1
- package/dist/client/BaseClient.js +27 -35
- package/dist/client/BaseClient.js.map +1 -1
- package/dist/client/RefreshTokenClient.d.ts.map +1 -1
- package/dist/client/RefreshTokenClient.js +208 -241
- package/dist/client/RefreshTokenClient.js.map +1 -1
- package/dist/client/SilentFlowClient.d.ts.map +1 -1
- package/dist/client/SilentFlowClient.js +77 -105
- package/dist/client/SilentFlowClient.js.map +1 -1
- package/dist/config/AppTokenProvider.d.ts +2 -2
- package/dist/config/AppTokenProvider.d.ts.map +1 -1
- package/dist/config/ClientConfiguration.d.ts +9 -9
- package/dist/config/ClientConfiguration.d.ts.map +1 -1
- package/dist/config/ClientConfiguration.js +40 -43
- package/dist/config/ClientConfiguration.js.map +1 -1
- package/dist/crypto/ICrypto.d.ts +2 -2
- package/dist/crypto/ICrypto.d.ts.map +1 -1
- package/dist/crypto/ICrypto.js +27 -58
- package/dist/crypto/ICrypto.js.map +1 -1
- package/dist/crypto/JoseHeader.d.ts +1 -1
- package/dist/crypto/JoseHeader.d.ts.map +1 -1
- package/dist/crypto/JoseHeader.js +8 -9
- package/dist/crypto/JoseHeader.js.map +1 -1
- package/dist/crypto/PopTokenGenerator.d.ts +2 -2
- package/dist/crypto/PopTokenGenerator.d.ts.map +1 -1
- package/dist/crypto/PopTokenGenerator.js +47 -71
- package/dist/crypto/PopTokenGenerator.js.map +1 -1
- package/dist/crypto/SignedHttpRequest.d.ts +1 -1
- package/dist/crypto/SignedHttpRequest.d.ts.map +1 -1
- package/dist/error/AuthError.d.ts.map +1 -1
- package/dist/error/AuthError.js +25 -28
- package/dist/error/AuthError.js.map +1 -1
- package/dist/error/ClientAuthError.d.ts +8 -0
- package/dist/error/ClientAuthError.d.ts.map +1 -1
- package/dist/error/ClientAuthError.js +187 -181
- package/dist/error/ClientAuthError.js.map +1 -1
- package/dist/error/ClientConfigurationError.d.ts.map +1 -1
- package/dist/error/ClientConfigurationError.js +82 -86
- package/dist/error/ClientConfigurationError.js.map +1 -1
- package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
- package/dist/error/InteractionRequiredAuthError.js +36 -35
- package/dist/error/InteractionRequiredAuthError.js.map +1 -1
- package/dist/error/JoseHeaderError.d.ts.map +1 -1
- package/dist/error/JoseHeaderError.js +14 -18
- package/dist/error/JoseHeaderError.js.map +1 -1
- package/dist/error/ServerError.d.ts.map +1 -1
- package/dist/error/ServerError.js +7 -11
- package/dist/error/ServerError.js.map +1 -1
- package/dist/index.cjs.js +4221 -4476
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +20 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/logger/Logger.d.ts +1 -1
- package/dist/logger/Logger.d.ts.map +1 -1
- package/dist/logger/Logger.js +70 -60
- package/dist/logger/Logger.js.map +1 -1
- package/dist/network/INetworkModule.d.ts +1 -1
- package/dist/network/INetworkModule.d.ts.map +1 -1
- package/dist/network/INetworkModule.js +7 -7
- package/dist/network/INetworkModule.js.map +1 -1
- package/dist/network/NetworkManager.d.ts +4 -3
- package/dist/network/NetworkManager.d.ts.map +1 -1
- package/dist/network/NetworkManager.js +21 -35
- package/dist/network/NetworkManager.js.map +1 -1
- package/dist/network/RequestThumbprint.d.ts +1 -1
- package/dist/network/RequestThumbprint.d.ts.map +1 -1
- package/dist/network/ThrottlingUtils.d.ts.map +1 -1
- package/dist/network/ThrottlingUtils.js +37 -36
- package/dist/network/ThrottlingUtils.js.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/packageMetadata.d.ts.map +1 -1
- package/dist/packageMetadata.js +3 -3
- package/dist/packageMetadata.js.map +1 -1
- package/dist/request/AuthenticationHeaderParser.d.ts.map +1 -1
- package/dist/request/AuthenticationHeaderParser.js +17 -18
- package/dist/request/AuthenticationHeaderParser.js.map +1 -1
- package/dist/request/BaseAuthRequest.d.ts +1 -1
- package/dist/request/BaseAuthRequest.d.ts.map +1 -1
- package/dist/request/CommonAuthorizationCodeRequest.d.ts +1 -1
- package/dist/request/CommonAuthorizationCodeRequest.d.ts.map +1 -1
- package/dist/request/CommonAuthorizationUrlRequest.d.ts +1 -1
- package/dist/request/CommonAuthorizationUrlRequest.d.ts.map +1 -1
- package/dist/request/CommonClientCredentialRequest.d.ts +1 -1
- package/dist/request/CommonClientCredentialRequest.d.ts.map +1 -1
- package/dist/request/CommonDeviceCodeRequest.d.ts +1 -1
- package/dist/request/CommonDeviceCodeRequest.d.ts.map +1 -1
- package/dist/request/CommonEndSessionRequest.d.ts +1 -1
- package/dist/request/CommonEndSessionRequest.d.ts.map +1 -1
- package/dist/request/CommonOnBehalfOfRequest.d.ts +1 -1
- package/dist/request/CommonOnBehalfOfRequest.d.ts.map +1 -1
- package/dist/request/CommonRefreshTokenRequest.d.ts +1 -1
- package/dist/request/CommonRefreshTokenRequest.d.ts.map +1 -1
- package/dist/request/CommonSilentFlowRequest.d.ts +1 -1
- package/dist/request/CommonSilentFlowRequest.d.ts.map +1 -1
- package/dist/request/CommonUsernamePasswordRequest.d.ts +1 -1
- package/dist/request/CommonUsernamePasswordRequest.d.ts.map +1 -1
- package/dist/request/NativeRequest.d.ts +1 -1
- package/dist/request/NativeRequest.d.ts.map +1 -1
- package/dist/request/NativeSignOutRequest.d.ts +1 -1
- package/dist/request/NativeSignOutRequest.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.js +111 -113
- package/dist/request/RequestParameterBuilder.js.map +1 -1
- package/dist/request/RequestValidator.d.ts.map +1 -1
- package/dist/request/RequestValidator.js +23 -28
- package/dist/request/RequestValidator.js.map +1 -1
- package/dist/request/ScopeSet.d.ts.map +1 -1
- package/dist/request/ScopeSet.js +70 -70
- package/dist/request/ScopeSet.js.map +1 -1
- package/dist/response/AuthenticationResult.d.ts +1 -1
- package/dist/response/AuthenticationResult.d.ts.map +1 -1
- package/dist/response/AuthorizationCodePayload.d.ts +1 -1
- package/dist/response/AuthorizationCodePayload.d.ts.map +1 -1
- package/dist/response/DeviceCodeResponse.d.ts +2 -2
- package/dist/response/DeviceCodeResponse.d.ts.map +1 -1
- package/dist/response/ExternalTokenResponse.d.ts +1 -1
- package/dist/response/ExternalTokenResponse.d.ts.map +1 -1
- package/dist/response/IMDSBadResponse.d.ts +1 -1
- package/dist/response/IMDSBadResponse.d.ts.map +1 -1
- package/dist/response/ResponseHandler.d.ts.map +1 -1
- package/dist/response/ResponseHandler.js +195 -180
- package/dist/response/ResponseHandler.js.map +1 -1
- package/dist/response/ServerAuthorizationCodeResponse.d.ts +1 -1
- package/dist/response/ServerAuthorizationCodeResponse.d.ts.map +1 -1
- package/dist/response/ServerAuthorizationTokenResponse.d.ts +1 -1
- package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
- package/dist/telemetry/performance/IPerformanceClient.d.ts +3 -4
- package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.d.ts +2 -10
- package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceClient.js +134 -129
- package/dist/telemetry/performance/PerformanceClient.js.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts +4 -4
- package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.js +2 -2
- package/dist/telemetry/performance/PerformanceEvent.js.map +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.d.ts +5 -3
- package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.js +23 -32
- package/dist/telemetry/performance/StubPerformanceClient.js.map +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.d.ts +1 -2
- package/dist/telemetry/server/ServerTelemetryManager.d.ts.map +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.js +106 -68
- package/dist/telemetry/server/ServerTelemetryManager.js.map +1 -1
- package/dist/telemetry/server/ServerTelemetryRequest.d.ts +1 -1
- package/dist/telemetry/server/ServerTelemetryRequest.d.ts.map +1 -1
- package/dist/url/UrlString.d.ts.map +1 -1
- package/dist/url/UrlString.js +85 -74
- package/dist/url/UrlString.js.map +1 -1
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.js +28 -27
- package/dist/utils/Constants.js.map +1 -1
- package/dist/utils/MsalTypes.d.ts +1 -1
- package/dist/utils/MsalTypes.d.ts.map +1 -1
- package/dist/utils/ProtocolUtils.d.ts +2 -2
- package/dist/utils/ProtocolUtils.d.ts.map +1 -1
- package/dist/utils/ProtocolUtils.js +27 -24
- package/dist/utils/ProtocolUtils.js.map +1 -1
- package/dist/utils/StringUtils.d.ts.map +1 -1
- package/dist/utils/StringUtils.js +44 -42
- package/dist/utils/StringUtils.js.map +1 -1
- package/dist/utils/TimeUtils.d.ts.map +1 -1
- package/dist/utils/TimeUtils.js +16 -19
- package/dist/utils/TimeUtils.js.map +1 -1
- package/package.json +79 -76
- package/dist/_virtual/_tslib.js +0 -90
- package/dist/_virtual/_tslib.js.map +0 -1
- package/dist/client/ClientCredentialClient.d.ts +0 -38
- package/dist/client/ClientCredentialClient.d.ts.map +0 -1
- package/dist/client/ClientCredentialClient.js +0 -203
- package/dist/client/ClientCredentialClient.js.map +0 -1
- package/dist/client/DeviceCodeClient.d.ts +0 -57
- package/dist/client/DeviceCodeClient.d.ts.map +0 -1
- package/dist/client/DeviceCodeClient.js +0 -250
- package/dist/client/DeviceCodeClient.js.map +0 -1
- package/dist/client/OnBehalfOfClient.d.ts +0 -51
- package/dist/client/OnBehalfOfClient.d.ts.map +0 -1
- package/dist/client/OnBehalfOfClient.js +0 -248
- package/dist/client/OnBehalfOfClient.js.map +0 -1
- package/dist/client/UsernamePasswordClient.d.ts +0 -29
- package/dist/client/UsernamePasswordClient.d.ts.map +0 -1
- package/dist/client/UsernamePasswordClient.js +0 -129
- package/dist/client/UsernamePasswordClient.js.map +0 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/*! @azure/msal-common
|
|
1
|
+
/*! @azure/msal-common v14.0.0-alpha.1 2023-05-08 */
|
|
2
2
|
'use strict';
|
|
3
|
-
import { __awaiter, __generator, __assign, __extends } from '../_virtual/_tslib.js';
|
|
4
3
|
import { Separators, CredentialType, AuthenticationScheme, THE_FAMILY_ID, APP_METADATA, AUTHORITY_METADATA_CONSTANTS } from '../utils/Constants.js';
|
|
5
4
|
import { ScopeSet } from '../request/ScopeSet.js';
|
|
6
5
|
import { AccountEntity } from './entities/AccountEntity.js';
|
|
@@ -16,8 +15,8 @@ import { name, version } from '../packageMetadata.js';
|
|
|
16
15
|
/**
|
|
17
16
|
* Interface class which implement cache storage functions used by MSAL to perform validity checks, and store tokens.
|
|
18
17
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
class CacheManager {
|
|
19
|
+
constructor(clientId, cryptoImpl, logger) {
|
|
21
20
|
this.clientId = clientId;
|
|
22
21
|
this.cryptoImpl = cryptoImpl;
|
|
23
22
|
this.commonLogger = logger.clone(name, version);
|
|
@@ -25,14 +24,13 @@ var CacheManager = /** @class */ (function () {
|
|
|
25
24
|
/**
|
|
26
25
|
* Returns all accounts in cache
|
|
27
26
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var allAccountKeys = this.getAccountKeys();
|
|
27
|
+
getAllAccounts() {
|
|
28
|
+
const allAccountKeys = this.getAccountKeys();
|
|
31
29
|
if (allAccountKeys.length < 1) {
|
|
32
30
|
return [];
|
|
33
31
|
}
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const accountEntities = allAccountKeys.reduce((accounts, key) => {
|
|
33
|
+
const entity = this.getAccount(key);
|
|
36
34
|
if (!entity) {
|
|
37
35
|
return accounts;
|
|
38
36
|
}
|
|
@@ -43,112 +41,90 @@ var CacheManager = /** @class */ (function () {
|
|
|
43
41
|
return [];
|
|
44
42
|
}
|
|
45
43
|
else {
|
|
46
|
-
|
|
47
|
-
return
|
|
44
|
+
const allAccounts = accountEntities.map((accountEntity) => {
|
|
45
|
+
return this.getAccountInfoFromEntity(accountEntity);
|
|
48
46
|
});
|
|
49
47
|
return allAccounts;
|
|
50
48
|
}
|
|
51
|
-
}
|
|
49
|
+
}
|
|
52
50
|
/**
|
|
53
51
|
* Gets accountInfo object based on provided filters
|
|
54
52
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
getAccountInfoFilteredBy(accountFilter) {
|
|
54
|
+
const allAccounts = this.getAccountsFilteredBy(accountFilter);
|
|
57
55
|
if (allAccounts.length > 0) {
|
|
58
56
|
return this.getAccountInfoFromEntity(allAccounts[0]);
|
|
59
57
|
}
|
|
60
58
|
else {
|
|
61
59
|
return null;
|
|
62
60
|
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
}
|
|
62
|
+
getAccountInfoFromEntity(accountEntity) {
|
|
63
|
+
const accountInfo = accountEntity.getAccountInfo();
|
|
64
|
+
const idToken = this.getIdToken(accountInfo);
|
|
67
65
|
if (idToken) {
|
|
68
66
|
accountInfo.idToken = idToken.secret;
|
|
69
67
|
accountInfo.idTokenClaims = new AuthToken(idToken.secret, this.cryptoImpl).claims;
|
|
70
68
|
}
|
|
71
69
|
return accountInfo;
|
|
72
|
-
}
|
|
70
|
+
}
|
|
73
71
|
/**
|
|
74
72
|
* saves a cache record
|
|
75
73
|
* @param cacheRecord
|
|
76
74
|
*/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (!!cacheRecord.refreshToken) {
|
|
98
|
-
this.setRefreshTokenCredential(cacheRecord.refreshToken);
|
|
99
|
-
}
|
|
100
|
-
if (!!cacheRecord.appMetadata) {
|
|
101
|
-
this.setAppMetadata(cacheRecord.appMetadata);
|
|
102
|
-
}
|
|
103
|
-
return [2 /*return*/];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
};
|
|
75
|
+
async saveCacheRecord(cacheRecord) {
|
|
76
|
+
if (!cacheRecord) {
|
|
77
|
+
throw ClientAuthError.createNullOrUndefinedCacheRecord();
|
|
78
|
+
}
|
|
79
|
+
if (!!cacheRecord.account) {
|
|
80
|
+
this.setAccount(cacheRecord.account);
|
|
81
|
+
}
|
|
82
|
+
if (!!cacheRecord.idToken) {
|
|
83
|
+
this.setIdTokenCredential(cacheRecord.idToken);
|
|
84
|
+
}
|
|
85
|
+
if (!!cacheRecord.accessToken) {
|
|
86
|
+
await this.saveAccessToken(cacheRecord.accessToken);
|
|
87
|
+
}
|
|
88
|
+
if (!!cacheRecord.refreshToken) {
|
|
89
|
+
this.setRefreshTokenCredential(cacheRecord.refreshToken);
|
|
90
|
+
}
|
|
91
|
+
if (!!cacheRecord.appMetadata) {
|
|
92
|
+
this.setAppMetadata(cacheRecord.appMetadata);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
108
95
|
/**
|
|
109
96
|
* saves access token credential
|
|
110
97
|
* @param credential
|
|
111
98
|
*/
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
var tokenEntity = _this.getAccessTokenCredential(key);
|
|
136
|
-
if (tokenEntity && _this.credentialMatchesFilter(tokenEntity, accessTokenFilter)) {
|
|
137
|
-
var tokenScopeSet = ScopeSet.fromString(tokenEntity.target);
|
|
138
|
-
if (tokenScopeSet.intersectingScopeSets(currentScopes)) {
|
|
139
|
-
removedAccessTokens.push(_this.removeAccessToken(key));
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
return [4 /*yield*/, Promise.all(removedAccessTokens)];
|
|
144
|
-
case 1:
|
|
145
|
-
_a.sent();
|
|
146
|
-
this.setAccessTokenCredential(credential);
|
|
147
|
-
return [2 /*return*/];
|
|
99
|
+
async saveAccessToken(credential) {
|
|
100
|
+
const accessTokenFilter = {
|
|
101
|
+
clientId: credential.clientId,
|
|
102
|
+
credentialType: credential.credentialType,
|
|
103
|
+
environment: credential.environment,
|
|
104
|
+
homeAccountId: credential.homeAccountId,
|
|
105
|
+
realm: credential.realm,
|
|
106
|
+
tokenType: credential.tokenType,
|
|
107
|
+
requestedClaimsHash: credential.requestedClaimsHash,
|
|
108
|
+
};
|
|
109
|
+
const tokenKeys = this.getTokenKeys();
|
|
110
|
+
const currentScopes = ScopeSet.fromString(credential.target);
|
|
111
|
+
const removedAccessTokens = [];
|
|
112
|
+
tokenKeys.accessToken.forEach((key) => {
|
|
113
|
+
if (!this.accessTokenKeyMatchesFilter(key, accessTokenFilter, false)) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const tokenEntity = this.getAccessTokenCredential(key);
|
|
117
|
+
if (tokenEntity &&
|
|
118
|
+
this.credentialMatchesFilter(tokenEntity, accessTokenFilter)) {
|
|
119
|
+
const tokenScopeSet = ScopeSet.fromString(tokenEntity.target);
|
|
120
|
+
if (tokenScopeSet.intersectingScopeSets(currentScopes)) {
|
|
121
|
+
removedAccessTokens.push(this.removeAccessToken(key));
|
|
148
122
|
}
|
|
149
|
-
}
|
|
123
|
+
}
|
|
150
124
|
});
|
|
151
|
-
|
|
125
|
+
await Promise.all(removedAccessTokens);
|
|
126
|
+
this.setAccessTokenCredential(credential);
|
|
127
|
+
}
|
|
152
128
|
/**
|
|
153
129
|
* retrieve accounts matching all provided filters; if no filter is set, get all accounts
|
|
154
130
|
* not checking for casing as keys are all generated in lower case, remember to convert to lower case if object properties are compared
|
|
@@ -156,41 +132,46 @@ var CacheManager = /** @class */ (function () {
|
|
|
156
132
|
* @param environment
|
|
157
133
|
* @param realm
|
|
158
134
|
*/
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (!_this.isAccountKey(cacheKey, accountFilter.homeAccountId, accountFilter.realm)) {
|
|
135
|
+
getAccountsFilteredBy(accountFilter) {
|
|
136
|
+
const allAccountKeys = this.getAccountKeys();
|
|
137
|
+
const matchingAccounts = [];
|
|
138
|
+
allAccountKeys.forEach((cacheKey) => {
|
|
139
|
+
if (!this.isAccountKey(cacheKey, accountFilter.homeAccountId, accountFilter.realm)) {
|
|
165
140
|
// Don't parse value if the key doesn't match the account filters
|
|
166
141
|
return;
|
|
167
142
|
}
|
|
168
|
-
|
|
143
|
+
const entity = this.getAccount(cacheKey);
|
|
169
144
|
if (!entity) {
|
|
170
145
|
return;
|
|
171
146
|
}
|
|
172
|
-
if (!!accountFilter.homeAccountId &&
|
|
147
|
+
if (!!accountFilter.homeAccountId &&
|
|
148
|
+
!this.matchHomeAccountId(entity, accountFilter.homeAccountId)) {
|
|
173
149
|
return;
|
|
174
150
|
}
|
|
175
|
-
if (!!accountFilter.localAccountId &&
|
|
151
|
+
if (!!accountFilter.localAccountId &&
|
|
152
|
+
!this.matchLocalAccountId(entity, accountFilter.localAccountId)) {
|
|
176
153
|
return;
|
|
177
154
|
}
|
|
178
|
-
if (!!accountFilter.username &&
|
|
155
|
+
if (!!accountFilter.username &&
|
|
156
|
+
!this.matchUsername(entity, accountFilter.username)) {
|
|
179
157
|
return;
|
|
180
158
|
}
|
|
181
|
-
if (!!accountFilter.environment &&
|
|
159
|
+
if (!!accountFilter.environment &&
|
|
160
|
+
!this.matchEnvironment(entity, accountFilter.environment)) {
|
|
182
161
|
return;
|
|
183
162
|
}
|
|
184
|
-
if (!!accountFilter.realm &&
|
|
163
|
+
if (!!accountFilter.realm &&
|
|
164
|
+
!this.matchRealm(entity, accountFilter.realm)) {
|
|
185
165
|
return;
|
|
186
166
|
}
|
|
187
|
-
if (!!accountFilter.nativeAccountId &&
|
|
167
|
+
if (!!accountFilter.nativeAccountId &&
|
|
168
|
+
!this.matchNativeAccountId(entity, accountFilter.nativeAccountId)) {
|
|
188
169
|
return;
|
|
189
170
|
}
|
|
190
171
|
matchingAccounts.push(entity);
|
|
191
172
|
});
|
|
192
173
|
return matchingAccounts;
|
|
193
|
-
}
|
|
174
|
+
}
|
|
194
175
|
/**
|
|
195
176
|
* Returns true if the given key matches our account key schema. Also matches homeAccountId and/or tenantId if provided
|
|
196
177
|
* @param key
|
|
@@ -198,12 +179,13 @@ var CacheManager = /** @class */ (function () {
|
|
|
198
179
|
* @param tenantId
|
|
199
180
|
* @returns
|
|
200
181
|
*/
|
|
201
|
-
|
|
182
|
+
isAccountKey(key, homeAccountId, tenantId) {
|
|
202
183
|
if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 3) {
|
|
203
184
|
// Account cache keys contain 3 items separated by '-' (each item may also contain '-')
|
|
204
185
|
return false;
|
|
205
186
|
}
|
|
206
|
-
if (homeAccountId &&
|
|
187
|
+
if (homeAccountId &&
|
|
188
|
+
!key.toLowerCase().includes(homeAccountId.toLowerCase())) {
|
|
207
189
|
return false;
|
|
208
190
|
}
|
|
209
191
|
if (tenantId && !key.toLowerCase().includes(tenantId.toLowerCase())) {
|
|
@@ -211,29 +193,34 @@ var CacheManager = /** @class */ (function () {
|
|
|
211
193
|
}
|
|
212
194
|
// Do not check environment as aliasing can cause false negatives
|
|
213
195
|
return true;
|
|
214
|
-
}
|
|
196
|
+
}
|
|
215
197
|
/**
|
|
216
198
|
* Returns true if the given key matches our credential key schema.
|
|
217
199
|
* @param key
|
|
218
200
|
*/
|
|
219
|
-
|
|
201
|
+
isCredentialKey(key) {
|
|
220
202
|
if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 6) {
|
|
221
203
|
// Credential cache keys contain 6 items separated by '-' (each item may also contain '-')
|
|
222
204
|
return false;
|
|
223
205
|
}
|
|
224
|
-
|
|
206
|
+
const lowerCaseKey = key.toLowerCase();
|
|
225
207
|
// Credential keys must indicate what credential type they represent
|
|
226
|
-
if (lowerCaseKey.indexOf(CredentialType.ID_TOKEN.toLowerCase()) ===
|
|
227
|
-
|
|
208
|
+
if (lowerCaseKey.indexOf(CredentialType.ID_TOKEN.toLowerCase()) ===
|
|
209
|
+
-1 &&
|
|
210
|
+
lowerCaseKey.indexOf(CredentialType.ACCESS_TOKEN.toLowerCase()) ===
|
|
211
|
+
-1 &&
|
|
228
212
|
lowerCaseKey.indexOf(CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()) === -1 &&
|
|
229
|
-
lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) ===
|
|
213
|
+
lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) ===
|
|
214
|
+
-1) {
|
|
230
215
|
return false;
|
|
231
216
|
}
|
|
232
|
-
if (lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) >
|
|
217
|
+
if (lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) >
|
|
218
|
+
-1) {
|
|
233
219
|
// Refresh tokens must contain the client id or family id
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (lowerCaseKey.indexOf(clientIdValidation.toLowerCase()) === -1 &&
|
|
220
|
+
const clientIdValidation = `${CredentialType.REFRESH_TOKEN}${Separators.CACHE_KEY_SEPARATOR}${this.clientId}${Separators.CACHE_KEY_SEPARATOR}`;
|
|
221
|
+
const familyIdValidation = `${CredentialType.REFRESH_TOKEN}${Separators.CACHE_KEY_SEPARATOR}${THE_FAMILY_ID}${Separators.CACHE_KEY_SEPARATOR}`;
|
|
222
|
+
if (lowerCaseKey.indexOf(clientIdValidation.toLowerCase()) === -1 &&
|
|
223
|
+
lowerCaseKey.indexOf(familyIdValidation.toLowerCase()) === -1) {
|
|
237
224
|
return false;
|
|
238
225
|
}
|
|
239
226
|
}
|
|
@@ -242,34 +229,38 @@ var CacheManager = /** @class */ (function () {
|
|
|
242
229
|
return false;
|
|
243
230
|
}
|
|
244
231
|
return true;
|
|
245
|
-
}
|
|
232
|
+
}
|
|
246
233
|
/**
|
|
247
234
|
* Returns whether or not the given credential entity matches the filter
|
|
248
235
|
* @param entity
|
|
249
236
|
* @param filter
|
|
250
237
|
* @returns
|
|
251
238
|
*/
|
|
252
|
-
|
|
239
|
+
credentialMatchesFilter(entity, filter) {
|
|
253
240
|
if (!!filter.clientId && !this.matchClientId(entity, filter.clientId)) {
|
|
254
241
|
return false;
|
|
255
242
|
}
|
|
256
|
-
if (!!filter.userAssertionHash &&
|
|
243
|
+
if (!!filter.userAssertionHash &&
|
|
244
|
+
!this.matchUserAssertionHash(entity, filter.userAssertionHash)) {
|
|
257
245
|
return false;
|
|
258
246
|
}
|
|
259
247
|
/*
|
|
260
248
|
* homeAccountId can be undefined, and we want to filter out cached items that have a homeAccountId of ""
|
|
261
249
|
* because we don't want a client_credential request to return a cached token that has a homeAccountId
|
|
262
250
|
*/
|
|
263
|
-
if (
|
|
251
|
+
if (typeof filter.homeAccountId === "string" &&
|
|
252
|
+
!this.matchHomeAccountId(entity, filter.homeAccountId)) {
|
|
264
253
|
return false;
|
|
265
254
|
}
|
|
266
|
-
if (!!filter.environment &&
|
|
255
|
+
if (!!filter.environment &&
|
|
256
|
+
!this.matchEnvironment(entity, filter.environment)) {
|
|
267
257
|
return false;
|
|
268
258
|
}
|
|
269
259
|
if (!!filter.realm && !this.matchRealm(entity, filter.realm)) {
|
|
270
260
|
return false;
|
|
271
261
|
}
|
|
272
|
-
if (!!filter.credentialType &&
|
|
262
|
+
if (!!filter.credentialType &&
|
|
263
|
+
!this.matchCredentialType(entity, filter.credentialType)) {
|
|
273
264
|
return false;
|
|
274
265
|
}
|
|
275
266
|
if (!!filter.familyId && !this.matchFamilyId(entity, filter.familyId)) {
|
|
@@ -290,8 +281,10 @@ var CacheManager = /** @class */ (function () {
|
|
|
290
281
|
}
|
|
291
282
|
}
|
|
292
283
|
// Access Token with Auth Scheme specific matching
|
|
293
|
-
if (entity.credentialType ===
|
|
294
|
-
|
|
284
|
+
if (entity.credentialType ===
|
|
285
|
+
CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME) {
|
|
286
|
+
if (!!filter.tokenType &&
|
|
287
|
+
!this.matchTokenType(entity, filter.tokenType)) {
|
|
295
288
|
return false;
|
|
296
289
|
}
|
|
297
290
|
// KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
|
|
@@ -302,58 +295,57 @@ var CacheManager = /** @class */ (function () {
|
|
|
302
295
|
}
|
|
303
296
|
}
|
|
304
297
|
return true;
|
|
305
|
-
}
|
|
298
|
+
}
|
|
306
299
|
/**
|
|
307
300
|
* retrieve appMetadata matching all provided filters; if no filter is set, get all appMetadata
|
|
308
301
|
* @param filter
|
|
309
302
|
*/
|
|
310
|
-
|
|
303
|
+
getAppMetadataFilteredBy(filter) {
|
|
311
304
|
return this.getAppMetadataFilteredByInternal(filter.environment, filter.clientId);
|
|
312
|
-
}
|
|
305
|
+
}
|
|
313
306
|
/**
|
|
314
307
|
* Support function to help match appMetadata
|
|
315
308
|
* @param environment
|
|
316
309
|
* @param clientId
|
|
317
310
|
*/
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
allCacheKeys.forEach(function (cacheKey) {
|
|
311
|
+
getAppMetadataFilteredByInternal(environment, clientId) {
|
|
312
|
+
const allCacheKeys = this.getKeys();
|
|
313
|
+
const matchingAppMetadata = {};
|
|
314
|
+
allCacheKeys.forEach((cacheKey) => {
|
|
323
315
|
// don't parse any non-appMetadata type cache entities
|
|
324
|
-
if (!
|
|
316
|
+
if (!this.isAppMetadata(cacheKey)) {
|
|
325
317
|
return;
|
|
326
318
|
}
|
|
327
319
|
// Attempt retrieval
|
|
328
|
-
|
|
320
|
+
const entity = this.getAppMetadata(cacheKey);
|
|
329
321
|
if (!entity) {
|
|
330
322
|
return;
|
|
331
323
|
}
|
|
332
|
-
if (!!environment && !
|
|
324
|
+
if (!!environment && !this.matchEnvironment(entity, environment)) {
|
|
333
325
|
return;
|
|
334
326
|
}
|
|
335
|
-
if (!!clientId && !
|
|
327
|
+
if (!!clientId && !this.matchClientId(entity, clientId)) {
|
|
336
328
|
return;
|
|
337
329
|
}
|
|
338
330
|
matchingAppMetadata[cacheKey] = entity;
|
|
339
331
|
});
|
|
340
332
|
return matchingAppMetadata;
|
|
341
|
-
}
|
|
333
|
+
}
|
|
342
334
|
/**
|
|
343
335
|
* retrieve authorityMetadata that contains a matching alias
|
|
344
336
|
* @param filter
|
|
345
337
|
*/
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
allCacheKeys.forEach(function (cacheKey) {
|
|
338
|
+
getAuthorityMetadataByAlias(host) {
|
|
339
|
+
const allCacheKeys = this.getAuthorityMetadataKeys();
|
|
340
|
+
let matchedEntity = null;
|
|
341
|
+
allCacheKeys.forEach((cacheKey) => {
|
|
351
342
|
// don't parse any non-authorityMetadata type cache entities
|
|
352
|
-
if (!
|
|
343
|
+
if (!this.isAuthorityMetadata(cacheKey) ||
|
|
344
|
+
cacheKey.indexOf(this.clientId) === -1) {
|
|
353
345
|
return;
|
|
354
346
|
}
|
|
355
347
|
// Attempt retrieval
|
|
356
|
-
|
|
348
|
+
const entity = this.getAuthorityMetadata(cacheKey);
|
|
357
349
|
if (!entity) {
|
|
358
350
|
return;
|
|
359
351
|
}
|
|
@@ -363,137 +355,94 @@ var CacheManager = /** @class */ (function () {
|
|
|
363
355
|
matchedEntity = entity;
|
|
364
356
|
});
|
|
365
357
|
return matchedEntity;
|
|
366
|
-
}
|
|
358
|
+
}
|
|
367
359
|
/**
|
|
368
360
|
* Removes all accounts and related tokens from cache.
|
|
369
361
|
*/
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
switch (_a.label) {
|
|
376
|
-
case 0:
|
|
377
|
-
allAccountKeys = this.getAccountKeys();
|
|
378
|
-
removedAccounts = [];
|
|
379
|
-
allAccountKeys.forEach(function (cacheKey) {
|
|
380
|
-
removedAccounts.push(_this.removeAccount(cacheKey));
|
|
381
|
-
});
|
|
382
|
-
return [4 /*yield*/, Promise.all(removedAccounts)];
|
|
383
|
-
case 1:
|
|
384
|
-
_a.sent();
|
|
385
|
-
return [2 /*return*/];
|
|
386
|
-
}
|
|
387
|
-
});
|
|
362
|
+
async removeAllAccounts() {
|
|
363
|
+
const allAccountKeys = this.getAccountKeys();
|
|
364
|
+
const removedAccounts = [];
|
|
365
|
+
allAccountKeys.forEach((cacheKey) => {
|
|
366
|
+
removedAccounts.push(this.removeAccount(cacheKey));
|
|
388
367
|
});
|
|
389
|
-
|
|
368
|
+
await Promise.all(removedAccounts);
|
|
369
|
+
}
|
|
390
370
|
/**
|
|
391
371
|
* Removes the account and related tokens for a given account key
|
|
392
372
|
* @param account
|
|
393
373
|
*/
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
return
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
throw ClientAuthError.createNoAccountFoundError();
|
|
403
|
-
}
|
|
404
|
-
return [4 /*yield*/, this.removeAccountContext(account)];
|
|
405
|
-
case 1:
|
|
406
|
-
_a.sent();
|
|
407
|
-
this.removeItem(accountKey);
|
|
408
|
-
return [2 /*return*/];
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
};
|
|
374
|
+
async removeAccount(accountKey) {
|
|
375
|
+
const account = this.getAccount(accountKey);
|
|
376
|
+
if (!account) {
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
await this.removeAccountContext(account);
|
|
380
|
+
this.removeItem(accountKey);
|
|
381
|
+
}
|
|
413
382
|
/**
|
|
414
383
|
* Removes credentials associated with the provided account
|
|
415
384
|
* @param account
|
|
416
385
|
*/
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
allTokenKeys.refreshToken.forEach(function (key) {
|
|
438
|
-
if (key.indexOf(accountId) === 0) {
|
|
439
|
-
_this.removeRefreshToken(key);
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
return [4 /*yield*/, Promise.all(removedCredentials)];
|
|
443
|
-
case 1:
|
|
444
|
-
_a.sent();
|
|
445
|
-
return [2 /*return*/];
|
|
446
|
-
}
|
|
447
|
-
});
|
|
386
|
+
async removeAccountContext(account) {
|
|
387
|
+
const allTokenKeys = this.getTokenKeys();
|
|
388
|
+
const accountId = account.generateAccountId();
|
|
389
|
+
const removedCredentials = [];
|
|
390
|
+
allTokenKeys.idToken.forEach((key) => {
|
|
391
|
+
if (key.indexOf(accountId) === 0) {
|
|
392
|
+
this.removeIdToken(key);
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
allTokenKeys.accessToken.forEach((key) => {
|
|
396
|
+
if (key.indexOf(accountId) === 0) {
|
|
397
|
+
removedCredentials.push(this.removeAccessToken(key));
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
allTokenKeys.refreshToken.forEach((key) => {
|
|
401
|
+
if (key.indexOf(accountId) === 0) {
|
|
402
|
+
this.removeRefreshToken(key);
|
|
403
|
+
}
|
|
448
404
|
});
|
|
449
|
-
|
|
405
|
+
await Promise.all(removedCredentials);
|
|
406
|
+
}
|
|
450
407
|
/**
|
|
451
408
|
* returns a boolean if the given credential is removed
|
|
452
409
|
* @param credential
|
|
453
410
|
*/
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
return
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
case 1:
|
|
471
|
-
_a.trys.push([1, 3, , 4]);
|
|
472
|
-
return [4 /*yield*/, this.cryptoImpl.removeTokenBindingKey(kid)];
|
|
473
|
-
case 2:
|
|
474
|
-
_a.sent();
|
|
475
|
-
return [3 /*break*/, 4];
|
|
476
|
-
case 3:
|
|
477
|
-
_a.sent();
|
|
411
|
+
async removeAccessToken(key) {
|
|
412
|
+
const credential = this.getAccessTokenCredential(key);
|
|
413
|
+
if (!credential) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
// Remove Token Binding Key from key store for PoP Tokens Credentials
|
|
417
|
+
if (credential.credentialType.toLowerCase() ===
|
|
418
|
+
CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()) {
|
|
419
|
+
if (credential.tokenType === AuthenticationScheme.POP) {
|
|
420
|
+
const accessTokenWithAuthSchemeEntity = credential;
|
|
421
|
+
const kid = accessTokenWithAuthSchemeEntity.keyId;
|
|
422
|
+
if (kid) {
|
|
423
|
+
try {
|
|
424
|
+
await this.cryptoImpl.removeTokenBindingKey(kid);
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
478
427
|
throw ClientAuthError.createBindingKeyNotRemovedError();
|
|
479
|
-
|
|
428
|
+
}
|
|
480
429
|
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return this.removeItem(key);
|
|
433
|
+
}
|
|
484
434
|
/**
|
|
485
435
|
* Removes all app metadata objects from cache.
|
|
486
436
|
*/
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
_this.removeItem(cacheKey);
|
|
437
|
+
removeAppMetadata() {
|
|
438
|
+
const allCacheKeys = this.getKeys();
|
|
439
|
+
allCacheKeys.forEach((cacheKey) => {
|
|
440
|
+
if (this.isAppMetadata(cacheKey)) {
|
|
441
|
+
this.removeItem(cacheKey);
|
|
493
442
|
}
|
|
494
443
|
});
|
|
495
444
|
return true;
|
|
496
|
-
}
|
|
445
|
+
}
|
|
497
446
|
/**
|
|
498
447
|
* Retrieve the cached credentials into a cacherecord
|
|
499
448
|
* @param account
|
|
@@ -502,13 +451,13 @@ var CacheManager = /** @class */ (function () {
|
|
|
502
451
|
* @param environment
|
|
503
452
|
* @param authScheme
|
|
504
453
|
*/
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
454
|
+
readCacheRecord(account, request, environment) {
|
|
455
|
+
const tokenKeys = this.getTokenKeys();
|
|
456
|
+
const cachedAccount = this.readAccountFromCache(account);
|
|
457
|
+
const cachedIdToken = this.getIdToken(account, tokenKeys);
|
|
458
|
+
const cachedAccessToken = this.getAccessToken(account, request, tokenKeys);
|
|
459
|
+
const cachedRefreshToken = this.getRefreshToken(account, false, tokenKeys);
|
|
460
|
+
const cachedAppMetadata = this.readAppMetadataFromCache(environment);
|
|
512
461
|
if (cachedAccount && cachedIdToken) {
|
|
513
462
|
cachedAccount.idTokenClaims = new AuthToken(cachedIdToken.secret, this.cryptoImpl).claims;
|
|
514
463
|
}
|
|
@@ -519,32 +468,32 @@ var CacheManager = /** @class */ (function () {
|
|
|
519
468
|
refreshToken: cachedRefreshToken,
|
|
520
469
|
appMetadata: cachedAppMetadata,
|
|
521
470
|
};
|
|
522
|
-
}
|
|
471
|
+
}
|
|
523
472
|
/**
|
|
524
473
|
* Retrieve AccountEntity from cache
|
|
525
474
|
* @param account
|
|
526
475
|
*/
|
|
527
|
-
|
|
528
|
-
|
|
476
|
+
readAccountFromCache(account) {
|
|
477
|
+
const accountKey = AccountEntity.generateAccountCacheKey(account);
|
|
529
478
|
return this.getAccount(accountKey);
|
|
530
|
-
}
|
|
479
|
+
}
|
|
531
480
|
/**
|
|
532
481
|
* Retrieve IdTokenEntity from cache
|
|
533
482
|
* @param clientId
|
|
534
483
|
* @param account
|
|
535
484
|
* @param inputRealm
|
|
536
485
|
*/
|
|
537
|
-
|
|
486
|
+
getIdToken(account, tokenKeys) {
|
|
538
487
|
this.commonLogger.trace("CacheManager - getIdToken called");
|
|
539
|
-
|
|
488
|
+
const idTokenFilter = {
|
|
540
489
|
homeAccountId: account.homeAccountId,
|
|
541
490
|
environment: account.environment,
|
|
542
491
|
credentialType: CredentialType.ID_TOKEN,
|
|
543
492
|
clientId: this.clientId,
|
|
544
493
|
realm: account.tenantId,
|
|
545
494
|
};
|
|
546
|
-
|
|
547
|
-
|
|
495
|
+
const idTokens = this.getIdTokensByFilter(idTokenFilter, tokenKeys);
|
|
496
|
+
const numIdTokens = idTokens.length;
|
|
548
497
|
if (numIdTokens < 1) {
|
|
549
498
|
this.commonLogger.info("CacheManager:getIdToken - No token found");
|
|
550
499
|
return null;
|
|
@@ -554,57 +503,61 @@ var CacheManager = /** @class */ (function () {
|
|
|
554
503
|
}
|
|
555
504
|
this.commonLogger.info("CacheManager:getIdToken - Returning id token");
|
|
556
505
|
return idTokens[0];
|
|
557
|
-
}
|
|
506
|
+
}
|
|
558
507
|
/**
|
|
559
508
|
* Gets all idTokens matching the given filter
|
|
560
509
|
* @param filter
|
|
561
510
|
* @returns
|
|
562
511
|
*/
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
512
|
+
getIdTokensByFilter(filter, tokenKeys) {
|
|
513
|
+
const idTokenKeys = (tokenKeys && tokenKeys.idToken) || this.getTokenKeys().idToken;
|
|
514
|
+
const idTokens = [];
|
|
515
|
+
idTokenKeys.forEach((key) => {
|
|
516
|
+
if (!this.idTokenKeyMatchesFilter(key, {
|
|
517
|
+
clientId: this.clientId,
|
|
518
|
+
...filter,
|
|
519
|
+
})) {
|
|
569
520
|
return;
|
|
570
521
|
}
|
|
571
|
-
|
|
572
|
-
if (idToken &&
|
|
522
|
+
const idToken = this.getIdTokenCredential(key);
|
|
523
|
+
if (idToken && this.credentialMatchesFilter(idToken, filter)) {
|
|
573
524
|
idTokens.push(idToken);
|
|
574
525
|
}
|
|
575
526
|
});
|
|
576
527
|
return idTokens;
|
|
577
|
-
}
|
|
528
|
+
}
|
|
578
529
|
/**
|
|
579
530
|
* Validate the cache key against filter before retrieving and parsing cache value
|
|
580
531
|
* @param key
|
|
581
532
|
* @param filter
|
|
582
533
|
* @returns
|
|
583
534
|
*/
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
if (filter.clientId &&
|
|
535
|
+
idTokenKeyMatchesFilter(inputKey, filter) {
|
|
536
|
+
const key = inputKey.toLowerCase();
|
|
537
|
+
if (filter.clientId &&
|
|
538
|
+
key.indexOf(filter.clientId.toLowerCase()) === -1) {
|
|
587
539
|
return false;
|
|
588
540
|
}
|
|
589
|
-
if (filter.homeAccountId &&
|
|
541
|
+
if (filter.homeAccountId &&
|
|
542
|
+
key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
|
|
590
543
|
return false;
|
|
591
544
|
}
|
|
592
545
|
return true;
|
|
593
|
-
}
|
|
546
|
+
}
|
|
594
547
|
/**
|
|
595
548
|
* Removes idToken from the cache
|
|
596
549
|
* @param key
|
|
597
550
|
*/
|
|
598
|
-
|
|
551
|
+
removeIdToken(key) {
|
|
599
552
|
this.removeItem(key);
|
|
600
|
-
}
|
|
553
|
+
}
|
|
601
554
|
/**
|
|
602
555
|
* Removes refresh token from the cache
|
|
603
556
|
* @param key
|
|
604
557
|
*/
|
|
605
|
-
|
|
558
|
+
removeRefreshToken(key) {
|
|
606
559
|
this.removeItem(key);
|
|
607
|
-
}
|
|
560
|
+
}
|
|
608
561
|
/**
|
|
609
562
|
* Retrieve AccessTokenEntity from cache
|
|
610
563
|
* @param clientId
|
|
@@ -612,17 +565,20 @@ var CacheManager = /** @class */ (function () {
|
|
|
612
565
|
* @param scopes
|
|
613
566
|
* @param authScheme
|
|
614
567
|
*/
|
|
615
|
-
|
|
616
|
-
var _this = this;
|
|
568
|
+
getAccessToken(account, request, tokenKeys) {
|
|
617
569
|
this.commonLogger.trace("CacheManager - getAccessToken called");
|
|
618
|
-
|
|
619
|
-
|
|
570
|
+
const scopes = ScopeSet.createSearchScopes(request.scopes);
|
|
571
|
+
const authScheme = request.authenticationScheme || AuthenticationScheme.BEARER;
|
|
620
572
|
/*
|
|
621
573
|
* Distinguish between Bearer and PoP/SSH token cache types
|
|
622
574
|
* Cast to lowercase to handle "bearer" from ADFS
|
|
623
575
|
*/
|
|
624
|
-
|
|
625
|
-
|
|
576
|
+
const credentialType = authScheme &&
|
|
577
|
+
authScheme.toLowerCase() !==
|
|
578
|
+
AuthenticationScheme.BEARER.toLowerCase()
|
|
579
|
+
? CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME
|
|
580
|
+
: CredentialType.ACCESS_TOKEN;
|
|
581
|
+
const accessTokenFilter = {
|
|
626
582
|
homeAccountId: account.homeAccountId,
|
|
627
583
|
environment: account.environment,
|
|
628
584
|
credentialType: credentialType,
|
|
@@ -633,19 +589,21 @@ var CacheManager = /** @class */ (function () {
|
|
|
633
589
|
keyId: request.sshKid,
|
|
634
590
|
requestedClaimsHash: request.requestedClaimsHash,
|
|
635
591
|
};
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
592
|
+
const accessTokenKeys = (tokenKeys && tokenKeys.accessToken) ||
|
|
593
|
+
this.getTokenKeys().accessToken;
|
|
594
|
+
const accessTokens = [];
|
|
595
|
+
accessTokenKeys.forEach((key) => {
|
|
639
596
|
// Validate key
|
|
640
|
-
if (
|
|
641
|
-
|
|
597
|
+
if (this.accessTokenKeyMatchesFilter(key, accessTokenFilter, true)) {
|
|
598
|
+
const accessToken = this.getAccessTokenCredential(key);
|
|
642
599
|
// Validate value
|
|
643
|
-
if (accessToken &&
|
|
600
|
+
if (accessToken &&
|
|
601
|
+
this.credentialMatchesFilter(accessToken, accessTokenFilter)) {
|
|
644
602
|
accessTokens.push(accessToken);
|
|
645
603
|
}
|
|
646
604
|
}
|
|
647
605
|
});
|
|
648
|
-
|
|
606
|
+
const numAccessTokens = accessTokens.length;
|
|
649
607
|
if (numAccessTokens < 1) {
|
|
650
608
|
this.commonLogger.info("CacheManager:getAccessToken - No token found");
|
|
651
609
|
return null;
|
|
@@ -655,7 +613,7 @@ var CacheManager = /** @class */ (function () {
|
|
|
655
613
|
}
|
|
656
614
|
this.commonLogger.info("CacheManager:getAccessToken - Returning access token");
|
|
657
615
|
return accessTokens[0];
|
|
658
|
-
}
|
|
616
|
+
}
|
|
659
617
|
/**
|
|
660
618
|
* Validate the cache key against filter before retrieving and parsing cache value
|
|
661
619
|
* @param key
|
|
@@ -663,85 +621,91 @@ var CacheManager = /** @class */ (function () {
|
|
|
663
621
|
* @param keyMustContainAllScopes
|
|
664
622
|
* @returns
|
|
665
623
|
*/
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
if (filter.clientId &&
|
|
624
|
+
accessTokenKeyMatchesFilter(inputKey, filter, keyMustContainAllScopes) {
|
|
625
|
+
const key = inputKey.toLowerCase();
|
|
626
|
+
if (filter.clientId &&
|
|
627
|
+
key.indexOf(filter.clientId.toLowerCase()) === -1) {
|
|
669
628
|
return false;
|
|
670
629
|
}
|
|
671
|
-
if (filter.homeAccountId &&
|
|
630
|
+
if (filter.homeAccountId &&
|
|
631
|
+
key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
|
|
672
632
|
return false;
|
|
673
633
|
}
|
|
674
634
|
if (filter.realm && key.indexOf(filter.realm.toLowerCase()) === -1) {
|
|
675
635
|
return false;
|
|
676
636
|
}
|
|
677
|
-
if (filter.requestedClaimsHash &&
|
|
637
|
+
if (filter.requestedClaimsHash &&
|
|
638
|
+
key.indexOf(filter.requestedClaimsHash.toLowerCase()) === -1) {
|
|
678
639
|
return false;
|
|
679
640
|
}
|
|
680
641
|
if (filter.target) {
|
|
681
|
-
|
|
682
|
-
for (
|
|
683
|
-
if (keyMustContainAllScopes &&
|
|
642
|
+
const scopes = filter.target.asArray();
|
|
643
|
+
for (let i = 0; i < scopes.length; i++) {
|
|
644
|
+
if (keyMustContainAllScopes &&
|
|
645
|
+
!key.includes(scopes[i].toLowerCase())) {
|
|
684
646
|
// When performing a cache lookup a missing scope would be a cache miss
|
|
685
647
|
return false;
|
|
686
648
|
}
|
|
687
|
-
else if (!keyMustContainAllScopes &&
|
|
649
|
+
else if (!keyMustContainAllScopes &&
|
|
650
|
+
key.includes(scopes[i].toLowerCase())) {
|
|
688
651
|
// When performing a cache write, any token with a subset of requested scopes should be replaced
|
|
689
652
|
return true;
|
|
690
653
|
}
|
|
691
654
|
}
|
|
692
655
|
}
|
|
693
656
|
return true;
|
|
694
|
-
}
|
|
657
|
+
}
|
|
695
658
|
/**
|
|
696
659
|
* Gets all access tokens matching the filter
|
|
697
660
|
* @param filter
|
|
698
661
|
* @returns
|
|
699
662
|
*/
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
if (!_this.accessTokenKeyMatchesFilter(key, filter, true)) {
|
|
663
|
+
getAccessTokensByFilter(filter) {
|
|
664
|
+
const tokenKeys = this.getTokenKeys();
|
|
665
|
+
const accessTokens = [];
|
|
666
|
+
tokenKeys.accessToken.forEach((key) => {
|
|
667
|
+
if (!this.accessTokenKeyMatchesFilter(key, filter, true)) {
|
|
706
668
|
return;
|
|
707
669
|
}
|
|
708
|
-
|
|
709
|
-
if (accessToken &&
|
|
670
|
+
const accessToken = this.getAccessTokenCredential(key);
|
|
671
|
+
if (accessToken &&
|
|
672
|
+
this.credentialMatchesFilter(accessToken, filter)) {
|
|
710
673
|
accessTokens.push(accessToken);
|
|
711
674
|
}
|
|
712
675
|
});
|
|
713
676
|
return accessTokens;
|
|
714
|
-
}
|
|
677
|
+
}
|
|
715
678
|
/**
|
|
716
679
|
* Helper to retrieve the appropriate refresh token from cache
|
|
717
680
|
* @param clientId
|
|
718
681
|
* @param account
|
|
719
682
|
* @param familyRT
|
|
720
683
|
*/
|
|
721
|
-
|
|
722
|
-
var _this = this;
|
|
684
|
+
getRefreshToken(account, familyRT, tokenKeys) {
|
|
723
685
|
this.commonLogger.trace("CacheManager - getRefreshToken called");
|
|
724
|
-
|
|
725
|
-
|
|
686
|
+
const id = familyRT ? THE_FAMILY_ID : undefined;
|
|
687
|
+
const refreshTokenFilter = {
|
|
726
688
|
homeAccountId: account.homeAccountId,
|
|
727
689
|
environment: account.environment,
|
|
728
690
|
credentialType: CredentialType.REFRESH_TOKEN,
|
|
729
691
|
clientId: this.clientId,
|
|
730
692
|
familyId: id,
|
|
731
693
|
};
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
694
|
+
const refreshTokenKeys = (tokenKeys && tokenKeys.refreshToken) ||
|
|
695
|
+
this.getTokenKeys().refreshToken;
|
|
696
|
+
const refreshTokens = [];
|
|
697
|
+
refreshTokenKeys.forEach((key) => {
|
|
735
698
|
// Validate key
|
|
736
|
-
if (
|
|
737
|
-
|
|
699
|
+
if (this.refreshTokenKeyMatchesFilter(key, refreshTokenFilter)) {
|
|
700
|
+
const refreshToken = this.getRefreshTokenCredential(key);
|
|
738
701
|
// Validate value
|
|
739
|
-
if (refreshToken &&
|
|
702
|
+
if (refreshToken &&
|
|
703
|
+
this.credentialMatchesFilter(refreshToken, refreshTokenFilter)) {
|
|
740
704
|
refreshTokens.push(refreshToken);
|
|
741
705
|
}
|
|
742
706
|
}
|
|
743
707
|
});
|
|
744
|
-
|
|
708
|
+
const numRefreshTokens = refreshTokens.length;
|
|
745
709
|
if (numRefreshTokens < 1) {
|
|
746
710
|
this.commonLogger.info("CacheManager:getRefreshToken - No refresh token found.");
|
|
747
711
|
return null;
|
|
@@ -749,37 +713,41 @@ var CacheManager = /** @class */ (function () {
|
|
|
749
713
|
// address the else case after remove functions address environment aliases
|
|
750
714
|
this.commonLogger.info("CacheManager:getRefreshToken - returning refresh token");
|
|
751
715
|
return refreshTokens[0];
|
|
752
|
-
}
|
|
716
|
+
}
|
|
753
717
|
/**
|
|
754
718
|
* Validate the cache key against filter before retrieving and parsing cache value
|
|
755
719
|
* @param key
|
|
756
720
|
* @param filter
|
|
757
721
|
*/
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
if (filter.familyId &&
|
|
722
|
+
refreshTokenKeyMatchesFilter(inputKey, filter) {
|
|
723
|
+
const key = inputKey.toLowerCase();
|
|
724
|
+
if (filter.familyId &&
|
|
725
|
+
key.indexOf(filter.familyId.toLowerCase()) === -1) {
|
|
761
726
|
return false;
|
|
762
727
|
}
|
|
763
728
|
// If familyId is used, clientId is not in the key
|
|
764
|
-
if (!filter.familyId &&
|
|
729
|
+
if (!filter.familyId &&
|
|
730
|
+
filter.clientId &&
|
|
731
|
+
key.indexOf(filter.clientId.toLowerCase()) === -1) {
|
|
765
732
|
return false;
|
|
766
733
|
}
|
|
767
|
-
if (filter.homeAccountId &&
|
|
734
|
+
if (filter.homeAccountId &&
|
|
735
|
+
key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
|
|
768
736
|
return false;
|
|
769
737
|
}
|
|
770
738
|
return true;
|
|
771
|
-
}
|
|
739
|
+
}
|
|
772
740
|
/**
|
|
773
741
|
* Retrieve AppMetadataEntity from cache
|
|
774
742
|
*/
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
environment
|
|
743
|
+
readAppMetadataFromCache(environment) {
|
|
744
|
+
const appMetadataFilter = {
|
|
745
|
+
environment,
|
|
778
746
|
clientId: this.clientId,
|
|
779
747
|
};
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
748
|
+
const appMetadata = this.getAppMetadataFilteredBy(appMetadataFilter);
|
|
749
|
+
const appMetadataEntries = Object.keys(appMetadata).map((key) => appMetadata[key]);
|
|
750
|
+
const numAppMetadata = appMetadataEntries.length;
|
|
783
751
|
if (numAppMetadata < 1) {
|
|
784
752
|
return null;
|
|
785
753
|
}
|
|
@@ -787,273 +755,270 @@ var CacheManager = /** @class */ (function () {
|
|
|
787
755
|
throw ClientAuthError.createMultipleMatchingAppMetadataInCacheError();
|
|
788
756
|
}
|
|
789
757
|
return appMetadataEntries[0];
|
|
790
|
-
}
|
|
758
|
+
}
|
|
791
759
|
/**
|
|
792
760
|
* Return the family_id value associated with FOCI
|
|
793
761
|
* @param environment
|
|
794
762
|
* @param clientId
|
|
795
763
|
*/
|
|
796
|
-
|
|
797
|
-
|
|
764
|
+
isAppMetadataFOCI(environment) {
|
|
765
|
+
const appMetadata = this.readAppMetadataFromCache(environment);
|
|
798
766
|
return !!(appMetadata && appMetadata.familyId === THE_FAMILY_ID);
|
|
799
|
-
}
|
|
767
|
+
}
|
|
800
768
|
/**
|
|
801
769
|
* helper to match account ids
|
|
802
770
|
* @param value
|
|
803
771
|
* @param homeAccountId
|
|
804
772
|
*/
|
|
805
|
-
|
|
806
|
-
return !!(
|
|
807
|
-
|
|
773
|
+
matchHomeAccountId(entity, homeAccountId) {
|
|
774
|
+
return !!(typeof entity.homeAccountId === "string" &&
|
|
775
|
+
homeAccountId === entity.homeAccountId);
|
|
776
|
+
}
|
|
808
777
|
/**
|
|
809
778
|
* helper to match account ids
|
|
810
779
|
* @param entity
|
|
811
780
|
* @param localAccountId
|
|
812
781
|
* @returns
|
|
813
782
|
*/
|
|
814
|
-
|
|
815
|
-
return !!(
|
|
816
|
-
|
|
783
|
+
matchLocalAccountId(entity, localAccountId) {
|
|
784
|
+
return !!(typeof entity.localAccountId === "string" &&
|
|
785
|
+
localAccountId === entity.localAccountId);
|
|
786
|
+
}
|
|
817
787
|
/**
|
|
818
788
|
* helper to match usernames
|
|
819
789
|
* @param entity
|
|
820
790
|
* @param username
|
|
821
791
|
* @returns
|
|
822
792
|
*/
|
|
823
|
-
|
|
824
|
-
return !!(
|
|
825
|
-
|
|
793
|
+
matchUsername(entity, username) {
|
|
794
|
+
return !!(typeof entity.username === "string" &&
|
|
795
|
+
username.toLowerCase() === entity.username.toLowerCase());
|
|
796
|
+
}
|
|
826
797
|
/**
|
|
827
798
|
* helper to match assertion
|
|
828
799
|
* @param value
|
|
829
800
|
* @param oboAssertion
|
|
830
801
|
*/
|
|
831
|
-
|
|
832
|
-
return !!(entity.userAssertionHash &&
|
|
833
|
-
|
|
802
|
+
matchUserAssertionHash(entity, userAssertionHash) {
|
|
803
|
+
return !!(entity.userAssertionHash &&
|
|
804
|
+
userAssertionHash === entity.userAssertionHash);
|
|
805
|
+
}
|
|
834
806
|
/**
|
|
835
807
|
* helper to match environment
|
|
836
808
|
* @param value
|
|
837
809
|
* @param environment
|
|
838
810
|
*/
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
if (cloudMetadata &&
|
|
811
|
+
matchEnvironment(entity, environment) {
|
|
812
|
+
const cloudMetadata = this.getAuthorityMetadataByAlias(environment);
|
|
813
|
+
if (cloudMetadata &&
|
|
814
|
+
cloudMetadata.aliases.indexOf(entity.environment) > -1) {
|
|
842
815
|
return true;
|
|
843
816
|
}
|
|
844
817
|
return false;
|
|
845
|
-
}
|
|
818
|
+
}
|
|
846
819
|
/**
|
|
847
820
|
* helper to match credential type
|
|
848
821
|
* @param entity
|
|
849
822
|
* @param credentialType
|
|
850
823
|
*/
|
|
851
|
-
|
|
852
|
-
return (entity.credentialType &&
|
|
853
|
-
|
|
824
|
+
matchCredentialType(entity, credentialType) {
|
|
825
|
+
return (entity.credentialType &&
|
|
826
|
+
credentialType.toLowerCase() === entity.credentialType.toLowerCase());
|
|
827
|
+
}
|
|
854
828
|
/**
|
|
855
829
|
* helper to match client ids
|
|
856
830
|
* @param entity
|
|
857
831
|
* @param clientId
|
|
858
832
|
*/
|
|
859
|
-
|
|
833
|
+
matchClientId(entity, clientId) {
|
|
860
834
|
return !!(entity.clientId && clientId === entity.clientId);
|
|
861
|
-
}
|
|
835
|
+
}
|
|
862
836
|
/**
|
|
863
837
|
* helper to match family ids
|
|
864
838
|
* @param entity
|
|
865
839
|
* @param familyId
|
|
866
840
|
*/
|
|
867
|
-
|
|
841
|
+
matchFamilyId(entity, familyId) {
|
|
868
842
|
return !!(entity.familyId && familyId === entity.familyId);
|
|
869
|
-
}
|
|
843
|
+
}
|
|
870
844
|
/**
|
|
871
845
|
* helper to match realm
|
|
872
846
|
* @param entity
|
|
873
847
|
* @param realm
|
|
874
848
|
*/
|
|
875
|
-
|
|
849
|
+
matchRealm(entity, realm) {
|
|
876
850
|
return !!(entity.realm && realm === entity.realm);
|
|
877
|
-
}
|
|
851
|
+
}
|
|
878
852
|
/**
|
|
879
853
|
* helper to match nativeAccountId
|
|
880
854
|
* @param entity
|
|
881
855
|
* @param nativeAccountId
|
|
882
856
|
* @returns boolean indicating the match result
|
|
883
857
|
*/
|
|
884
|
-
|
|
858
|
+
matchNativeAccountId(entity, nativeAccountId) {
|
|
885
859
|
return !!(entity.nativeAccountId && nativeAccountId === entity.nativeAccountId);
|
|
886
|
-
}
|
|
860
|
+
}
|
|
887
861
|
/**
|
|
888
862
|
* Returns true if the target scopes are a subset of the current entity's scopes, false otherwise.
|
|
889
863
|
* @param entity
|
|
890
864
|
* @param target
|
|
891
865
|
*/
|
|
892
|
-
|
|
893
|
-
|
|
866
|
+
matchTarget(entity, target) {
|
|
867
|
+
const isNotAccessTokenCredential = entity.credentialType !== CredentialType.ACCESS_TOKEN &&
|
|
868
|
+
entity.credentialType !==
|
|
869
|
+
CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME;
|
|
894
870
|
if (isNotAccessTokenCredential || !entity.target) {
|
|
895
871
|
return false;
|
|
896
872
|
}
|
|
897
|
-
|
|
873
|
+
const entityScopeSet = ScopeSet.fromString(entity.target);
|
|
898
874
|
return entityScopeSet.containsScopeSet(target);
|
|
899
|
-
}
|
|
875
|
+
}
|
|
900
876
|
/**
|
|
901
877
|
* Returns true if the credential's tokenType or Authentication Scheme matches the one in the request, false otherwise
|
|
902
878
|
* @param entity
|
|
903
879
|
* @param tokenType
|
|
904
880
|
*/
|
|
905
|
-
|
|
881
|
+
matchTokenType(entity, tokenType) {
|
|
906
882
|
return !!(entity.tokenType && entity.tokenType === tokenType);
|
|
907
|
-
}
|
|
883
|
+
}
|
|
908
884
|
/**
|
|
909
885
|
* Returns true if the credential's keyId matches the one in the request, false otherwise
|
|
910
886
|
* @param entity
|
|
911
887
|
* @param tokenType
|
|
912
888
|
*/
|
|
913
|
-
|
|
889
|
+
matchKeyId(entity, keyId) {
|
|
914
890
|
return !!(entity.keyId && entity.keyId === keyId);
|
|
915
|
-
}
|
|
891
|
+
}
|
|
916
892
|
/**
|
|
917
893
|
* returns if a given cache entity is of the type appmetadata
|
|
918
894
|
* @param key
|
|
919
895
|
*/
|
|
920
|
-
|
|
896
|
+
isAppMetadata(key) {
|
|
921
897
|
return key.indexOf(APP_METADATA) !== -1;
|
|
922
|
-
}
|
|
898
|
+
}
|
|
923
899
|
/**
|
|
924
900
|
* returns if a given cache entity is of the type authoritymetadata
|
|
925
901
|
* @param key
|
|
926
902
|
*/
|
|
927
|
-
|
|
903
|
+
isAuthorityMetadata(key) {
|
|
928
904
|
return key.indexOf(AUTHORITY_METADATA_CONSTANTS.CACHE_KEY) !== -1;
|
|
929
|
-
}
|
|
905
|
+
}
|
|
930
906
|
/**
|
|
931
907
|
* returns cache key used for cloud instance metadata
|
|
932
908
|
*/
|
|
933
|
-
|
|
934
|
-
return AUTHORITY_METADATA_CONSTANTS.CACHE_KEY
|
|
935
|
-
}
|
|
909
|
+
generateAuthorityMetadataCacheKey(authority) {
|
|
910
|
+
return `${AUTHORITY_METADATA_CONSTANTS.CACHE_KEY}-${this.clientId}-${authority}`;
|
|
911
|
+
}
|
|
936
912
|
/**
|
|
937
913
|
* Helper to convert serialized data to object
|
|
938
914
|
* @param obj
|
|
939
915
|
* @param json
|
|
940
916
|
*/
|
|
941
|
-
|
|
942
|
-
for (
|
|
917
|
+
static toObject(obj, json) {
|
|
918
|
+
for (const propertyName in json) {
|
|
943
919
|
obj[propertyName] = json[propertyName];
|
|
944
920
|
}
|
|
945
921
|
return obj;
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
function DefaultStorageClass() {
|
|
952
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
953
|
-
}
|
|
954
|
-
DefaultStorageClass.prototype.setAccount = function () {
|
|
955
|
-
var notImplErr = "Storage interface - setAccount() has not been implemented for the cacheStorage interface.";
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
class DefaultStorageClass extends CacheManager {
|
|
925
|
+
setAccount() {
|
|
926
|
+
const notImplErr = "Storage interface - setAccount() has not been implemented for the cacheStorage interface.";
|
|
956
927
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
|
|
928
|
+
}
|
|
929
|
+
getAccount() {
|
|
930
|
+
const notImplErr = "Storage interface - getAccount() has not been implemented for the cacheStorage interface.";
|
|
960
931
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
|
|
932
|
+
}
|
|
933
|
+
setIdTokenCredential() {
|
|
934
|
+
const notImplErr = "Storage interface - setIdTokenCredential() has not been implemented for the cacheStorage interface.";
|
|
964
935
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
|
|
936
|
+
}
|
|
937
|
+
getIdTokenCredential() {
|
|
938
|
+
const notImplErr = "Storage interface - getIdTokenCredential() has not been implemented for the cacheStorage interface.";
|
|
968
939
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
|
|
940
|
+
}
|
|
941
|
+
setAccessTokenCredential() {
|
|
942
|
+
const notImplErr = "Storage interface - setAccessTokenCredential() has not been implemented for the cacheStorage interface.";
|
|
972
943
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
|
|
944
|
+
}
|
|
945
|
+
getAccessTokenCredential() {
|
|
946
|
+
const notImplErr = "Storage interface - getAccessTokenCredential() has not been implemented for the cacheStorage interface.";
|
|
976
947
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
|
|
948
|
+
}
|
|
949
|
+
setRefreshTokenCredential() {
|
|
950
|
+
const notImplErr = "Storage interface - setRefreshTokenCredential() has not been implemented for the cacheStorage interface.";
|
|
980
951
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
|
|
952
|
+
}
|
|
953
|
+
getRefreshTokenCredential() {
|
|
954
|
+
const notImplErr = "Storage interface - getRefreshTokenCredential() has not been implemented for the cacheStorage interface.";
|
|
984
955
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
|
|
956
|
+
}
|
|
957
|
+
setAppMetadata() {
|
|
958
|
+
const notImplErr = "Storage interface - setAppMetadata() has not been implemented for the cacheStorage interface.";
|
|
988
959
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
|
|
960
|
+
}
|
|
961
|
+
getAppMetadata() {
|
|
962
|
+
const notImplErr = "Storage interface - getAppMetadata() has not been implemented for the cacheStorage interface.";
|
|
963
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
964
|
+
}
|
|
965
|
+
setServerTelemetry() {
|
|
966
|
+
const notImplErr = "Storage interface - setServerTelemetry() has not been implemented for the cacheStorage interface.";
|
|
992
967
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
|
|
968
|
+
}
|
|
969
|
+
getServerTelemetry() {
|
|
970
|
+
const notImplErr = "Storage interface - getServerTelemetry() has not been implemented for the cacheStorage interface.";
|
|
996
971
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
|
|
972
|
+
}
|
|
973
|
+
setAuthorityMetadata() {
|
|
974
|
+
const notImplErr = "Storage interface - setAuthorityMetadata() has not been implemented for the cacheStorage interface.";
|
|
1000
975
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
|
|
976
|
+
}
|
|
977
|
+
getAuthorityMetadata() {
|
|
978
|
+
const notImplErr = "Storage interface - getAuthorityMetadata() has not been implemented for the cacheStorage interface.";
|
|
1004
979
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
|
|
980
|
+
}
|
|
981
|
+
getAuthorityMetadataKeys() {
|
|
982
|
+
const notImplErr = "Storage interface - getAuthorityMetadataKeys() has not been implemented for the cacheStorage interface.";
|
|
1008
983
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
|
|
984
|
+
}
|
|
985
|
+
setThrottlingCache() {
|
|
986
|
+
const notImplErr = "Storage interface - setThrottlingCache() has not been implemented for the cacheStorage interface.";
|
|
1012
987
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
|
|
988
|
+
}
|
|
989
|
+
getThrottlingCache() {
|
|
990
|
+
const notImplErr = "Storage interface - getThrottlingCache() has not been implemented for the cacheStorage interface.";
|
|
1016
991
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
|
|
992
|
+
}
|
|
993
|
+
removeItem() {
|
|
994
|
+
const notImplErr = "Storage interface - removeItem() has not been implemented for the cacheStorage interface.";
|
|
1020
995
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
|
|
996
|
+
}
|
|
997
|
+
containsKey() {
|
|
998
|
+
const notImplErr = "Storage interface - containsKey() has not been implemented for the cacheStorage interface.";
|
|
1024
999
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1000
|
+
}
|
|
1001
|
+
getKeys() {
|
|
1002
|
+
const notImplErr = "Storage interface - getKeys() has not been implemented for the cacheStorage interface.";
|
|
1028
1003
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1004
|
+
}
|
|
1005
|
+
getAccountKeys() {
|
|
1006
|
+
const notImplErr = "Storage interface - getAccountKeys() has not been implemented for the cacheStorage interface.";
|
|
1032
1007
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1008
|
+
}
|
|
1009
|
+
getTokenKeys() {
|
|
1010
|
+
const notImplErr = "Storage interface - getTokenKeys() has not been implemented for the cacheStorage interface.";
|
|
1036
1011
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1012
|
+
}
|
|
1013
|
+
async clear() {
|
|
1014
|
+
const notImplErr = "Storage interface - clear() has not been implemented for the cacheStorage interface.";
|
|
1040
1015
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
var notImplErr;
|
|
1045
|
-
return __generator(this, function (_a) {
|
|
1046
|
-
notImplErr = "Storage interface - clear() has not been implemented for the cacheStorage interface.";
|
|
1047
|
-
throw AuthError.createUnexpectedError(notImplErr);
|
|
1048
|
-
});
|
|
1049
|
-
});
|
|
1050
|
-
};
|
|
1051
|
-
DefaultStorageClass.prototype.updateCredentialCacheKey = function () {
|
|
1052
|
-
var notImplErr = "Storage interface - updateCredentialCacheKey() has not been implemented for the cacheStorage interface.";
|
|
1016
|
+
}
|
|
1017
|
+
updateCredentialCacheKey() {
|
|
1018
|
+
const notImplErr = "Storage interface - updateCredentialCacheKey() has not been implemented for the cacheStorage interface.";
|
|
1053
1019
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
}(CacheManager));
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1057
1022
|
|
|
1058
1023
|
export { CacheManager, DefaultStorageClass };
|
|
1059
1024
|
//# sourceMappingURL=CacheManager.js.map
|