@azure/msal-common 14.4.1-beta.1 → 14.5.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/account/AccountInfo.d.ts +58 -31
- package/dist/account/AccountInfo.d.ts.map +1 -1
- package/dist/account/AccountInfo.mjs +64 -0
- package/dist/account/AccountInfo.mjs.map +1 -0
- package/dist/account/AuthToken.d.ts +17 -17
- package/dist/account/AuthToken.mjs +58 -58
- package/dist/account/AuthToken.mjs.map +1 -1
- package/dist/account/CcsCredential.d.ts +9 -9
- package/dist/account/CcsCredential.mjs +8 -8
- package/dist/account/CcsCredential.mjs.map +1 -1
- package/dist/account/ClientCredentials.d.ts +14 -14
- package/dist/account/ClientInfo.d.ts +18 -19
- package/dist/account/ClientInfo.d.ts.map +1 -1
- package/dist/account/ClientInfo.mjs +37 -37
- package/dist/account/ClientInfo.mjs.map +1 -1
- package/dist/account/TokenClaims.d.ts +83 -65
- package/dist/account/TokenClaims.d.ts.map +1 -1
- package/dist/account/TokenClaims.mjs +25 -0
- package/dist/account/TokenClaims.mjs.map +1 -0
- package/dist/authority/Authority.d.ts +253 -249
- package/dist/authority/Authority.d.ts.map +1 -1
- package/dist/authority/Authority.mjs +812 -789
- package/dist/authority/Authority.mjs.map +1 -1
- package/dist/authority/AuthorityFactory.d.ts +31 -31
- package/dist/authority/AuthorityFactory.mjs +47 -47
- package/dist/authority/AuthorityFactory.mjs.map +1 -1
- package/dist/authority/AuthorityMetadata.d.ts +503 -503
- package/dist/authority/AuthorityMetadata.mjs +603 -603
- package/dist/authority/AuthorityMetadata.mjs.map +1 -1
- package/dist/authority/AuthorityOptions.d.ts +27 -27
- package/dist/authority/AuthorityOptions.mjs +18 -18
- package/dist/authority/AuthorityOptions.mjs.map +1 -1
- package/dist/authority/AuthorityType.d.ts +10 -10
- package/dist/authority/AuthorityType.mjs +13 -13
- package/dist/authority/AuthorityType.mjs.map +1 -1
- package/dist/authority/AzureRegion.d.ts +1 -1
- package/dist/authority/AzureRegionConfiguration.d.ts +5 -5
- package/dist/authority/CloudDiscoveryMetadata.d.ts +5 -5
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.d.ts +13 -13
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +8 -8
- package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs.map +1 -1
- package/dist/authority/CloudInstanceDiscoveryResponse.d.ts +9 -9
- package/dist/authority/CloudInstanceDiscoveryResponse.mjs +8 -8
- package/dist/authority/CloudInstanceDiscoveryResponse.mjs.map +1 -1
- package/dist/authority/ImdsOptions.d.ts +5 -5
- package/dist/authority/OIDCOptions.d.ts +8 -8
- package/dist/authority/OpenIdConfigResponse.d.ts +11 -11
- package/dist/authority/OpenIdConfigResponse.mjs +10 -10
- package/dist/authority/OpenIdConfigResponse.mjs.map +1 -1
- package/dist/authority/ProtocolMode.d.ts +8 -8
- package/dist/authority/ProtocolMode.mjs +11 -11
- package/dist/authority/ProtocolMode.mjs.map +1 -1
- package/dist/authority/RegionDiscovery.d.ts +32 -32
- package/dist/authority/RegionDiscovery.mjs +106 -106
- package/dist/authority/RegionDiscovery.mjs.map +1 -1
- package/dist/authority/RegionDiscoveryMetadata.d.ts +6 -6
- package/dist/broker/nativeBroker/INativeBrokerPlugin.d.ts +15 -15
- package/dist/cache/CacheManager.d.ts +517 -485
- package/dist/cache/CacheManager.d.ts.map +1 -1
- package/dist/cache/CacheManager.mjs +1264 -1102
- package/dist/cache/CacheManager.mjs.map +1 -1
- package/dist/cache/entities/AccessTokenEntity.d.ts +25 -25
- package/dist/cache/entities/AccountEntity.d.ts +106 -101
- package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
- package/dist/cache/entities/AccountEntity.mjs +247 -219
- package/dist/cache/entities/AccountEntity.mjs.map +1 -1
- package/dist/cache/entities/AppMetadataEntity.d.ts +39 -39
- package/dist/cache/entities/AppMetadataEntity.mjs +66 -66
- package/dist/cache/entities/AppMetadataEntity.mjs.map +1 -1
- package/dist/cache/entities/AuthorityMetadataEntity.d.ts +48 -48
- package/dist/cache/entities/AuthorityMetadataEntity.mjs +78 -78
- package/dist/cache/entities/AuthorityMetadataEntity.mjs.map +1 -1
- package/dist/cache/entities/CacheRecord.d.ts +14 -14
- package/dist/cache/entities/CacheRecord.mjs +14 -14
- package/dist/cache/entities/CacheRecord.mjs.map +1 -1
- package/dist/cache/entities/CredentialEntity.d.ts +30 -30
- package/dist/cache/entities/IdTokenEntity.d.ts +8 -8
- package/dist/cache/entities/RefreshTokenEntity.d.ts +5 -7
- package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
- package/dist/cache/entities/ServerTelemetryEntity.d.ts +5 -5
- package/dist/cache/entities/ThrottlingEntity.d.ts +13 -13
- package/dist/cache/entities/ThrottlingEntity.mjs +23 -23
- package/dist/cache/entities/ThrottlingEntity.mjs.map +1 -1
- package/dist/cache/interface/ICacheManager.d.ts +166 -166
- package/dist/cache/interface/ICachePlugin.d.ts +5 -5
- package/dist/cache/interface/ISerializableTokenCache.d.ts +4 -4
- package/dist/cache/persistence/TokenCacheContext.d.ts +23 -23
- package/dist/cache/persistence/TokenCacheContext.mjs +25 -25
- package/dist/cache/persistence/TokenCacheContext.mjs.map +1 -1
- package/dist/cache/utils/CacheHelpers.d.ts +64 -64
- package/dist/cache/utils/CacheHelpers.d.ts.map +1 -1
- package/dist/cache/utils/CacheHelpers.mjs +231 -234
- package/dist/cache/utils/CacheHelpers.mjs.map +1 -1
- package/dist/cache/utils/CacheTypes.d.ts +69 -67
- package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.d.ts +74 -74
- package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
- package/dist/client/AuthorizationCodeClient.mjs +404 -403
- package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
- package/dist/client/BaseClient.d.ts +51 -51
- package/dist/client/BaseClient.mjs +100 -100
- package/dist/client/BaseClient.mjs.map +1 -1
- package/dist/client/RefreshTokenClient.d.ts +35 -35
- package/dist/client/RefreshTokenClient.d.ts.map +1 -1
- package/dist/client/RefreshTokenClient.mjs +189 -194
- package/dist/client/RefreshTokenClient.mjs.map +1 -1
- package/dist/client/SilentFlowClient.d.ts +27 -27
- package/dist/client/SilentFlowClient.mjs +118 -118
- package/dist/client/SilentFlowClient.mjs.map +1 -1
- package/dist/config/AppTokenProvider.d.ts +38 -38
- package/dist/config/ClientConfiguration.d.ts +150 -150
- package/dist/config/ClientConfiguration.mjs +97 -97
- package/dist/config/ClientConfiguration.mjs.map +1 -1
- package/dist/constants/AADServerParamKeys.d.ts +52 -0
- package/dist/constants/AADServerParamKeys.d.ts.map +1 -0
- package/dist/constants/AADServerParamKeys.mjs +60 -0
- package/dist/constants/AADServerParamKeys.mjs.map +1 -0
- package/dist/crypto/ICrypto.d.ts +58 -58
- package/dist/crypto/ICrypto.mjs +30 -30
- package/dist/crypto/ICrypto.mjs.map +1 -1
- package/dist/crypto/IGuidGenerator.d.ts +4 -4
- package/dist/crypto/JoseHeader.d.ts +22 -22
- package/dist/crypto/JoseHeader.mjs +37 -37
- package/dist/crypto/JoseHeader.mjs.map +1 -1
- package/dist/crypto/PopTokenGenerator.d.ts +60 -60
- package/dist/crypto/PopTokenGenerator.mjs +82 -82
- package/dist/crypto/PopTokenGenerator.mjs.map +1 -1
- package/dist/crypto/SignedHttpRequest.d.ts +15 -15
- package/dist/error/AuthError.d.ts +44 -44
- package/dist/error/AuthError.mjs +46 -46
- package/dist/error/AuthError.mjs.map +1 -1
- package/dist/error/AuthErrorCodes.d.ts +5 -5
- package/dist/error/AuthErrorCodes.mjs +9 -9
- package/dist/error/AuthErrorCodes.mjs.map +1 -1
- package/dist/error/ClientAuthError.d.ts +237 -237
- package/dist/error/ClientAuthError.mjs +249 -249
- package/dist/error/ClientAuthError.mjs.map +1 -1
- package/dist/error/ClientAuthErrorCodes.d.ts +44 -44
- package/dist/error/ClientAuthErrorCodes.mjs +48 -48
- package/dist/error/ClientAuthErrorCodes.mjs.map +1 -1
- package/dist/error/ClientConfigurationError.d.ts +128 -128
- package/dist/error/ClientConfigurationError.mjs +135 -135
- package/dist/error/ClientConfigurationError.mjs.map +1 -1
- package/dist/error/ClientConfigurationErrorCodes.d.ts +22 -22
- package/dist/error/ClientConfigurationErrorCodes.mjs +26 -26
- package/dist/error/ClientConfigurationErrorCodes.mjs.map +1 -1
- package/dist/error/InteractionRequiredAuthError.d.ts +57 -57
- package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
- package/dist/error/InteractionRequiredAuthError.mjs +77 -78
- package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
- package/dist/error/InteractionRequiredAuthErrorCodes.d.ts +5 -6
- package/dist/error/InteractionRequiredAuthErrorCodes.d.ts.map +1 -1
- package/dist/error/InteractionRequiredAuthErrorCodes.mjs +12 -13
- package/dist/error/InteractionRequiredAuthErrorCodes.mjs.map +1 -1
- package/dist/error/JoseHeaderError.d.ts +15 -15
- package/dist/error/JoseHeaderError.mjs +22 -22
- package/dist/error/JoseHeaderError.mjs.map +1 -1
- package/dist/error/JoseHeaderErrorCodes.d.ts +2 -2
- package/dist/error/JoseHeaderErrorCodes.mjs +6 -6
- package/dist/error/JoseHeaderErrorCodes.mjs.map +1 -1
- package/dist/error/ServerError.d.ts +7 -7
- package/dist/error/ServerError.mjs +14 -14
- package/dist/error/ServerError.mjs.map +1 -1
- package/dist/index.cjs +8645 -8295
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +99 -98
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +7 -3
- package/dist/index.mjs.map +1 -1
- package/dist/logger/Logger.d.ts +95 -95
- package/dist/logger/Logger.mjs +188 -188
- package/dist/logger/Logger.mjs.map +1 -1
- package/dist/network/INetworkModule.d.ts +29 -29
- package/dist/network/INetworkModule.mjs +12 -12
- package/dist/network/INetworkModule.mjs.map +1 -1
- package/dist/network/NetworkManager.d.ts +33 -33
- package/dist/network/NetworkManager.mjs +34 -34
- package/dist/network/NetworkManager.mjs.map +1 -1
- package/dist/network/RequestThumbprint.d.ts +18 -18
- package/dist/network/ThrottlingUtils.d.ts +42 -42
- package/dist/network/ThrottlingUtils.mjs +95 -95
- package/dist/network/ThrottlingUtils.mjs.map +1 -1
- package/dist/packageMetadata.d.ts +2 -2
- package/dist/packageMetadata.d.ts.map +1 -1
- package/dist/packageMetadata.mjs +4 -4
- package/dist/packageMetadata.mjs.map +1 -1
- package/dist/request/AuthenticationHeaderParser.d.ts +19 -19
- package/dist/request/AuthenticationHeaderParser.mjs +55 -55
- package/dist/request/AuthenticationHeaderParser.mjs.map +1 -1
- package/dist/request/BaseAuthRequest.d.ts +43 -43
- package/dist/request/CommonAuthorizationCodeRequest.d.ts +27 -27
- package/dist/request/CommonAuthorizationUrlRequest.d.ts +50 -50
- package/dist/request/CommonClientCredentialRequest.d.ts +17 -17
- package/dist/request/CommonDeviceCodeRequest.d.ts +21 -21
- package/dist/request/CommonEndSessionRequest.d.ts +21 -21
- package/dist/request/CommonOnBehalfOfRequest.d.ts +13 -13
- package/dist/request/CommonRefreshTokenRequest.d.ts +22 -23
- package/dist/request/CommonRefreshTokenRequest.d.ts.map +1 -1
- package/dist/request/CommonSilentFlowRequest.d.ts +20 -21
- package/dist/request/CommonSilentFlowRequest.d.ts.map +1 -1
- package/dist/request/CommonUsernamePasswordRequest.d.ts +17 -17
- package/dist/request/NativeRequest.d.ts +19 -19
- package/dist/request/NativeSignOutRequest.d.ts +5 -5
- package/dist/request/RequestParameterBuilder.d.ts +217 -217
- package/dist/request/RequestParameterBuilder.d.ts.map +1 -1
- package/dist/request/RequestParameterBuilder.mjs +383 -382
- package/dist/request/RequestParameterBuilder.mjs.map +1 -1
- package/dist/request/RequestValidator.d.ts +33 -33
- package/dist/request/RequestValidator.mjs +81 -81
- package/dist/request/RequestValidator.mjs.map +1 -1
- package/dist/request/ScopeSet.d.ts +88 -88
- package/dist/request/ScopeSet.mjs +197 -197
- package/dist/request/ScopeSet.mjs.map +1 -1
- package/dist/request/StoreInCache.d.ts +8 -8
- package/dist/response/AuthenticationResult.d.ts +41 -41
- package/dist/response/AuthorizationCodePayload.d.ts +13 -13
- package/dist/response/DeviceCodeResponse.d.ts +25 -25
- package/dist/response/ExternalTokenResponse.d.ts +15 -15
- package/dist/response/IMDSBadResponse.d.ts +4 -4
- package/dist/response/ResponseHandler.d.ts +69 -67
- package/dist/response/ResponseHandler.d.ts.map +1 -1
- package/dist/response/ResponseHandler.mjs +339 -313
- package/dist/response/ResponseHandler.mjs.map +1 -1
- package/dist/response/ServerAuthorizationCodeResponse.d.ts +25 -25
- package/dist/response/ServerAuthorizationTokenResponse.d.ts +46 -46
- package/dist/telemetry/performance/IPerformanceClient.d.ts +51 -51
- package/dist/telemetry/performance/IPerformanceMeasurement.d.ts +5 -5
- package/dist/telemetry/performance/PerformanceClient.d.ts +191 -191
- package/dist/telemetry/performance/PerformanceClient.mjs +409 -409
- package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
- package/dist/telemetry/performance/PerformanceEvent.d.ts +464 -464
- package/dist/telemetry/performance/PerformanceEvent.mjs +253 -253
- package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
- package/dist/telemetry/performance/StubPerformanceClient.d.ts +24 -24
- package/dist/telemetry/performance/StubPerformanceClient.mjs +76 -76
- package/dist/telemetry/performance/StubPerformanceClient.mjs.map +1 -1
- package/dist/telemetry/server/ServerTelemetryManager.d.ts +66 -66
- package/dist/telemetry/server/ServerTelemetryManager.mjs +201 -201
- package/dist/telemetry/server/ServerTelemetryManager.mjs.map +1 -1
- package/dist/telemetry/server/ServerTelemetryRequest.d.ts +8 -8
- package/dist/url/IUri.d.ts +12 -12
- package/dist/url/UrlString.d.ts +48 -48
- package/dist/url/UrlString.mjs +161 -161
- package/dist/url/UrlString.mjs.map +1 -1
- package/dist/utils/Constants.d.ts +296 -365
- package/dist/utils/Constants.d.ts.map +1 -1
- package/dist/utils/Constants.mjs +309 -376
- package/dist/utils/Constants.mjs.map +1 -1
- package/dist/utils/FunctionWrappers.d.ts +27 -27
- package/dist/utils/FunctionWrappers.mjs +84 -84
- package/dist/utils/FunctionWrappers.mjs.map +1 -1
- package/dist/utils/MsalTypes.d.ts +6 -6
- package/dist/utils/ProtocolUtils.d.ts +42 -42
- package/dist/utils/ProtocolUtils.mjs +69 -69
- package/dist/utils/ProtocolUtils.mjs.map +1 -1
- package/dist/utils/StringUtils.d.ts +40 -40
- package/dist/utils/StringUtils.mjs +95 -95
- package/dist/utils/StringUtils.mjs.map +1 -1
- package/dist/utils/TimeUtils.d.ts +27 -27
- package/dist/utils/TimeUtils.mjs +45 -45
- package/dist/utils/TimeUtils.mjs.map +1 -1
- package/dist/utils/UrlUtils.d.ts +10 -10
- package/dist/utils/UrlUtils.mjs +44 -44
- package/dist/utils/UrlUtils.mjs.map +1 -1
- package/package.json +93 -92
- package/src/account/AccountInfo.ts +96 -0
- package/src/account/ClientInfo.ts +2 -3
- package/src/account/TokenClaims.ts +28 -0
- package/src/authority/Authority.ts +29 -2
- package/src/cache/CacheManager.ts +416 -114
- package/src/cache/entities/AccountEntity.ts +84 -33
- package/src/cache/entities/RefreshTokenEntity.ts +1 -3
- package/src/cache/utils/CacheHelpers.ts +1 -6
- package/src/cache/utils/CacheTypes.ts +11 -0
- package/src/client/AuthorizationCodeClient.ts +4 -5
- package/src/client/RefreshTokenClient.ts +3 -15
- package/src/client/SilentFlowClient.ts +1 -1
- package/src/constants/AADServerParamKeys.ts +56 -0
- package/src/crypto/PopTokenGenerator.ts +1 -1
- package/src/error/InteractionRequiredAuthError.ts +0 -2
- package/src/error/InteractionRequiredAuthErrorCodes.ts +0 -1
- package/src/index.ts +17 -5
- package/src/packageMetadata.ts +1 -1
- package/src/request/CommonRefreshTokenRequest.ts +0 -1
- package/src/request/CommonSilentFlowRequest.ts +0 -1
- package/src/request/RequestParameterBuilder.ts +7 -5
- package/src/response/ResponseHandler.ts +95 -27
- package/src/utils/Constants.ts +0 -72
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
AppMetadataFilter,
|
|
11
11
|
AppMetadataCache,
|
|
12
12
|
TokenKeys,
|
|
13
|
+
TenantProfileFilter,
|
|
13
14
|
} from "./utils/CacheTypes";
|
|
14
15
|
import { CacheRecord } from "./entities/CacheRecord";
|
|
15
16
|
import {
|
|
@@ -32,7 +33,12 @@ import {
|
|
|
32
33
|
createClientAuthError,
|
|
33
34
|
ClientAuthErrorCodes,
|
|
34
35
|
} from "../error/ClientAuthError";
|
|
35
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
AccountInfo,
|
|
38
|
+
TenantProfile,
|
|
39
|
+
tenantIdMatchesHomeTenant,
|
|
40
|
+
updateAccountTenantProfileData,
|
|
41
|
+
} from "../account/AccountInfo";
|
|
36
42
|
import { AppMetadataEntity } from "./entities/AppMetadataEntity";
|
|
37
43
|
import { ServerTelemetryEntity } from "./entities/ServerTelemetryEntity";
|
|
38
44
|
import { ThrottlingEntity } from "./entities/ThrottlingEntity";
|
|
@@ -43,6 +49,7 @@ import { BaseAuthRequest } from "../request/BaseAuthRequest";
|
|
|
43
49
|
import { Logger } from "../logger/Logger";
|
|
44
50
|
import { name, version } from "../packageMetadata";
|
|
45
51
|
import { StoreInCache } from "../request/StoreInCache";
|
|
52
|
+
import { getTenantFromAuthorityString } from "../authority/Authority";
|
|
46
53
|
import { getAliasesFromStaticSources } from "../authority/AuthorityMetadata";
|
|
47
54
|
import { StaticAuthorityOptions } from "../authority/AuthorityOptions";
|
|
48
55
|
import { TokenClaims } from "../account/TokenClaims";
|
|
@@ -75,7 +82,15 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
75
82
|
* fetch the account entity from the platform cache
|
|
76
83
|
* @param accountKey
|
|
77
84
|
*/
|
|
78
|
-
abstract getAccount(
|
|
85
|
+
abstract getAccount(
|
|
86
|
+
accountKey: string,
|
|
87
|
+
logger?: Logger
|
|
88
|
+
): AccountEntity | null;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Returns deserialized account if found in the cache, otherwiser returns null
|
|
92
|
+
*/
|
|
93
|
+
abstract getCachedAccountEntity(accountKey: string): AccountEntity | null;
|
|
79
94
|
|
|
80
95
|
/**
|
|
81
96
|
* set account entity in the platform cache
|
|
@@ -83,6 +98,11 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
83
98
|
*/
|
|
84
99
|
abstract setAccount(account: AccountEntity): void;
|
|
85
100
|
|
|
101
|
+
/**
|
|
102
|
+
* remove account entity from the platform cache if it's outdated
|
|
103
|
+
*/
|
|
104
|
+
abstract removeOutdatedAccount(accountKey: string): void;
|
|
105
|
+
|
|
86
106
|
/**
|
|
87
107
|
* fetch the idToken entity from the platform cache
|
|
88
108
|
* @param idTokenKey
|
|
@@ -238,31 +258,23 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
238
258
|
* @returns Array of AccountInfo objects in cache
|
|
239
259
|
*/
|
|
240
260
|
getAllAccounts(accountFilter?: AccountFilter): AccountInfo[] {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const accountInfo = this.getAccountInfoFromEntity(
|
|
245
|
-
accountEntity,
|
|
246
|
-
accountFilter
|
|
247
|
-
);
|
|
248
|
-
if (accountInfo) {
|
|
249
|
-
validAccounts.push(accountInfo);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
261
|
+
return this.buildTenantProfiles(
|
|
262
|
+
this.getAccountsFilteredBy(accountFilter || {}),
|
|
263
|
+
accountFilter
|
|
252
264
|
);
|
|
253
|
-
return validAccounts;
|
|
254
265
|
}
|
|
255
266
|
|
|
256
267
|
/**
|
|
257
|
-
* Gets
|
|
268
|
+
* Gets first tenanted AccountInfo object found based on provided filters
|
|
258
269
|
*/
|
|
259
270
|
getAccountInfoFilteredBy(accountFilter: AccountFilter): AccountInfo | null {
|
|
260
271
|
const allAccounts = this.getAllAccounts(accountFilter);
|
|
261
272
|
if (allAccounts.length > 1) {
|
|
262
|
-
// If one or more accounts are found,
|
|
263
|
-
|
|
264
|
-
return
|
|
265
|
-
})
|
|
273
|
+
// If one or more accounts are found, prioritize accounts that have an ID token
|
|
274
|
+
const sortedAccounts = allAccounts.sort((account) => {
|
|
275
|
+
return account.idTokenClaims ? -1 : 1;
|
|
276
|
+
});
|
|
277
|
+
return sortedAccounts[0];
|
|
266
278
|
} else if (allAccounts.length === 1) {
|
|
267
279
|
// If only one account is found, return it regardless of whether a matching ID token was found
|
|
268
280
|
return allAccounts[0];
|
|
@@ -285,52 +297,214 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
285
297
|
}
|
|
286
298
|
}
|
|
287
299
|
|
|
288
|
-
|
|
300
|
+
/**
|
|
301
|
+
* Matches filtered account entities with cached ID tokens that match the tenant profile-specific account filters
|
|
302
|
+
* and builds the account info objects from the matching ID token's claims
|
|
303
|
+
* @param cachedAccounts
|
|
304
|
+
* @param accountFilter
|
|
305
|
+
* @returns Array of AccountInfo objects that match account and tenant profile filters
|
|
306
|
+
*/
|
|
307
|
+
private buildTenantProfiles(
|
|
308
|
+
cachedAccounts: AccountEntity[],
|
|
309
|
+
accountFilter?: AccountFilter
|
|
310
|
+
): AccountInfo[] {
|
|
311
|
+
return cachedAccounts.flatMap((accountEntity) => {
|
|
312
|
+
return this.getAccountInfoForTenantProfiles(
|
|
313
|
+
accountEntity,
|
|
314
|
+
accountFilter
|
|
315
|
+
);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private getAccountInfoForTenantProfiles(
|
|
289
320
|
accountEntity: AccountEntity,
|
|
290
321
|
accountFilter?: AccountFilter
|
|
322
|
+
): AccountInfo[] {
|
|
323
|
+
return this.getTenantProfilesFromAccountEntity(
|
|
324
|
+
accountEntity,
|
|
325
|
+
accountFilter?.tenantId,
|
|
326
|
+
accountFilter
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private getTenantedAccountInfoByFilter(
|
|
331
|
+
accountInfo: AccountInfo,
|
|
332
|
+
tokenKeys: TokenKeys,
|
|
333
|
+
tenantProfile: TenantProfile,
|
|
334
|
+
tenantProfileFilter?: TenantProfileFilter
|
|
291
335
|
): AccountInfo | null {
|
|
292
|
-
|
|
293
|
-
|
|
336
|
+
let tenantedAccountInfo: AccountInfo | null = null;
|
|
337
|
+
let idTokenClaims: TokenClaims | undefined;
|
|
338
|
+
|
|
339
|
+
if (tenantProfileFilter) {
|
|
340
|
+
if (
|
|
341
|
+
!this.tenantProfileMatchesFilter(
|
|
342
|
+
tenantProfile,
|
|
343
|
+
tenantProfileFilter
|
|
344
|
+
)
|
|
345
|
+
) {
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const idToken = this.getIdToken(
|
|
351
|
+
accountInfo,
|
|
352
|
+
tokenKeys,
|
|
353
|
+
tenantProfile.tenantId
|
|
354
|
+
);
|
|
355
|
+
|
|
294
356
|
if (idToken) {
|
|
295
|
-
|
|
357
|
+
idTokenClaims = extractTokenClaims(
|
|
296
358
|
idToken.secret,
|
|
297
359
|
this.cryptoImpl.base64Decode
|
|
298
360
|
);
|
|
299
361
|
|
|
300
362
|
if (
|
|
301
|
-
this.
|
|
363
|
+
!this.idTokenClaimsMatchTenantProfileFilter(
|
|
302
364
|
idTokenClaims,
|
|
303
|
-
|
|
365
|
+
tenantProfileFilter
|
|
304
366
|
)
|
|
305
367
|
) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
368
|
+
// ID token sourced claims don't match so this tenant profile is not a match
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// Expand tenant profile into account info based on matching tenant profile and if available matching ID token claims
|
|
374
|
+
tenantedAccountInfo = updateAccountTenantProfileData(
|
|
375
|
+
accountInfo,
|
|
376
|
+
tenantProfile,
|
|
377
|
+
idTokenClaims
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
return tenantedAccountInfo;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
private getTenantProfilesFromAccountEntity(
|
|
384
|
+
accountEntity: AccountEntity,
|
|
385
|
+
targetTenantId?: string,
|
|
386
|
+
tenantProfileFilter?: TenantProfileFilter
|
|
387
|
+
): AccountInfo[] {
|
|
388
|
+
const accountInfo = accountEntity.getAccountInfo();
|
|
389
|
+
let searchTenantProfiles: Map<string, TenantProfile> =
|
|
390
|
+
accountInfo.tenantProfiles || new Map<string, TenantProfile>();
|
|
391
|
+
const tokenKeys = this.getTokenKeys();
|
|
392
|
+
|
|
393
|
+
// If a tenant ID was provided, only return the tenant profile for that tenant ID if it exists
|
|
394
|
+
if (targetTenantId) {
|
|
395
|
+
const tenantProfile = searchTenantProfiles.get(targetTenantId);
|
|
396
|
+
if (tenantProfile) {
|
|
397
|
+
// Reduce search field to just this tenant profile
|
|
398
|
+
searchTenantProfiles = new Map<string, TenantProfile>([
|
|
399
|
+
[targetTenantId, tenantProfile],
|
|
400
|
+
]);
|
|
401
|
+
} else {
|
|
402
|
+
// No tenant profile for search tenant ID, return empty array
|
|
403
|
+
return [];
|
|
309
404
|
}
|
|
310
405
|
}
|
|
311
|
-
|
|
406
|
+
|
|
407
|
+
const matchingTenantProfiles: AccountInfo[] = [];
|
|
408
|
+
searchTenantProfiles.forEach((tenantProfile: TenantProfile) => {
|
|
409
|
+
const tenantedAccountInfo = this.getTenantedAccountInfoByFilter(
|
|
410
|
+
accountInfo,
|
|
411
|
+
tokenKeys,
|
|
412
|
+
tenantProfile,
|
|
413
|
+
tenantProfileFilter
|
|
414
|
+
);
|
|
415
|
+
if (tenantedAccountInfo) {
|
|
416
|
+
matchingTenantProfiles.push(tenantedAccountInfo);
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
return matchingTenantProfiles;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
private tenantProfileMatchesFilter(
|
|
424
|
+
tenantProfile: TenantProfile,
|
|
425
|
+
tenantProfileFilter: TenantProfileFilter
|
|
426
|
+
): boolean {
|
|
427
|
+
if (
|
|
428
|
+
!!tenantProfileFilter.localAccountId &&
|
|
429
|
+
!this.matchLocalAccountIdFromTenantProfile(
|
|
430
|
+
tenantProfile,
|
|
431
|
+
tenantProfileFilter.localAccountId
|
|
432
|
+
)
|
|
433
|
+
) {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (
|
|
438
|
+
!!tenantProfileFilter.name &&
|
|
439
|
+
!(tenantProfile.name === tenantProfileFilter.name)
|
|
440
|
+
) {
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (
|
|
445
|
+
tenantProfileFilter.isHomeTenant !== undefined &&
|
|
446
|
+
!(tenantProfile.isHomeTenant === tenantProfileFilter.isHomeTenant)
|
|
447
|
+
) {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return true;
|
|
312
452
|
}
|
|
313
453
|
|
|
314
|
-
private
|
|
454
|
+
private idTokenClaimsMatchTenantProfileFilter(
|
|
315
455
|
idTokenClaims: TokenClaims,
|
|
316
|
-
|
|
456
|
+
tenantProfileFilter?: TenantProfileFilter
|
|
317
457
|
): boolean {
|
|
318
|
-
|
|
458
|
+
// Tenant Profile filtering
|
|
459
|
+
if (tenantProfileFilter) {
|
|
460
|
+
if (
|
|
461
|
+
!!tenantProfileFilter.localAccountId &&
|
|
462
|
+
!this.matchLocalAccountIdFromTokenClaims(
|
|
463
|
+
idTokenClaims,
|
|
464
|
+
tenantProfileFilter.localAccountId
|
|
465
|
+
)
|
|
466
|
+
) {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (
|
|
471
|
+
!!tenantProfileFilter.loginHint &&
|
|
472
|
+
!this.matchLoginHintFromTokenClaims(
|
|
473
|
+
idTokenClaims,
|
|
474
|
+
tenantProfileFilter.loginHint
|
|
475
|
+
)
|
|
476
|
+
) {
|
|
477
|
+
return false;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (
|
|
481
|
+
!!tenantProfileFilter.username &&
|
|
482
|
+
!this.matchUsername(
|
|
483
|
+
idTokenClaims.preferred_username,
|
|
484
|
+
tenantProfileFilter.username
|
|
485
|
+
)
|
|
486
|
+
) {
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
|
|
319
490
|
if (
|
|
320
|
-
!!
|
|
321
|
-
!this.
|
|
491
|
+
!!tenantProfileFilter.name &&
|
|
492
|
+
!this.matchName(idTokenClaims, tenantProfileFilter.name)
|
|
322
493
|
) {
|
|
323
494
|
return false;
|
|
324
495
|
}
|
|
496
|
+
|
|
325
497
|
if (
|
|
326
|
-
!!
|
|
327
|
-
!this.matchSid(idTokenClaims,
|
|
498
|
+
!!tenantProfileFilter.sid &&
|
|
499
|
+
!this.matchSid(idTokenClaims, tenantProfileFilter.sid)
|
|
328
500
|
) {
|
|
329
501
|
return false;
|
|
330
502
|
}
|
|
331
503
|
}
|
|
504
|
+
|
|
332
505
|
return true;
|
|
333
506
|
}
|
|
507
|
+
|
|
334
508
|
/**
|
|
335
509
|
* saves a cache record
|
|
336
510
|
* @param cacheRecord
|
|
@@ -414,7 +588,7 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
414
588
|
}
|
|
415
589
|
|
|
416
590
|
/**
|
|
417
|
-
* Retrieve
|
|
591
|
+
* Retrieve account entities matching all provided tenant-agnostic filters; if no filter is set, get all account entities in the cache
|
|
418
592
|
* Not checking for casing as keys are all generated in lower case, remember to convert to lower case if object properties are compared
|
|
419
593
|
* @param accountFilter - An object containing Account properties to filter by
|
|
420
594
|
*/
|
|
@@ -422,18 +596,17 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
422
596
|
const allAccountKeys = this.getAccountKeys();
|
|
423
597
|
const matchingAccounts: AccountEntity[] = [];
|
|
424
598
|
allAccountKeys.forEach((cacheKey) => {
|
|
425
|
-
if (
|
|
426
|
-
!this.isAccountKey(
|
|
427
|
-
cacheKey,
|
|
428
|
-
accountFilter.homeAccountId,
|
|
429
|
-
accountFilter.tenantId
|
|
430
|
-
)
|
|
431
|
-
) {
|
|
599
|
+
if (!this.isAccountKey(cacheKey, accountFilter.homeAccountId)) {
|
|
432
600
|
// Don't parse value if the key doesn't match the account filters
|
|
433
601
|
return;
|
|
434
602
|
}
|
|
435
603
|
|
|
436
|
-
const entity: AccountEntity | null = this.getAccount(
|
|
604
|
+
const entity: AccountEntity | null = this.getAccount(
|
|
605
|
+
cacheKey,
|
|
606
|
+
this.commonLogger
|
|
607
|
+
);
|
|
608
|
+
|
|
609
|
+
// Match base account fields
|
|
437
610
|
|
|
438
611
|
if (!entity) {
|
|
439
612
|
return;
|
|
@@ -446,16 +619,9 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
446
619
|
return;
|
|
447
620
|
}
|
|
448
621
|
|
|
449
|
-
if (
|
|
450
|
-
!!accountFilter.localAccountId &&
|
|
451
|
-
!this.matchLocalAccountId(entity, accountFilter.localAccountId)
|
|
452
|
-
) {
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
622
|
if (
|
|
457
623
|
!!accountFilter.username &&
|
|
458
|
-
!this.matchUsername(entity, accountFilter.username)
|
|
624
|
+
!this.matchUsername(entity.username, accountFilter.username)
|
|
459
625
|
) {
|
|
460
626
|
return;
|
|
461
627
|
}
|
|
@@ -474,14 +640,6 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
474
640
|
return;
|
|
475
641
|
}
|
|
476
642
|
|
|
477
|
-
// tenantId is another name for realm
|
|
478
|
-
if (
|
|
479
|
-
!!accountFilter.tenantId &&
|
|
480
|
-
!this.matchRealm(entity, accountFilter.tenantId)
|
|
481
|
-
) {
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
643
|
if (
|
|
486
644
|
!!accountFilter.nativeAccountId &&
|
|
487
645
|
!this.matchNativeAccountId(
|
|
@@ -499,10 +657,23 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
499
657
|
return;
|
|
500
658
|
}
|
|
501
659
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
660
|
+
// If at least one tenant profile matches the tenant profile filter, add the account to the list of matching accounts
|
|
661
|
+
const tenantProfileFilter: TenantProfileFilter = {
|
|
662
|
+
localAccountId: accountFilter?.localAccountId,
|
|
663
|
+
name: accountFilter?.name,
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
const matchingTenantProfiles = entity.tenantProfiles?.filter(
|
|
667
|
+
(tenantProfile: TenantProfile) => {
|
|
668
|
+
return this.tenantProfileMatchesFilter(
|
|
669
|
+
tenantProfile,
|
|
670
|
+
tenantProfileFilter
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
);
|
|
674
|
+
|
|
675
|
+
if (matchingTenantProfiles && matchingTenantProfiles.length === 0) {
|
|
676
|
+
// No tenant profile for this account matches filter, don't add to list of matching accounts
|
|
506
677
|
return;
|
|
507
678
|
}
|
|
508
679
|
|
|
@@ -788,7 +959,7 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
788
959
|
* @param account
|
|
789
960
|
*/
|
|
790
961
|
async removeAccount(accountKey: string): Promise<void> {
|
|
791
|
-
const account = this.getAccount(accountKey);
|
|
962
|
+
const account = this.getAccount(accountKey, this.commonLogger);
|
|
792
963
|
if (!account) {
|
|
793
964
|
return;
|
|
794
965
|
}
|
|
@@ -826,6 +997,88 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
826
997
|
await Promise.all(removedCredentials);
|
|
827
998
|
}
|
|
828
999
|
|
|
1000
|
+
/**
|
|
1001
|
+
* Migrates a single-tenant account and all it's associated alternate cross-tenant account objects in the
|
|
1002
|
+
* cache into a condensed multi-tenant account object with tenant profiles.
|
|
1003
|
+
* @param accountKey
|
|
1004
|
+
* @param accountEntity
|
|
1005
|
+
* @param logger
|
|
1006
|
+
* @returns
|
|
1007
|
+
*/
|
|
1008
|
+
protected updateOutdatedCachedAccount(
|
|
1009
|
+
accountKey: string,
|
|
1010
|
+
accountEntity: AccountEntity | null,
|
|
1011
|
+
logger?: Logger
|
|
1012
|
+
): AccountEntity | null {
|
|
1013
|
+
// Only update if account entity is defined and has no tenantProfiles object (is outdated)
|
|
1014
|
+
if (accountEntity && accountEntity.isSingleTenant()) {
|
|
1015
|
+
this.commonLogger?.verbose(
|
|
1016
|
+
"updateOutdatedCachedAccount: Found a single-tenant (outdated) account entity in the cache, migrating to multi-tenant account entity"
|
|
1017
|
+
);
|
|
1018
|
+
|
|
1019
|
+
// Get keys of all accounts belonging to user
|
|
1020
|
+
const matchingAccountKeys = this.getAccountKeys().filter(
|
|
1021
|
+
(key: string) => {
|
|
1022
|
+
return key.startsWith(accountEntity.homeAccountId);
|
|
1023
|
+
}
|
|
1024
|
+
);
|
|
1025
|
+
|
|
1026
|
+
// Get all account entities belonging to user
|
|
1027
|
+
const accountsToMerge: AccountEntity[] = [];
|
|
1028
|
+
matchingAccountKeys.forEach((key: string) => {
|
|
1029
|
+
const account = this.getCachedAccountEntity(key);
|
|
1030
|
+
if (account) {
|
|
1031
|
+
accountsToMerge.push(account);
|
|
1032
|
+
}
|
|
1033
|
+
});
|
|
1034
|
+
|
|
1035
|
+
// Set base account to home account if available, any account if not
|
|
1036
|
+
const baseAccount =
|
|
1037
|
+
accountsToMerge.find((account) => {
|
|
1038
|
+
return tenantIdMatchesHomeTenant(
|
|
1039
|
+
account.realm,
|
|
1040
|
+
account.homeAccountId
|
|
1041
|
+
);
|
|
1042
|
+
}) || accountsToMerge[0];
|
|
1043
|
+
|
|
1044
|
+
// Populate tenant profiles built from each account entity belonging to the user
|
|
1045
|
+
baseAccount.tenantProfiles = accountsToMerge.map(
|
|
1046
|
+
(account: AccountEntity) => {
|
|
1047
|
+
return {
|
|
1048
|
+
tenantId: account.realm,
|
|
1049
|
+
localAccountId: account.localAccountId,
|
|
1050
|
+
name: account.name,
|
|
1051
|
+
isHomeTenant: tenantIdMatchesHomeTenant(
|
|
1052
|
+
account.realm,
|
|
1053
|
+
account.homeAccountId
|
|
1054
|
+
),
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
);
|
|
1058
|
+
|
|
1059
|
+
const updatedAccount = CacheManager.toObject(new AccountEntity(), {
|
|
1060
|
+
...baseAccount,
|
|
1061
|
+
});
|
|
1062
|
+
|
|
1063
|
+
const newAccountKey = updatedAccount.generateAccountKey();
|
|
1064
|
+
|
|
1065
|
+
// Clear cache of legacy account objects that have been collpsed into tenant profiles
|
|
1066
|
+
matchingAccountKeys.forEach((key: string) => {
|
|
1067
|
+
if (key !== newAccountKey) {
|
|
1068
|
+
this.removeOutdatedAccount(accountKey);
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
// Cache updated account object
|
|
1073
|
+
this.setAccount(updatedAccount);
|
|
1074
|
+
logger?.verbose("Updated an outdated account entity in the cache");
|
|
1075
|
+
return updatedAccount;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
// No update is necessary
|
|
1079
|
+
return accountEntity;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
829
1082
|
/**
|
|
830
1083
|
* returns a boolean if the given credential is removed
|
|
831
1084
|
* @param credential
|
|
@@ -890,11 +1143,15 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
890
1143
|
performanceClient?: IPerformanceClient,
|
|
891
1144
|
correlationId?: string
|
|
892
1145
|
): CacheRecord {
|
|
1146
|
+
// Use authority tenantId for cache lookup filter if it's defined, otherwise use tenantId from account passed in
|
|
1147
|
+
const requestTenantId =
|
|
1148
|
+
account.tenantId || getTenantFromAuthorityString(request.authority);
|
|
893
1149
|
const tokenKeys = this.getTokenKeys();
|
|
894
1150
|
const cachedAccount = this.readAccountFromCache(account);
|
|
895
1151
|
const cachedIdToken = this.getIdToken(
|
|
896
1152
|
account,
|
|
897
1153
|
tokenKeys,
|
|
1154
|
+
requestTenantId,
|
|
898
1155
|
performanceClient,
|
|
899
1156
|
correlationId
|
|
900
1157
|
);
|
|
@@ -902,6 +1159,7 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
902
1159
|
account,
|
|
903
1160
|
request,
|
|
904
1161
|
tokenKeys,
|
|
1162
|
+
requestTenantId,
|
|
905
1163
|
performanceClient,
|
|
906
1164
|
correlationId
|
|
907
1165
|
);
|
|
@@ -914,13 +1172,6 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
914
1172
|
);
|
|
915
1173
|
const cachedAppMetadata = this.readAppMetadataFromCache(environment);
|
|
916
1174
|
|
|
917
|
-
if (cachedAccount && cachedIdToken) {
|
|
918
|
-
cachedAccount.idTokenClaims = extractTokenClaims(
|
|
919
|
-
cachedIdToken.secret,
|
|
920
|
-
this.cryptoImpl.base64Decode
|
|
921
|
-
);
|
|
922
|
-
}
|
|
923
|
-
|
|
924
1175
|
return {
|
|
925
1176
|
account: cachedAccount,
|
|
926
1177
|
idToken: cachedIdToken,
|
|
@@ -937,19 +1188,21 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
937
1188
|
readAccountFromCache(account: AccountInfo): AccountEntity | null {
|
|
938
1189
|
const accountKey: string =
|
|
939
1190
|
AccountEntity.generateAccountCacheKey(account);
|
|
940
|
-
return this.getAccount(accountKey);
|
|
1191
|
+
return this.getAccount(accountKey, this.commonLogger);
|
|
941
1192
|
}
|
|
942
1193
|
|
|
943
1194
|
/**
|
|
944
1195
|
* Retrieve IdTokenEntity from cache
|
|
945
1196
|
* @param account {AccountInfo}
|
|
946
1197
|
* @param tokenKeys {?TokenKeys}
|
|
1198
|
+
* @param targetRealm {?string}
|
|
947
1199
|
* @param performanceClient {?IPerformanceClient}
|
|
948
1200
|
* @param correlationId {?string}
|
|
949
1201
|
*/
|
|
950
1202
|
getIdToken(
|
|
951
1203
|
account: AccountInfo,
|
|
952
1204
|
tokenKeys?: TokenKeys,
|
|
1205
|
+
targetRealm?: string,
|
|
953
1206
|
performanceClient?: IPerformanceClient,
|
|
954
1207
|
correlationId?: string
|
|
955
1208
|
): IdTokenEntity | null {
|
|
@@ -959,36 +1212,66 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
959
1212
|
environment: account.environment,
|
|
960
1213
|
credentialType: CredentialType.ID_TOKEN,
|
|
961
1214
|
clientId: this.clientId,
|
|
962
|
-
realm:
|
|
1215
|
+
realm: targetRealm,
|
|
963
1216
|
};
|
|
964
1217
|
|
|
965
|
-
const
|
|
1218
|
+
const idTokenMap: Map<string, IdTokenEntity> = this.getIdTokensByFilter(
|
|
966
1219
|
idTokenFilter,
|
|
967
1220
|
tokenKeys
|
|
968
1221
|
);
|
|
969
|
-
|
|
1222
|
+
|
|
1223
|
+
const numIdTokens = idTokenMap.size;
|
|
970
1224
|
|
|
971
1225
|
if (numIdTokens < 1) {
|
|
972
1226
|
this.commonLogger.info("CacheManager:getIdToken - No token found");
|
|
973
1227
|
return null;
|
|
974
1228
|
} else if (numIdTokens > 1) {
|
|
1229
|
+
let tokensToBeRemoved: Map<string, IdTokenEntity> = idTokenMap;
|
|
1230
|
+
// Multiple tenant profiles and no tenant specified, pick home account
|
|
1231
|
+
if (!targetRealm) {
|
|
1232
|
+
const homeIdTokenMap: Map<string, IdTokenEntity> = new Map<
|
|
1233
|
+
string,
|
|
1234
|
+
IdTokenEntity
|
|
1235
|
+
>();
|
|
1236
|
+
idTokenMap.forEach((idToken, key) => {
|
|
1237
|
+
if (idToken.realm === account.tenantId) {
|
|
1238
|
+
homeIdTokenMap.set(key, idToken);
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1241
|
+
const numHomeIdTokens = homeIdTokenMap.size;
|
|
1242
|
+
if (numHomeIdTokens < 1) {
|
|
1243
|
+
this.commonLogger.info(
|
|
1244
|
+
"CacheManager:getIdToken - Multiple ID tokens found for account but none match account entity tenant id, returning first result"
|
|
1245
|
+
);
|
|
1246
|
+
return idTokenMap.values().next().value;
|
|
1247
|
+
} else if (numHomeIdTokens === 1) {
|
|
1248
|
+
this.commonLogger.info(
|
|
1249
|
+
"CacheManager:getIdToken - Multiple ID tokens found for account, defaulting to home tenant profile"
|
|
1250
|
+
);
|
|
1251
|
+
return homeIdTokenMap.values().next().value;
|
|
1252
|
+
} else {
|
|
1253
|
+
// Multiple ID tokens for home tenant profile, remove all and return null
|
|
1254
|
+
tokensToBeRemoved = homeIdTokenMap;
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
// Multiple tokens for a single tenant profile, remove all and return null
|
|
975
1258
|
this.commonLogger.info(
|
|
976
|
-
"CacheManager:getIdToken - Multiple
|
|
1259
|
+
"CacheManager:getIdToken - Multiple matching ID tokens found, clearing them"
|
|
977
1260
|
);
|
|
978
|
-
|
|
979
|
-
this.removeIdToken(
|
|
1261
|
+
tokensToBeRemoved.forEach((idToken, key) => {
|
|
1262
|
+
this.removeIdToken(key);
|
|
980
1263
|
});
|
|
981
1264
|
if (performanceClient && correlationId) {
|
|
982
1265
|
performanceClient.addFields(
|
|
983
|
-
{ multiMatchedID:
|
|
1266
|
+
{ multiMatchedID: idTokenMap.size },
|
|
984
1267
|
correlationId
|
|
985
1268
|
);
|
|
986
1269
|
}
|
|
987
1270
|
return null;
|
|
988
1271
|
}
|
|
989
1272
|
|
|
990
|
-
this.commonLogger.info("CacheManager:getIdToken - Returning
|
|
991
|
-
return
|
|
1273
|
+
this.commonLogger.info("CacheManager:getIdToken - Returning ID token");
|
|
1274
|
+
return idTokenMap.values().next().value;
|
|
992
1275
|
}
|
|
993
1276
|
|
|
994
1277
|
/**
|
|
@@ -999,11 +1282,14 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
999
1282
|
getIdTokensByFilter(
|
|
1000
1283
|
filter: CredentialFilter,
|
|
1001
1284
|
tokenKeys?: TokenKeys
|
|
1002
|
-
): IdTokenEntity
|
|
1285
|
+
): Map<string, IdTokenEntity> {
|
|
1003
1286
|
const idTokenKeys =
|
|
1004
1287
|
(tokenKeys && tokenKeys.idToken) || this.getTokenKeys().idToken;
|
|
1005
1288
|
|
|
1006
|
-
const idTokens: IdTokenEntity
|
|
1289
|
+
const idTokens: Map<string, IdTokenEntity> = new Map<
|
|
1290
|
+
string,
|
|
1291
|
+
IdTokenEntity
|
|
1292
|
+
>();
|
|
1007
1293
|
idTokenKeys.forEach((key) => {
|
|
1008
1294
|
if (
|
|
1009
1295
|
!this.idTokenKeyMatchesFilter(key, {
|
|
@@ -1015,7 +1301,7 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
1015
1301
|
}
|
|
1016
1302
|
const idToken = this.getIdTokenCredential(key);
|
|
1017
1303
|
if (idToken && this.credentialMatchesFilter(idToken, filter)) {
|
|
1018
|
-
idTokens.
|
|
1304
|
+
idTokens.set(key, idToken);
|
|
1019
1305
|
}
|
|
1020
1306
|
});
|
|
1021
1307
|
|
|
@@ -1078,6 +1364,7 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
1078
1364
|
account: AccountInfo,
|
|
1079
1365
|
request: BaseAuthRequest,
|
|
1080
1366
|
tokenKeys?: TokenKeys,
|
|
1367
|
+
targetRealm?: string,
|
|
1081
1368
|
performanceClient?: IPerformanceClient,
|
|
1082
1369
|
correlationId?: string
|
|
1083
1370
|
): AccessTokenEntity | null {
|
|
@@ -1101,7 +1388,7 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
1101
1388
|
environment: account.environment,
|
|
1102
1389
|
credentialType: credentialType,
|
|
1103
1390
|
clientId: this.clientId,
|
|
1104
|
-
realm: account.tenantId,
|
|
1391
|
+
realm: targetRealm || account.tenantId,
|
|
1105
1392
|
target: scopes,
|
|
1106
1393
|
tokenType: authScheme,
|
|
1107
1394
|
keyId: request.sshKid,
|
|
@@ -1407,27 +1694,19 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
1407
1694
|
* @param localAccountId
|
|
1408
1695
|
* @returns
|
|
1409
1696
|
*/
|
|
1410
|
-
private
|
|
1411
|
-
|
|
1697
|
+
private matchLocalAccountIdFromTokenClaims(
|
|
1698
|
+
tokenClaims: TokenClaims,
|
|
1412
1699
|
localAccountId: string
|
|
1413
1700
|
): boolean {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
localAccountId === entity.localAccountId
|
|
1417
|
-
);
|
|
1701
|
+
const idTokenLocalAccountId = tokenClaims.oid || tokenClaims.sub;
|
|
1702
|
+
return localAccountId === idTokenLocalAccountId;
|
|
1418
1703
|
}
|
|
1419
1704
|
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
*/
|
|
1426
|
-
private matchUsername(entity: AccountEntity, username: string): boolean {
|
|
1427
|
-
return !!(
|
|
1428
|
-
typeof entity.username === "string" &&
|
|
1429
|
-
username.toLowerCase() === entity.username.toLowerCase()
|
|
1430
|
-
);
|
|
1705
|
+
private matchLocalAccountIdFromTenantProfile(
|
|
1706
|
+
tenantProfile: TenantProfile,
|
|
1707
|
+
localAccountId: string
|
|
1708
|
+
): boolean {
|
|
1709
|
+
return tenantProfile.localAccountId === localAccountId;
|
|
1431
1710
|
}
|
|
1432
1711
|
|
|
1433
1712
|
/**
|
|
@@ -1436,8 +1715,25 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
1436
1715
|
* @param name
|
|
1437
1716
|
* @returns true if the downcased name properties are present and match in the filter and the entity
|
|
1438
1717
|
*/
|
|
1439
|
-
private matchName(
|
|
1440
|
-
return !!(name.toLowerCase() ===
|
|
1718
|
+
private matchName(claims: TokenClaims, name: string): boolean {
|
|
1719
|
+
return !!(name.toLowerCase() === claims.name?.toLowerCase());
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
/**
|
|
1723
|
+
* helper to match usernames
|
|
1724
|
+
* @param entity
|
|
1725
|
+
* @param username
|
|
1726
|
+
* @returns
|
|
1727
|
+
*/
|
|
1728
|
+
private matchUsername(
|
|
1729
|
+
cachedUsername?: string,
|
|
1730
|
+
filterUsername?: string
|
|
1731
|
+
): boolean {
|
|
1732
|
+
return !!(
|
|
1733
|
+
cachedUsername &&
|
|
1734
|
+
typeof cachedUsername === "string" &&
|
|
1735
|
+
filterUsername?.toLowerCase() === cachedUsername.toLowerCase()
|
|
1736
|
+
);
|
|
1441
1737
|
}
|
|
1442
1738
|
|
|
1443
1739
|
/**
|
|
@@ -1537,7 +1833,7 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
1537
1833
|
entity: AccountEntity | CredentialEntity,
|
|
1538
1834
|
realm: string
|
|
1539
1835
|
): boolean {
|
|
1540
|
-
return !!(entity.realm
|
|
1836
|
+
return !!(entity.realm?.toLowerCase() === realm.toLowerCase());
|
|
1541
1837
|
}
|
|
1542
1838
|
|
|
1543
1839
|
/**
|
|
@@ -1564,19 +1860,19 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
1564
1860
|
* @param loginHint
|
|
1565
1861
|
* @returns
|
|
1566
1862
|
*/
|
|
1567
|
-
private
|
|
1568
|
-
|
|
1863
|
+
private matchLoginHintFromTokenClaims(
|
|
1864
|
+
tokenClaims: TokenClaims,
|
|
1569
1865
|
loginHint: string
|
|
1570
1866
|
): boolean {
|
|
1571
|
-
if (
|
|
1867
|
+
if (tokenClaims.login_hint === loginHint) {
|
|
1572
1868
|
return true;
|
|
1573
1869
|
}
|
|
1574
1870
|
|
|
1575
|
-
if (
|
|
1871
|
+
if (tokenClaims.preferred_username === loginHint) {
|
|
1576
1872
|
return true;
|
|
1577
1873
|
}
|
|
1578
1874
|
|
|
1579
|
-
if (
|
|
1875
|
+
if (tokenClaims.upn === loginHint) {
|
|
1580
1876
|
return true;
|
|
1581
1877
|
}
|
|
1582
1878
|
|
|
@@ -1585,12 +1881,12 @@ export abstract class CacheManager implements ICacheManager {
|
|
|
1585
1881
|
|
|
1586
1882
|
/**
|
|
1587
1883
|
* Helper to match sid
|
|
1588
|
-
* @param
|
|
1884
|
+
* @param entity
|
|
1589
1885
|
* @param sid
|
|
1590
1886
|
* @returns true if the sid claim is present and matches the filter
|
|
1591
1887
|
*/
|
|
1592
1888
|
private matchSid(idTokenClaims: TokenClaims, sid: string): boolean {
|
|
1593
|
-
return
|
|
1889
|
+
return idTokenClaims.sid === sid;
|
|
1594
1890
|
}
|
|
1595
1891
|
|
|
1596
1892
|
private matchAuthorityType(
|
|
@@ -1688,6 +1984,9 @@ export class DefaultStorageClass extends CacheManager {
|
|
|
1688
1984
|
getAccount(): AccountEntity {
|
|
1689
1985
|
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
1690
1986
|
}
|
|
1987
|
+
getCachedAccountEntity(): AccountEntity | null {
|
|
1988
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
1989
|
+
}
|
|
1691
1990
|
setIdTokenCredential(): void {
|
|
1692
1991
|
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
1693
1992
|
}
|
|
@@ -1754,4 +2053,7 @@ export class DefaultStorageClass extends CacheManager {
|
|
|
1754
2053
|
updateCredentialCacheKey(): string {
|
|
1755
2054
|
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
1756
2055
|
}
|
|
2056
|
+
removeOutdatedAccount(): void {
|
|
2057
|
+
throw createClientAuthError(ClientAuthErrorCodes.methodNotImplemented);
|
|
2058
|
+
}
|
|
1757
2059
|
}
|