@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
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/*! @azure/msal-common
|
|
1
|
+
/*! @azure/msal-common v12.1.0 2023-04-18 */
|
|
2
2
|
'use strict';
|
|
3
|
-
import { __awaiter, __generator, __extends } from '../_virtual/_tslib.js';
|
|
4
|
-
import {
|
|
5
|
-
import { CredentialEntity } from './entities/CredentialEntity.js';
|
|
3
|
+
import { __awaiter, __generator, __assign, __extends } from '../_virtual/_tslib.js';
|
|
4
|
+
import { Separators, CredentialType, AuthenticationScheme, THE_FAMILY_ID, APP_METADATA, AUTHORITY_METADATA_CONSTANTS } from '../utils/Constants.js';
|
|
6
5
|
import { ScopeSet } from '../request/ScopeSet.js';
|
|
7
6
|
import { AccountEntity } from './entities/AccountEntity.js';
|
|
8
7
|
import { AuthError } from '../error/AuthError.js';
|
|
9
8
|
import { ClientAuthError } from '../error/ClientAuthError.js';
|
|
10
9
|
import { AuthToken } from '../account/AuthToken.js';
|
|
10
|
+
import { name, version } from '../packageMetadata.js';
|
|
11
11
|
|
|
12
12
|
/*
|
|
13
13
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -17,35 +17,59 @@ import { AuthToken } from '../account/AuthToken.js';
|
|
|
17
17
|
* Interface class which implement cache storage functions used by MSAL to perform validity checks, and store tokens.
|
|
18
18
|
*/
|
|
19
19
|
var CacheManager = /** @class */ (function () {
|
|
20
|
-
function CacheManager(clientId, cryptoImpl) {
|
|
20
|
+
function CacheManager(clientId, cryptoImpl, logger) {
|
|
21
21
|
this.clientId = clientId;
|
|
22
22
|
this.cryptoImpl = cryptoImpl;
|
|
23
|
+
this.commonLogger = logger.clone(name, version);
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Returns all accounts in cache
|
|
26
27
|
*/
|
|
27
28
|
CacheManager.prototype.getAllAccounts = function () {
|
|
28
29
|
var _this = this;
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
var allAccountKeys = this.getAccountKeys();
|
|
31
|
+
if (allAccountKeys.length < 1) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
var accountEntities = allAccountKeys.reduce(function (accounts, key) {
|
|
35
|
+
var entity = _this.getAccount(key);
|
|
36
|
+
if (!entity) {
|
|
37
|
+
return accounts;
|
|
38
|
+
}
|
|
39
|
+
accounts.push(entity);
|
|
40
|
+
return accounts;
|
|
41
|
+
}, []);
|
|
42
|
+
if (accountEntities.length < 1) {
|
|
33
43
|
return [];
|
|
34
44
|
}
|
|
35
45
|
else {
|
|
36
|
-
var allAccounts =
|
|
37
|
-
|
|
38
|
-
var accountInfo = accountEntity.getAccountInfo();
|
|
39
|
-
var idToken = _this.readIdTokenFromCache(_this.clientId, accountInfo);
|
|
40
|
-
if (idToken && !accountInfo.idTokenClaims) {
|
|
41
|
-
accountInfo.idToken = idToken.secret;
|
|
42
|
-
accountInfo.idTokenClaims = new AuthToken(idToken.secret, _this.cryptoImpl).claims;
|
|
43
|
-
}
|
|
44
|
-
return accountInfo;
|
|
46
|
+
var allAccounts = accountEntities.map(function (accountEntity) {
|
|
47
|
+
return _this.getAccountInfoFromEntity(accountEntity);
|
|
45
48
|
});
|
|
46
49
|
return allAccounts;
|
|
47
50
|
}
|
|
48
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* Gets accountInfo object based on provided filters
|
|
54
|
+
*/
|
|
55
|
+
CacheManager.prototype.getAccountInfoFilteredBy = function (accountFilter) {
|
|
56
|
+
var allAccounts = this.getAccountsFilteredBy(accountFilter);
|
|
57
|
+
if (allAccounts.length > 0) {
|
|
58
|
+
return this.getAccountInfoFromEntity(allAccounts[0]);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
CacheManager.prototype.getAccountInfoFromEntity = function (accountEntity) {
|
|
65
|
+
var accountInfo = accountEntity.getAccountInfo();
|
|
66
|
+
var idToken = this.getIdToken(accountInfo);
|
|
67
|
+
if (idToken) {
|
|
68
|
+
accountInfo.idToken = idToken.secret;
|
|
69
|
+
accountInfo.idTokenClaims = new AuthToken(idToken.secret, this.cryptoImpl).claims;
|
|
70
|
+
}
|
|
71
|
+
return accountInfo;
|
|
72
|
+
};
|
|
49
73
|
/**
|
|
50
74
|
* saves a cache record
|
|
51
75
|
* @param cacheRecord
|
|
@@ -87,12 +111,12 @@ var CacheManager = /** @class */ (function () {
|
|
|
87
111
|
*/
|
|
88
112
|
CacheManager.prototype.saveAccessToken = function (credential) {
|
|
89
113
|
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
-
var
|
|
114
|
+
var accessTokenFilter, tokenKeys, currentScopes, removedAccessTokens;
|
|
91
115
|
var _this = this;
|
|
92
116
|
return __generator(this, function (_a) {
|
|
93
117
|
switch (_a.label) {
|
|
94
118
|
case 0:
|
|
95
|
-
|
|
119
|
+
accessTokenFilter = {
|
|
96
120
|
clientId: credential.clientId,
|
|
97
121
|
credentialType: credential.credentialType,
|
|
98
122
|
environment: credential.environment,
|
|
@@ -100,22 +124,25 @@ var CacheManager = /** @class */ (function () {
|
|
|
100
124
|
realm: credential.realm,
|
|
101
125
|
tokenType: credential.tokenType,
|
|
102
126
|
requestedClaimsHash: credential.requestedClaimsHash
|
|
103
|
-
}
|
|
127
|
+
};
|
|
128
|
+
tokenKeys = this.getTokenKeys();
|
|
104
129
|
currentScopes = ScopeSet.fromString(credential.target);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
130
|
+
removedAccessTokens = [];
|
|
131
|
+
tokenKeys.accessToken.forEach(function (key) {
|
|
132
|
+
if (!_this.accessTokenKeyMatchesFilter(key, accessTokenFilter, false)) {
|
|
133
|
+
return;
|
|
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
|
+
}
|
|
112
141
|
}
|
|
113
142
|
});
|
|
114
|
-
return [4 /*yield*/, Promise.all(
|
|
143
|
+
return [4 /*yield*/, Promise.all(removedAccessTokens)];
|
|
115
144
|
case 1:
|
|
116
145
|
_a.sent();
|
|
117
|
-
_a.label = 2;
|
|
118
|
-
case 2:
|
|
119
146
|
this.setAccessTokenCredential(credential);
|
|
120
147
|
return [2 /*return*/];
|
|
121
148
|
}
|
|
@@ -130,149 +157,151 @@ var CacheManager = /** @class */ (function () {
|
|
|
130
157
|
* @param realm
|
|
131
158
|
*/
|
|
132
159
|
CacheManager.prototype.getAccountsFilteredBy = function (accountFilter) {
|
|
133
|
-
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);
|
|
134
|
-
};
|
|
135
|
-
/**
|
|
136
|
-
* retrieve accounts matching all provided filters; if no filter is set, get all accounts
|
|
137
|
-
* not checking for casing as keys are all generated in lower case, remember to convert to lower case if object properties are compared
|
|
138
|
-
* @param homeAccountId
|
|
139
|
-
* @param environment
|
|
140
|
-
* @param realm
|
|
141
|
-
*/
|
|
142
|
-
CacheManager.prototype.getAccountsFilteredByInternal = function (homeAccountId, environment, realm, nativeAccountId) {
|
|
143
160
|
var _this = this;
|
|
144
|
-
var
|
|
145
|
-
var matchingAccounts =
|
|
146
|
-
|
|
161
|
+
var allAccountKeys = this.getAccountKeys();
|
|
162
|
+
var matchingAccounts = [];
|
|
163
|
+
allAccountKeys.forEach(function (cacheKey) {
|
|
164
|
+
if (!_this.isAccountKey(cacheKey, accountFilter.homeAccountId, accountFilter.realm)) {
|
|
165
|
+
// Don't parse value if the key doesn't match the account filters
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
147
168
|
var entity = _this.getAccount(cacheKey);
|
|
148
169
|
if (!entity) {
|
|
149
170
|
return;
|
|
150
171
|
}
|
|
151
|
-
if (!!homeAccountId && !_this.matchHomeAccountId(entity, homeAccountId)) {
|
|
172
|
+
if (!!accountFilter.homeAccountId && !_this.matchHomeAccountId(entity, accountFilter.homeAccountId)) {
|
|
152
173
|
return;
|
|
153
174
|
}
|
|
154
|
-
if (!!
|
|
175
|
+
if (!!accountFilter.localAccountId && !_this.matchLocalAccountId(entity, accountFilter.localAccountId)) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (!!accountFilter.username && !_this.matchUsername(entity, accountFilter.username)) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (!!accountFilter.environment && !_this.matchEnvironment(entity, accountFilter.environment)) {
|
|
155
182
|
return;
|
|
156
183
|
}
|
|
157
|
-
if (!!realm && !_this.matchRealm(entity, realm)) {
|
|
184
|
+
if (!!accountFilter.realm && !_this.matchRealm(entity, accountFilter.realm)) {
|
|
158
185
|
return;
|
|
159
186
|
}
|
|
160
|
-
if (!!nativeAccountId && !_this.matchNativeAccountId(entity, nativeAccountId)) {
|
|
187
|
+
if (!!accountFilter.nativeAccountId && !_this.matchNativeAccountId(entity, accountFilter.nativeAccountId)) {
|
|
161
188
|
return;
|
|
162
189
|
}
|
|
163
|
-
matchingAccounts
|
|
190
|
+
matchingAccounts.push(entity);
|
|
164
191
|
});
|
|
165
192
|
return matchingAccounts;
|
|
166
193
|
};
|
|
167
194
|
/**
|
|
168
|
-
*
|
|
195
|
+
* Returns true if the given key matches our account key schema. Also matches homeAccountId and/or tenantId if provided
|
|
196
|
+
* @param key
|
|
169
197
|
* @param homeAccountId
|
|
170
|
-
* @param
|
|
171
|
-
* @
|
|
172
|
-
* @param clientId
|
|
173
|
-
* @param realm
|
|
174
|
-
* @param target
|
|
198
|
+
* @param tenantId
|
|
199
|
+
* @returns
|
|
175
200
|
*/
|
|
176
|
-
CacheManager.prototype.
|
|
177
|
-
|
|
201
|
+
CacheManager.prototype.isAccountKey = function (key, homeAccountId, tenantId) {
|
|
202
|
+
if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 3) {
|
|
203
|
+
// Account cache keys contain 3 items separated by '-' (each item may also contain '-')
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
if (homeAccountId && !key.toLowerCase().includes(homeAccountId.toLowerCase())) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
if (tenantId && !key.toLowerCase().includes(tenantId.toLowerCase())) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
// Do not check environment as aliasing can cause false negatives
|
|
213
|
+
return true;
|
|
178
214
|
};
|
|
179
215
|
/**
|
|
180
|
-
*
|
|
181
|
-
* @param
|
|
182
|
-
* @param environment
|
|
183
|
-
* @param credentialType
|
|
184
|
-
* @param clientId
|
|
185
|
-
* @param realm
|
|
186
|
-
* @param target
|
|
187
|
-
* @param userAssertionHash
|
|
188
|
-
* @param tokenType
|
|
216
|
+
* Returns true if the given key matches our credential key schema.
|
|
217
|
+
* @param key
|
|
189
218
|
*/
|
|
190
|
-
CacheManager.prototype.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
//
|
|
205
|
-
var
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (!!userAssertionHash && !_this.matchUserAssertionHash(entity, userAssertionHash)) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
/*
|
|
213
|
-
* homeAccountId can undefined, and we want to filter out cached items that have a homeAccountId of ""
|
|
214
|
-
* because we don't want a client_credential request to return a cached token that has a homeAccountId
|
|
215
|
-
*/
|
|
216
|
-
if ((typeof homeAccountId === "string") && !_this.matchHomeAccountId(entity, homeAccountId)) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
if (!!environment && !_this.matchEnvironment(entity, environment)) {
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
if (!!realm && !_this.matchRealm(entity, realm)) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
if (!!credentialType && !_this.matchCredentialType(entity, credentialType)) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
if (!!clientId && !_this.matchClientId(entity, clientId)) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
if (!!familyId && !_this.matchFamilyId(entity, familyId)) {
|
|
232
|
-
return;
|
|
219
|
+
CacheManager.prototype.isCredentialKey = function (key) {
|
|
220
|
+
if (key.split(Separators.CACHE_KEY_SEPARATOR).length < 6) {
|
|
221
|
+
// Credential cache keys contain 6 items separated by '-' (each item may also contain '-')
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
var lowerCaseKey = key.toLowerCase();
|
|
225
|
+
// Credential keys must indicate what credential type they represent
|
|
226
|
+
if (lowerCaseKey.indexOf(CredentialType.ID_TOKEN.toLowerCase()) === -1 &&
|
|
227
|
+
lowerCaseKey.indexOf(CredentialType.ACCESS_TOKEN.toLowerCase()) === -1 &&
|
|
228
|
+
lowerCaseKey.indexOf(CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase()) === -1 &&
|
|
229
|
+
lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) === -1) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
if (lowerCaseKey.indexOf(CredentialType.REFRESH_TOKEN.toLowerCase()) > -1) {
|
|
233
|
+
// Refresh tokens must contain the client id or family id
|
|
234
|
+
var clientIdValidation = "" + CredentialType.REFRESH_TOKEN + Separators.CACHE_KEY_SEPARATOR + this.clientId + Separators.CACHE_KEY_SEPARATOR;
|
|
235
|
+
var familyIdValidation = "" + CredentialType.REFRESH_TOKEN + Separators.CACHE_KEY_SEPARATOR + THE_FAMILY_ID + Separators.CACHE_KEY_SEPARATOR;
|
|
236
|
+
if (lowerCaseKey.indexOf(clientIdValidation.toLowerCase()) === -1 && lowerCaseKey.indexOf(familyIdValidation.toLowerCase()) === -1) {
|
|
237
|
+
return false;
|
|
233
238
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
}
|
|
240
|
+
else if (lowerCaseKey.indexOf(this.clientId.toLowerCase()) === -1) {
|
|
241
|
+
// Tokens must contain the clientId
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
return true;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Returns whether or not the given credential entity matches the filter
|
|
248
|
+
* @param entity
|
|
249
|
+
* @param filter
|
|
250
|
+
* @returns
|
|
251
|
+
*/
|
|
252
|
+
CacheManager.prototype.credentialMatchesFilter = function (entity, filter) {
|
|
253
|
+
if (!!filter.clientId && !this.matchClientId(entity, filter.clientId)) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
if (!!filter.userAssertionHash && !this.matchUserAssertionHash(entity, filter.userAssertionHash)) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
/*
|
|
260
|
+
* homeAccountId can be undefined, and we want to filter out cached items that have a homeAccountId of ""
|
|
261
|
+
* because we don't want a client_credential request to return a cached token that has a homeAccountId
|
|
262
|
+
*/
|
|
263
|
+
if ((typeof filter.homeAccountId === "string") && !this.matchHomeAccountId(entity, filter.homeAccountId)) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
if (!!filter.environment && !this.matchEnvironment(entity, filter.environment)) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
if (!!filter.realm && !this.matchRealm(entity, filter.realm)) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
if (!!filter.credentialType && !this.matchCredentialType(entity, filter.credentialType)) {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
if (!!filter.familyId && !this.matchFamilyId(entity, filter.familyId)) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
/*
|
|
279
|
+
* idTokens do not have "target", target specific refreshTokens do exist for some types of authentication
|
|
280
|
+
* Resource specific refresh tokens case will be added when the support is deemed necessary
|
|
281
|
+
*/
|
|
282
|
+
if (!!filter.target && !this.matchTarget(entity, filter.target)) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
// If request OR cached entity has requested Claims Hash, check if they match
|
|
286
|
+
if (filter.requestedClaimsHash || entity.requestedClaimsHash) {
|
|
287
|
+
// Don't match if either is undefined or they are different
|
|
288
|
+
if (entity.requestedClaimsHash !== filter.requestedClaimsHash) {
|
|
289
|
+
return false;
|
|
240
290
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
291
|
+
}
|
|
292
|
+
// Access Token with Auth Scheme specific matching
|
|
293
|
+
if (entity.credentialType === CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME) {
|
|
294
|
+
if (!!filter.tokenType && !this.matchTokenType(entity, filter.tokenType)) {
|
|
295
|
+
return false;
|
|
247
296
|
}
|
|
248
|
-
//
|
|
249
|
-
if (
|
|
250
|
-
if (
|
|
251
|
-
return;
|
|
297
|
+
// KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
|
|
298
|
+
if (filter.tokenType === AuthenticationScheme.SSH) {
|
|
299
|
+
if (filter.keyId && !this.matchKeyId(entity, filter.keyId)) {
|
|
300
|
+
return false;
|
|
252
301
|
}
|
|
253
|
-
// KeyId (sshKid) in request must match cached SSH certificate keyId because SSH cert is bound to a specific key
|
|
254
|
-
if (tokenType === AuthenticationScheme.SSH) {
|
|
255
|
-
if (keyId && !_this.matchKeyId(entity, keyId)) {
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
// At this point, the entity matches the request, update cache key if key schema has changed
|
|
261
|
-
var updatedCacheKey = _this.updateCredentialCacheKey(cacheKey, entity);
|
|
262
|
-
switch (credType) {
|
|
263
|
-
case CredentialType.ID_TOKEN:
|
|
264
|
-
matchingCredentials.idTokens[updatedCacheKey] = entity;
|
|
265
|
-
break;
|
|
266
|
-
case CredentialType.ACCESS_TOKEN:
|
|
267
|
-
case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME:
|
|
268
|
-
matchingCredentials.accessTokens[updatedCacheKey] = entity;
|
|
269
|
-
break;
|
|
270
|
-
case CredentialType.REFRESH_TOKEN:
|
|
271
|
-
matchingCredentials.refreshTokens[updatedCacheKey] = entity;
|
|
272
|
-
break;
|
|
273
302
|
}
|
|
274
|
-
}
|
|
275
|
-
return
|
|
303
|
+
}
|
|
304
|
+
return true;
|
|
276
305
|
};
|
|
277
306
|
/**
|
|
278
307
|
* retrieve appMetadata matching all provided filters; if no filter is set, get all appMetadata
|
|
@@ -340,30 +369,26 @@ var CacheManager = /** @class */ (function () {
|
|
|
340
369
|
*/
|
|
341
370
|
CacheManager.prototype.removeAllAccounts = function () {
|
|
342
371
|
return __awaiter(this, void 0, void 0, function () {
|
|
343
|
-
var
|
|
372
|
+
var allAccountKeys, removedAccounts;
|
|
344
373
|
var _this = this;
|
|
345
374
|
return __generator(this, function (_a) {
|
|
346
375
|
switch (_a.label) {
|
|
347
376
|
case 0:
|
|
348
|
-
|
|
377
|
+
allAccountKeys = this.getAccountKeys();
|
|
349
378
|
removedAccounts = [];
|
|
350
|
-
|
|
351
|
-
var entity = _this.getAccount(cacheKey);
|
|
352
|
-
if (!entity) {
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
379
|
+
allAccountKeys.forEach(function (cacheKey) {
|
|
355
380
|
removedAccounts.push(_this.removeAccount(cacheKey));
|
|
356
381
|
});
|
|
357
382
|
return [4 /*yield*/, Promise.all(removedAccounts)];
|
|
358
383
|
case 1:
|
|
359
384
|
_a.sent();
|
|
360
|
-
return [2 /*return
|
|
385
|
+
return [2 /*return*/];
|
|
361
386
|
}
|
|
362
387
|
});
|
|
363
388
|
});
|
|
364
389
|
};
|
|
365
390
|
/**
|
|
366
|
-
*
|
|
391
|
+
* Removes the account and related tokens for a given account key
|
|
367
392
|
* @param account
|
|
368
393
|
*/
|
|
369
394
|
CacheManager.prototype.removeAccount = function (accountKey) {
|
|
@@ -377,7 +402,10 @@ var CacheManager = /** @class */ (function () {
|
|
|
377
402
|
throw ClientAuthError.createNoAccountFoundError();
|
|
378
403
|
}
|
|
379
404
|
return [4 /*yield*/, this.removeAccountContext(account)];
|
|
380
|
-
case 1:
|
|
405
|
+
case 1:
|
|
406
|
+
_a.sent();
|
|
407
|
+
this.removeItem(accountKey);
|
|
408
|
+
return [2 /*return*/];
|
|
381
409
|
}
|
|
382
410
|
});
|
|
383
411
|
});
|
|
@@ -388,29 +416,33 @@ var CacheManager = /** @class */ (function () {
|
|
|
388
416
|
*/
|
|
389
417
|
CacheManager.prototype.removeAccountContext = function (account) {
|
|
390
418
|
return __awaiter(this, void 0, void 0, function () {
|
|
391
|
-
var
|
|
419
|
+
var allTokenKeys, accountId, removedCredentials;
|
|
392
420
|
var _this = this;
|
|
393
421
|
return __generator(this, function (_a) {
|
|
394
422
|
switch (_a.label) {
|
|
395
423
|
case 0:
|
|
396
|
-
|
|
424
|
+
allTokenKeys = this.getTokenKeys();
|
|
397
425
|
accountId = account.generateAccountId();
|
|
398
426
|
removedCredentials = [];
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
427
|
+
allTokenKeys.idToken.forEach(function (key) {
|
|
428
|
+
if (key.indexOf(accountId) === 0) {
|
|
429
|
+
_this.removeIdToken(key);
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
allTokenKeys.accessToken.forEach(function (key) {
|
|
433
|
+
if (key.indexOf(accountId) === 0) {
|
|
434
|
+
removedCredentials.push(_this.removeAccessToken(key));
|
|
404
435
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
436
|
+
});
|
|
437
|
+
allTokenKeys.refreshToken.forEach(function (key) {
|
|
438
|
+
if (key.indexOf(accountId) === 0) {
|
|
439
|
+
_this.removeRefreshToken(key);
|
|
408
440
|
}
|
|
409
441
|
});
|
|
410
442
|
return [4 /*yield*/, Promise.all(removedCredentials)];
|
|
411
443
|
case 1:
|
|
412
444
|
_a.sent();
|
|
413
|
-
return [2 /*return
|
|
445
|
+
return [2 /*return*/];
|
|
414
446
|
}
|
|
415
447
|
});
|
|
416
448
|
});
|
|
@@ -419,13 +451,16 @@ var CacheManager = /** @class */ (function () {
|
|
|
419
451
|
* returns a boolean if the given credential is removed
|
|
420
452
|
* @param credential
|
|
421
453
|
*/
|
|
422
|
-
CacheManager.prototype.
|
|
454
|
+
CacheManager.prototype.removeAccessToken = function (key) {
|
|
423
455
|
return __awaiter(this, void 0, void 0, function () {
|
|
424
|
-
var
|
|
456
|
+
var credential, accessTokenWithAuthSchemeEntity, kid;
|
|
425
457
|
return __generator(this, function (_a) {
|
|
426
458
|
switch (_a.label) {
|
|
427
459
|
case 0:
|
|
428
|
-
|
|
460
|
+
credential = this.getAccessTokenCredential(key);
|
|
461
|
+
if (!credential) {
|
|
462
|
+
return [2 /*return*/];
|
|
463
|
+
}
|
|
429
464
|
if (!(credential.credentialType.toLowerCase() === CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME.toLowerCase())) return [3 /*break*/, 4];
|
|
430
465
|
if (!(credential.tokenType === AuthenticationScheme.POP)) return [3 /*break*/, 4];
|
|
431
466
|
accessTokenWithAuthSchemeEntity = credential;
|
|
@@ -441,7 +476,7 @@ var CacheManager = /** @class */ (function () {
|
|
|
441
476
|
case 3:
|
|
442
477
|
_a.sent();
|
|
443
478
|
throw ClientAuthError.createBindingKeyNotRemovedError();
|
|
444
|
-
case 4: return [2 /*return*/, this.removeItem(key
|
|
479
|
+
case 4: return [2 /*return*/, this.removeItem(key)];
|
|
445
480
|
}
|
|
446
481
|
});
|
|
447
482
|
});
|
|
@@ -454,7 +489,7 @@ var CacheManager = /** @class */ (function () {
|
|
|
454
489
|
var allCacheKeys = this.getKeys();
|
|
455
490
|
allCacheKeys.forEach(function (cacheKey) {
|
|
456
491
|
if (_this.isAppMetadata(cacheKey)) {
|
|
457
|
-
_this.removeItem(cacheKey
|
|
492
|
+
_this.removeItem(cacheKey);
|
|
458
493
|
}
|
|
459
494
|
});
|
|
460
495
|
return true;
|
|
@@ -467,12 +502,13 @@ var CacheManager = /** @class */ (function () {
|
|
|
467
502
|
* @param environment
|
|
468
503
|
* @param authScheme
|
|
469
504
|
*/
|
|
470
|
-
CacheManager.prototype.readCacheRecord = function (account,
|
|
505
|
+
CacheManager.prototype.readCacheRecord = function (account, request, environment) {
|
|
506
|
+
var tokenKeys = this.getTokenKeys();
|
|
471
507
|
var cachedAccount = this.readAccountFromCache(account);
|
|
472
|
-
var cachedIdToken = this.
|
|
473
|
-
var cachedAccessToken = this.
|
|
474
|
-
var cachedRefreshToken = this.
|
|
475
|
-
var cachedAppMetadata = this.readAppMetadataFromCache(environment
|
|
508
|
+
var cachedIdToken = this.getIdToken(account, tokenKeys);
|
|
509
|
+
var cachedAccessToken = this.getAccessToken(account, request, tokenKeys);
|
|
510
|
+
var cachedRefreshToken = this.getRefreshToken(account, false, tokenKeys);
|
|
511
|
+
var cachedAppMetadata = this.readAppMetadataFromCache(environment);
|
|
476
512
|
if (cachedAccount && cachedIdToken) {
|
|
477
513
|
cachedAccount.idTokenClaims = new AuthToken(cachedIdToken.secret, this.cryptoImpl).claims;
|
|
478
514
|
}
|
|
@@ -492,51 +528,83 @@ var CacheManager = /** @class */ (function () {
|
|
|
492
528
|
var accountKey = AccountEntity.generateAccountCacheKey(account);
|
|
493
529
|
return this.getAccount(accountKey);
|
|
494
530
|
};
|
|
495
|
-
/**
|
|
496
|
-
* Retrieve AccountEntity from cache
|
|
497
|
-
* @param nativeAccountId
|
|
498
|
-
* @returns AccountEntity or Null
|
|
499
|
-
*/
|
|
500
|
-
CacheManager.prototype.readAccountFromCacheWithNativeAccountId = function (nativeAccountId) {
|
|
501
|
-
// fetch account from memory
|
|
502
|
-
var accountFilter = {
|
|
503
|
-
nativeAccountId: nativeAccountId
|
|
504
|
-
};
|
|
505
|
-
var accountCache = this.getAccountsFilteredBy(accountFilter);
|
|
506
|
-
var accounts = Object.keys(accountCache).map(function (key) { return accountCache[key]; });
|
|
507
|
-
if (accounts.length < 1) {
|
|
508
|
-
return null;
|
|
509
|
-
}
|
|
510
|
-
else if (accounts.length > 1) {
|
|
511
|
-
throw ClientAuthError.createMultipleMatchingAccountsInCacheError();
|
|
512
|
-
}
|
|
513
|
-
return accounts[0];
|
|
514
|
-
};
|
|
515
531
|
/**
|
|
516
532
|
* Retrieve IdTokenEntity from cache
|
|
517
533
|
* @param clientId
|
|
518
534
|
* @param account
|
|
519
535
|
* @param inputRealm
|
|
520
536
|
*/
|
|
521
|
-
CacheManager.prototype.
|
|
537
|
+
CacheManager.prototype.getIdToken = function (account, tokenKeys) {
|
|
538
|
+
this.commonLogger.trace("CacheManager - getIdToken called");
|
|
522
539
|
var idTokenFilter = {
|
|
523
540
|
homeAccountId: account.homeAccountId,
|
|
524
541
|
environment: account.environment,
|
|
525
542
|
credentialType: CredentialType.ID_TOKEN,
|
|
526
|
-
clientId: clientId,
|
|
543
|
+
clientId: this.clientId,
|
|
527
544
|
realm: account.tenantId,
|
|
528
545
|
};
|
|
529
|
-
var
|
|
530
|
-
var idTokens = Object.keys(credentialCache.idTokens).map(function (key) { return credentialCache.idTokens[key]; });
|
|
546
|
+
var idTokens = this.getIdTokensByFilter(idTokenFilter, tokenKeys);
|
|
531
547
|
var numIdTokens = idTokens.length;
|
|
532
548
|
if (numIdTokens < 1) {
|
|
549
|
+
this.commonLogger.info("CacheManager:getIdToken - No token found");
|
|
533
550
|
return null;
|
|
534
551
|
}
|
|
535
552
|
else if (numIdTokens > 1) {
|
|
536
553
|
throw ClientAuthError.createMultipleMatchingTokensInCacheError();
|
|
537
554
|
}
|
|
555
|
+
this.commonLogger.info("CacheManager:getIdToken - Returning id token");
|
|
538
556
|
return idTokens[0];
|
|
539
557
|
};
|
|
558
|
+
/**
|
|
559
|
+
* Gets all idTokens matching the given filter
|
|
560
|
+
* @param filter
|
|
561
|
+
* @returns
|
|
562
|
+
*/
|
|
563
|
+
CacheManager.prototype.getIdTokensByFilter = function (filter, tokenKeys) {
|
|
564
|
+
var _this = this;
|
|
565
|
+
var idTokenKeys = tokenKeys && tokenKeys.idToken || this.getTokenKeys().idToken;
|
|
566
|
+
var idTokens = [];
|
|
567
|
+
idTokenKeys.forEach(function (key) {
|
|
568
|
+
if (!_this.idTokenKeyMatchesFilter(key, __assign({ clientId: _this.clientId }, filter))) {
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
var idToken = _this.getIdTokenCredential(key);
|
|
572
|
+
if (idToken && _this.credentialMatchesFilter(idToken, filter)) {
|
|
573
|
+
idTokens.push(idToken);
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
return idTokens;
|
|
577
|
+
};
|
|
578
|
+
/**
|
|
579
|
+
* Validate the cache key against filter before retrieving and parsing cache value
|
|
580
|
+
* @param key
|
|
581
|
+
* @param filter
|
|
582
|
+
* @returns
|
|
583
|
+
*/
|
|
584
|
+
CacheManager.prototype.idTokenKeyMatchesFilter = function (inputKey, filter) {
|
|
585
|
+
var key = inputKey.toLowerCase();
|
|
586
|
+
if (filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {
|
|
587
|
+
return false;
|
|
588
|
+
}
|
|
589
|
+
if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
return true;
|
|
593
|
+
};
|
|
594
|
+
/**
|
|
595
|
+
* Removes idToken from the cache
|
|
596
|
+
* @param key
|
|
597
|
+
*/
|
|
598
|
+
CacheManager.prototype.removeIdToken = function (key) {
|
|
599
|
+
this.removeItem(key);
|
|
600
|
+
};
|
|
601
|
+
/**
|
|
602
|
+
* Removes refresh token from the cache
|
|
603
|
+
* @param key
|
|
604
|
+
*/
|
|
605
|
+
CacheManager.prototype.removeRefreshToken = function (key) {
|
|
606
|
+
this.removeItem(key);
|
|
607
|
+
};
|
|
540
608
|
/**
|
|
541
609
|
* Retrieve AccessTokenEntity from cache
|
|
542
610
|
* @param clientId
|
|
@@ -544,8 +612,10 @@ var CacheManager = /** @class */ (function () {
|
|
|
544
612
|
* @param scopes
|
|
545
613
|
* @param authScheme
|
|
546
614
|
*/
|
|
547
|
-
CacheManager.prototype.
|
|
548
|
-
var
|
|
615
|
+
CacheManager.prototype.getAccessToken = function (account, request, tokenKeys) {
|
|
616
|
+
var _this = this;
|
|
617
|
+
this.commonLogger.trace("CacheManager - getAccessToken called");
|
|
618
|
+
var scopes = ScopeSet.createSearchScopes(request.scopes);
|
|
549
619
|
var authScheme = request.authenticationScheme || AuthenticationScheme.BEARER;
|
|
550
620
|
/*
|
|
551
621
|
* Distinguish between Bearer and PoP/SSH token cache types
|
|
@@ -556,55 +626,156 @@ var CacheManager = /** @class */ (function () {
|
|
|
556
626
|
homeAccountId: account.homeAccountId,
|
|
557
627
|
environment: account.environment,
|
|
558
628
|
credentialType: credentialType,
|
|
559
|
-
clientId: clientId,
|
|
629
|
+
clientId: this.clientId,
|
|
560
630
|
realm: account.tenantId,
|
|
561
|
-
target: scopes
|
|
631
|
+
target: scopes,
|
|
562
632
|
tokenType: authScheme,
|
|
563
633
|
keyId: request.sshKid,
|
|
564
634
|
requestedClaimsHash: request.requestedClaimsHash,
|
|
565
635
|
};
|
|
566
|
-
var
|
|
567
|
-
var accessTokens =
|
|
636
|
+
var accessTokenKeys = tokenKeys && tokenKeys.accessToken || this.getTokenKeys().accessToken;
|
|
637
|
+
var accessTokens = [];
|
|
638
|
+
accessTokenKeys.forEach(function (key) {
|
|
639
|
+
// Validate key
|
|
640
|
+
if (_this.accessTokenKeyMatchesFilter(key, accessTokenFilter, true)) {
|
|
641
|
+
var accessToken = _this.getAccessTokenCredential(key);
|
|
642
|
+
// Validate value
|
|
643
|
+
if (accessToken && _this.credentialMatchesFilter(accessToken, accessTokenFilter)) {
|
|
644
|
+
accessTokens.push(accessToken);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
});
|
|
568
648
|
var numAccessTokens = accessTokens.length;
|
|
569
649
|
if (numAccessTokens < 1) {
|
|
650
|
+
this.commonLogger.info("CacheManager:getAccessToken - No token found");
|
|
570
651
|
return null;
|
|
571
652
|
}
|
|
572
653
|
else if (numAccessTokens > 1) {
|
|
573
654
|
throw ClientAuthError.createMultipleMatchingTokensInCacheError();
|
|
574
655
|
}
|
|
656
|
+
this.commonLogger.info("CacheManager:getAccessToken - Returning access token");
|
|
575
657
|
return accessTokens[0];
|
|
576
658
|
};
|
|
659
|
+
/**
|
|
660
|
+
* Validate the cache key against filter before retrieving and parsing cache value
|
|
661
|
+
* @param key
|
|
662
|
+
* @param filter
|
|
663
|
+
* @param keyMustContainAllScopes
|
|
664
|
+
* @returns
|
|
665
|
+
*/
|
|
666
|
+
CacheManager.prototype.accessTokenKeyMatchesFilter = function (inputKey, filter, keyMustContainAllScopes) {
|
|
667
|
+
var key = inputKey.toLowerCase();
|
|
668
|
+
if (filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {
|
|
669
|
+
return false;
|
|
670
|
+
}
|
|
671
|
+
if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
|
|
672
|
+
return false;
|
|
673
|
+
}
|
|
674
|
+
if (filter.realm && key.indexOf(filter.realm.toLowerCase()) === -1) {
|
|
675
|
+
return false;
|
|
676
|
+
}
|
|
677
|
+
if (filter.requestedClaimsHash && key.indexOf(filter.requestedClaimsHash.toLowerCase()) === -1) {
|
|
678
|
+
return false;
|
|
679
|
+
}
|
|
680
|
+
if (filter.target) {
|
|
681
|
+
var scopes = filter.target.asArray();
|
|
682
|
+
for (var i = 0; i < scopes.length; i++) {
|
|
683
|
+
if (keyMustContainAllScopes && !key.includes(scopes[i].toLowerCase())) {
|
|
684
|
+
// When performing a cache lookup a missing scope would be a cache miss
|
|
685
|
+
return false;
|
|
686
|
+
}
|
|
687
|
+
else if (!keyMustContainAllScopes && key.includes(scopes[i].toLowerCase())) {
|
|
688
|
+
// When performing a cache write, any token with a subset of requested scopes should be replaced
|
|
689
|
+
return true;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
return true;
|
|
694
|
+
};
|
|
695
|
+
/**
|
|
696
|
+
* Gets all access tokens matching the filter
|
|
697
|
+
* @param filter
|
|
698
|
+
* @returns
|
|
699
|
+
*/
|
|
700
|
+
CacheManager.prototype.getAccessTokensByFilter = function (filter) {
|
|
701
|
+
var _this = this;
|
|
702
|
+
var tokenKeys = this.getTokenKeys();
|
|
703
|
+
var accessTokens = [];
|
|
704
|
+
tokenKeys.accessToken.forEach(function (key) {
|
|
705
|
+
if (!_this.accessTokenKeyMatchesFilter(key, filter, true)) {
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
var accessToken = _this.getAccessTokenCredential(key);
|
|
709
|
+
if (accessToken && _this.credentialMatchesFilter(accessToken, filter)) {
|
|
710
|
+
accessTokens.push(accessToken);
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
return accessTokens;
|
|
714
|
+
};
|
|
577
715
|
/**
|
|
578
716
|
* Helper to retrieve the appropriate refresh token from cache
|
|
579
717
|
* @param clientId
|
|
580
718
|
* @param account
|
|
581
719
|
* @param familyRT
|
|
582
720
|
*/
|
|
583
|
-
CacheManager.prototype.
|
|
721
|
+
CacheManager.prototype.getRefreshToken = function (account, familyRT, tokenKeys) {
|
|
722
|
+
var _this = this;
|
|
723
|
+
this.commonLogger.trace("CacheManager - getRefreshToken called");
|
|
584
724
|
var id = familyRT ? THE_FAMILY_ID : undefined;
|
|
585
725
|
var refreshTokenFilter = {
|
|
586
726
|
homeAccountId: account.homeAccountId,
|
|
587
727
|
environment: account.environment,
|
|
588
728
|
credentialType: CredentialType.REFRESH_TOKEN,
|
|
589
|
-
clientId: clientId,
|
|
729
|
+
clientId: this.clientId,
|
|
590
730
|
familyId: id,
|
|
591
731
|
};
|
|
592
|
-
var
|
|
593
|
-
var refreshTokens =
|
|
732
|
+
var refreshTokenKeys = tokenKeys && tokenKeys.refreshToken || this.getTokenKeys().refreshToken;
|
|
733
|
+
var refreshTokens = [];
|
|
734
|
+
refreshTokenKeys.forEach(function (key) {
|
|
735
|
+
// Validate key
|
|
736
|
+
if (_this.refreshTokenKeyMatchesFilter(key, refreshTokenFilter)) {
|
|
737
|
+
var refreshToken = _this.getRefreshTokenCredential(key);
|
|
738
|
+
// Validate value
|
|
739
|
+
if (refreshToken && _this.credentialMatchesFilter(refreshToken, refreshTokenFilter)) {
|
|
740
|
+
refreshTokens.push(refreshToken);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
});
|
|
594
744
|
var numRefreshTokens = refreshTokens.length;
|
|
595
745
|
if (numRefreshTokens < 1) {
|
|
746
|
+
this.commonLogger.info("CacheManager:getRefreshToken - No refresh token found.");
|
|
596
747
|
return null;
|
|
597
748
|
}
|
|
598
749
|
// address the else case after remove functions address environment aliases
|
|
750
|
+
this.commonLogger.info("CacheManager:getRefreshToken - returning refresh token");
|
|
599
751
|
return refreshTokens[0];
|
|
600
752
|
};
|
|
753
|
+
/**
|
|
754
|
+
* Validate the cache key against filter before retrieving and parsing cache value
|
|
755
|
+
* @param key
|
|
756
|
+
* @param filter
|
|
757
|
+
*/
|
|
758
|
+
CacheManager.prototype.refreshTokenKeyMatchesFilter = function (inputKey, filter) {
|
|
759
|
+
var key = inputKey.toLowerCase();
|
|
760
|
+
if (filter.familyId && key.indexOf(filter.familyId.toLowerCase()) === -1) {
|
|
761
|
+
return false;
|
|
762
|
+
}
|
|
763
|
+
// If familyId is used, clientId is not in the key
|
|
764
|
+
if (!filter.familyId && filter.clientId && key.indexOf(filter.clientId.toLowerCase()) === -1) {
|
|
765
|
+
return false;
|
|
766
|
+
}
|
|
767
|
+
if (filter.homeAccountId && key.indexOf(filter.homeAccountId.toLowerCase()) === -1) {
|
|
768
|
+
return false;
|
|
769
|
+
}
|
|
770
|
+
return true;
|
|
771
|
+
};
|
|
601
772
|
/**
|
|
602
773
|
* Retrieve AppMetadataEntity from cache
|
|
603
774
|
*/
|
|
604
|
-
CacheManager.prototype.readAppMetadataFromCache = function (environment
|
|
775
|
+
CacheManager.prototype.readAppMetadataFromCache = function (environment) {
|
|
605
776
|
var appMetadataFilter = {
|
|
606
777
|
environment: environment,
|
|
607
|
-
clientId: clientId,
|
|
778
|
+
clientId: this.clientId,
|
|
608
779
|
};
|
|
609
780
|
var appMetadata = this.getAppMetadataFilteredBy(appMetadataFilter);
|
|
610
781
|
var appMetadataEntries = Object.keys(appMetadata).map(function (key) { return appMetadata[key]; });
|
|
@@ -622,8 +793,8 @@ var CacheManager = /** @class */ (function () {
|
|
|
622
793
|
* @param environment
|
|
623
794
|
* @param clientId
|
|
624
795
|
*/
|
|
625
|
-
CacheManager.prototype.isAppMetadataFOCI = function (environment
|
|
626
|
-
var appMetadata = this.readAppMetadataFromCache(environment
|
|
796
|
+
CacheManager.prototype.isAppMetadataFOCI = function (environment) {
|
|
797
|
+
var appMetadata = this.readAppMetadataFromCache(environment);
|
|
627
798
|
return !!(appMetadata && appMetadata.familyId === THE_FAMILY_ID);
|
|
628
799
|
};
|
|
629
800
|
/**
|
|
@@ -634,6 +805,24 @@ var CacheManager = /** @class */ (function () {
|
|
|
634
805
|
CacheManager.prototype.matchHomeAccountId = function (entity, homeAccountId) {
|
|
635
806
|
return !!((typeof entity.homeAccountId === "string") && (homeAccountId === entity.homeAccountId));
|
|
636
807
|
};
|
|
808
|
+
/**
|
|
809
|
+
* helper to match account ids
|
|
810
|
+
* @param entity
|
|
811
|
+
* @param localAccountId
|
|
812
|
+
* @returns
|
|
813
|
+
*/
|
|
814
|
+
CacheManager.prototype.matchLocalAccountId = function (entity, localAccountId) {
|
|
815
|
+
return !!((typeof entity.localAccountId === "string") && (localAccountId === entity.localAccountId));
|
|
816
|
+
};
|
|
817
|
+
/**
|
|
818
|
+
* helper to match usernames
|
|
819
|
+
* @param entity
|
|
820
|
+
* @param username
|
|
821
|
+
* @returns
|
|
822
|
+
*/
|
|
823
|
+
CacheManager.prototype.matchUsername = function (entity, username) {
|
|
824
|
+
return !!((typeof entity.username === "string") && (username.toLowerCase() === entity.username.toLowerCase()));
|
|
825
|
+
};
|
|
637
826
|
/**
|
|
638
827
|
* helper to match assertion
|
|
639
828
|
* @param value
|
|
@@ -706,14 +895,7 @@ var CacheManager = /** @class */ (function () {
|
|
|
706
895
|
return false;
|
|
707
896
|
}
|
|
708
897
|
var entityScopeSet = ScopeSet.fromString(entity.target);
|
|
709
|
-
|
|
710
|
-
if (!requestTargetScopeSet.containsOnlyOIDCScopes()) {
|
|
711
|
-
requestTargetScopeSet.removeOIDCScopes(); // ignore OIDC scopes
|
|
712
|
-
}
|
|
713
|
-
else {
|
|
714
|
-
requestTargetScopeSet.removeScope(Constants.OFFLINE_ACCESS_SCOPE);
|
|
715
|
-
}
|
|
716
|
-
return entityScopeSet.containsScopeSet(requestTargetScopeSet);
|
|
898
|
+
return entityScopeSet.containsScopeSet(target);
|
|
717
899
|
};
|
|
718
900
|
/**
|
|
719
901
|
* Returns true if the credential's tokenType or Authentication Scheme matches the one in the request, false otherwise
|
|
@@ -751,27 +933,6 @@ var CacheManager = /** @class */ (function () {
|
|
|
751
933
|
CacheManager.prototype.generateAuthorityMetadataCacheKey = function (authority) {
|
|
752
934
|
return AUTHORITY_METADATA_CONSTANTS.CACHE_KEY + "-" + this.clientId + "-" + authority;
|
|
753
935
|
};
|
|
754
|
-
/**
|
|
755
|
-
* Returns the specific credential (IdToken/AccessToken/RefreshToken) from the cache
|
|
756
|
-
* @param key
|
|
757
|
-
* @param credType
|
|
758
|
-
*/
|
|
759
|
-
CacheManager.prototype.getSpecificCredential = function (key, credType) {
|
|
760
|
-
switch (credType) {
|
|
761
|
-
case CredentialType.ID_TOKEN: {
|
|
762
|
-
return this.getIdTokenCredential(key);
|
|
763
|
-
}
|
|
764
|
-
case CredentialType.ACCESS_TOKEN:
|
|
765
|
-
case CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME: {
|
|
766
|
-
return this.getAccessTokenCredential(key);
|
|
767
|
-
}
|
|
768
|
-
case CredentialType.REFRESH_TOKEN: {
|
|
769
|
-
return this.getRefreshTokenCredential(key);
|
|
770
|
-
}
|
|
771
|
-
default:
|
|
772
|
-
return null;
|
|
773
|
-
}
|
|
774
|
-
};
|
|
775
936
|
/**
|
|
776
937
|
* Helper to convert serialized data to object
|
|
777
938
|
* @param obj
|
|
@@ -870,6 +1031,14 @@ var DefaultStorageClass = /** @class */ (function (_super) {
|
|
|
870
1031
|
var notImplErr = "Storage interface - getKeys() has not been implemented for the cacheStorage interface.";
|
|
871
1032
|
throw AuthError.createUnexpectedError(notImplErr);
|
|
872
1033
|
};
|
|
1034
|
+
DefaultStorageClass.prototype.getAccountKeys = function () {
|
|
1035
|
+
var notImplErr = "Storage interface - getAccountKeys() has not been implemented for the cacheStorage interface.";
|
|
1036
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
1037
|
+
};
|
|
1038
|
+
DefaultStorageClass.prototype.getTokenKeys = function () {
|
|
1039
|
+
var notImplErr = "Storage interface - getTokenKeys() has not been implemented for the cacheStorage interface.";
|
|
1040
|
+
throw AuthError.createUnexpectedError(notImplErr);
|
|
1041
|
+
};
|
|
873
1042
|
DefaultStorageClass.prototype.clear = function () {
|
|
874
1043
|
return __awaiter(this, void 0, void 0, function () {
|
|
875
1044
|
var notImplErr;
|