@azure/msal-node 1.3.2 → 1.6.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/CHANGELOG.json +1027 -907
- package/CHANGELOG.md +333 -297
- package/LICENSE +21 -21
- package/README.md +183 -182
- package/dist/cache/NodeStorage.d.ts +5 -1
- package/dist/cache/NodeStorage.d.ts.map +1 -1
- package/dist/cache/distributed/DistributedCachePlugin.d.ts +11 -0
- package/dist/cache/distributed/DistributedCachePlugin.d.ts.map +1 -0
- package/dist/cache/distributed/ICacheClient.d.ts +18 -0
- package/dist/cache/distributed/ICacheClient.d.ts.map +1 -0
- package/dist/cache/distributed/IPartitionManager.d.ts +33 -0
- package/dist/cache/distributed/IPartitionManager.d.ts.map +1 -0
- package/dist/client/ClientApplication.d.ts +2 -2
- package/dist/client/ClientApplication.d.ts.map +1 -1
- package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
- package/dist/client/PublicClientApplication.d.ts.map +1 -1
- package/dist/config/Configuration.d.ts +3 -1
- package/dist/config/Configuration.d.ts.map +1 -1
- package/dist/crypto/CryptoProvider.d.ts +4 -0
- package/dist/crypto/CryptoProvider.d.ts.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/msal-node.cjs.development.js +117 -21
- package/dist/msal-node.cjs.development.js.map +1 -1
- package/dist/msal-node.cjs.production.min.js +1 -1
- package/dist/msal-node.cjs.production.min.js.map +1 -1
- package/dist/msal-node.esm.js +113 -24
- package/dist/msal-node.esm.js.map +1 -1
- package/dist/network/HttpClient.d.ts.map +1 -1
- package/dist/packageMetadata.d.ts +1 -1
- package/dist/request/AuthorizationCodeRequest.d.ts +1 -1
- package/dist/request/AuthorizationCodeRequest.d.ts.map +1 -1
- package/dist/request/AuthorizationUrlRequest.d.ts +1 -1
- package/dist/request/AuthorizationUrlRequest.d.ts.map +1 -1
- package/dist/request/ClientCredentialRequest.d.ts +1 -1
- package/dist/request/ClientCredentialRequest.d.ts.map +1 -1
- package/dist/request/DeviceCodeRequest.d.ts +1 -1
- package/dist/request/DeviceCodeRequest.d.ts.map +1 -1
- package/dist/request/OnBehalfOfRequest.d.ts +1 -1
- package/dist/request/OnBehalfOfRequest.d.ts.map +1 -1
- package/dist/request/RefreshTokenRequest.d.ts +1 -1
- package/dist/request/RefreshTokenRequest.d.ts.map +1 -1
- package/dist/request/SilentFlowRequest.d.ts +1 -1
- package/dist/request/SilentFlowRequest.d.ts.map +1 -1
- package/dist/request/UsernamePasswordRequest.d.ts +1 -1
- package/dist/request/UsernamePasswordRequest.d.ts.map +1 -1
- package/package.json +70 -82
package/dist/msal-node.esm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Constants as Constants$1, ProtocolMode, LogLevel, StringUtils, AccountEntity, CacheManager, IdTokenEntity, AccessTokenEntity, RefreshTokenEntity, AppMetadataEntity, ServerTelemetryEntity, AuthorityMetadataEntity, ThrottlingEntity, TokenCacheContext, Logger, ResponseMode, AuthenticationScheme, AuthorizationCodeClient, AuthError, RefreshTokenClient, SilentFlowClient, UsernamePasswordClient, OIDC_DEFAULT_SCOPES, ServerTelemetryManager, AuthorityFactory, DeviceCodeClient, ClientAuthError, TimeUtils, ClientCredentialClient, OnBehalfOfClient } from '@azure/msal-common';
|
|
2
|
-
export { AuthError, AuthErrorMessage, ClientAuthError, ClientAuthErrorMessage, ClientConfigurationError, ClientConfigurationErrorMessage, InteractionRequiredAuthError, InteractionRequiredAuthErrorMessage, LogLevel, Logger, PromptValue, ProtocolMode, ResponseMode, ServerError, TokenCacheContext } from '@azure/msal-common';
|
|
1
|
+
import { Constants as Constants$1, ProtocolMode, AzureCloudInstance, LogLevel, StringUtils, AccountEntity, CacheManager, IdTokenEntity, AccessTokenEntity, RefreshTokenEntity, AppMetadataEntity, ServerTelemetryEntity, AuthorityMetadataEntity, ThrottlingEntity, TokenCacheContext, Logger, ResponseMode, AuthenticationScheme, AuthorizationCodeClient, AuthError, RefreshTokenClient, SilentFlowClient, UsernamePasswordClient, OIDC_DEFAULT_SCOPES, ServerTelemetryManager, Authority, AuthorityFactory, DeviceCodeClient, ClientAuthError, TimeUtils, ClientCredentialClient, OnBehalfOfClient } from '@azure/msal-common';
|
|
2
|
+
export { AuthError, AuthErrorMessage, AzureCloudInstance, ClientAuthError, ClientAuthErrorMessage, ClientConfigurationError, ClientConfigurationErrorMessage, InteractionRequiredAuthError, InteractionRequiredAuthErrorMessage, LogLevel, Logger, PromptValue, ProtocolMode, ResponseMode, ServerError, TokenCacheContext } from '@azure/msal-common';
|
|
3
3
|
import axios from 'axios';
|
|
4
|
+
import createHttpsProxyAgent from 'https-proxy-agent';
|
|
4
5
|
import { v4 } from 'uuid';
|
|
5
6
|
import crypto from 'crypto';
|
|
6
7
|
import { sign } from 'jsonwebtoken';
|
|
@@ -113,6 +114,13 @@ class HttpClient {
|
|
|
113
114
|
/* istanbul ignore next */
|
|
114
115
|
validateStatus: () => true
|
|
115
116
|
};
|
|
117
|
+
|
|
118
|
+
if (options && options.proxyUrl) {
|
|
119
|
+
// for axios, this has to be disabled
|
|
120
|
+
request.proxy = false;
|
|
121
|
+
request.httpsAgent = createHttpsProxyAgent(options.proxyUrl);
|
|
122
|
+
}
|
|
123
|
+
|
|
116
124
|
const response = await axios(request);
|
|
117
125
|
return {
|
|
118
126
|
headers: response.headers,
|
|
@@ -142,6 +150,13 @@ class HttpClient {
|
|
|
142
150
|
/* istanbul ignore next */
|
|
143
151
|
validateStatus: () => true
|
|
144
152
|
};
|
|
153
|
+
|
|
154
|
+
if (options && options.proxyUrl) {
|
|
155
|
+
// for axios, this has to be disabled
|
|
156
|
+
request.proxy = false;
|
|
157
|
+
request.httpsAgent = createHttpsProxyAgent(options.proxyUrl);
|
|
158
|
+
}
|
|
159
|
+
|
|
145
160
|
const response = await axios(request);
|
|
146
161
|
return {
|
|
147
162
|
headers: response.headers,
|
|
@@ -184,7 +199,11 @@ const DEFAULT_AUTH_OPTIONS = {
|
|
|
184
199
|
cloudDiscoveryMetadata: "",
|
|
185
200
|
authorityMetadata: "",
|
|
186
201
|
clientCapabilities: [],
|
|
187
|
-
protocolMode: ProtocolMode.AAD
|
|
202
|
+
protocolMode: ProtocolMode.AAD,
|
|
203
|
+
azureCloudOptions: {
|
|
204
|
+
azureCloudInstance: AzureCloudInstance.None,
|
|
205
|
+
tenant: ""
|
|
206
|
+
}
|
|
188
207
|
};
|
|
189
208
|
const DEFAULT_CACHE_OPTIONS = {};
|
|
190
209
|
const DEFAULT_LOGGER_OPTIONS = {
|
|
@@ -195,7 +214,8 @@ const DEFAULT_LOGGER_OPTIONS = {
|
|
|
195
214
|
};
|
|
196
215
|
const DEFAULT_SYSTEM_OPTIONS = {
|
|
197
216
|
loggerOptions: DEFAULT_LOGGER_OPTIONS,
|
|
198
|
-
networkClient: /*#__PURE__*/NetworkUtils.getNetworkClient()
|
|
217
|
+
networkClient: /*#__PURE__*/NetworkUtils.getNetworkClient(),
|
|
218
|
+
proxyUrl: ""
|
|
199
219
|
};
|
|
200
220
|
/**
|
|
201
221
|
* Sets the default options when not explicitly configured from app developer
|
|
@@ -455,6 +475,14 @@ class CryptoProvider {
|
|
|
455
475
|
signJwt() {
|
|
456
476
|
throw new Error("Method not implemented.");
|
|
457
477
|
}
|
|
478
|
+
/**
|
|
479
|
+
* Returns the SHA-256 hash of an input string
|
|
480
|
+
*/
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
hashString() {
|
|
484
|
+
throw new Error("Method not implemented.");
|
|
485
|
+
}
|
|
458
486
|
|
|
459
487
|
}
|
|
460
488
|
|
|
@@ -1232,6 +1260,29 @@ class NodeStorage extends CacheManager {
|
|
|
1232
1260
|
static generateJsonCache(inMemoryCache) {
|
|
1233
1261
|
return Serializer.serializeAllCache(inMemoryCache);
|
|
1234
1262
|
}
|
|
1263
|
+
/**
|
|
1264
|
+
* Updates a credential's cache key if the current cache key is outdated
|
|
1265
|
+
*/
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
updateCredentialCacheKey(currentCacheKey, credential) {
|
|
1269
|
+
const updatedCacheKey = credential.generateCredentialKey();
|
|
1270
|
+
|
|
1271
|
+
if (currentCacheKey !== updatedCacheKey) {
|
|
1272
|
+
const cacheItem = this.getItem(currentCacheKey);
|
|
1273
|
+
|
|
1274
|
+
if (cacheItem) {
|
|
1275
|
+
this.removeItem(currentCacheKey);
|
|
1276
|
+
this.setItem(updatedCacheKey, cacheItem);
|
|
1277
|
+
this.logger.verbose(`Updated an outdated ${credential.credentialType} cache key`);
|
|
1278
|
+
return updatedCacheKey;
|
|
1279
|
+
} else {
|
|
1280
|
+
this.logger.error(`Attempted to update an outdated ${credential.credentialType} cache key but no item matching the outdated key was found in storage`);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
return currentCacheKey;
|
|
1285
|
+
}
|
|
1235
1286
|
|
|
1236
1287
|
}
|
|
1237
1288
|
|
|
@@ -1517,7 +1568,7 @@ class TokenCache {
|
|
|
1517
1568
|
|
|
1518
1569
|
/* eslint-disable header/header */
|
|
1519
1570
|
const name = "@azure/msal-node";
|
|
1520
|
-
const version = "1.
|
|
1571
|
+
const version = "1.6.0";
|
|
1521
1572
|
|
|
1522
1573
|
/*
|
|
1523
1574
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
@@ -1557,7 +1608,7 @@ class ClientApplication {
|
|
|
1557
1608
|
responseMode: request.responseMode || ResponseMode.QUERY,
|
|
1558
1609
|
authenticationScheme: AuthenticationScheme.BEARER
|
|
1559
1610
|
};
|
|
1560
|
-
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId);
|
|
1611
|
+
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
|
|
1561
1612
|
const authorizationCodeClient = new AuthorizationCodeClient(authClientConfig);
|
|
1562
1613
|
this.logger.verbose("Auth code client created", validRequest.correlationId);
|
|
1563
1614
|
return authorizationCodeClient.getAuthCodeUrl(validRequest);
|
|
@@ -1581,7 +1632,7 @@ class ClientApplication {
|
|
|
1581
1632
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByCode, validRequest.correlationId);
|
|
1582
1633
|
|
|
1583
1634
|
try {
|
|
1584
|
-
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1635
|
+
const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1585
1636
|
const authorizationCodeClient = new AuthorizationCodeClient(authClientConfig);
|
|
1586
1637
|
this.logger.verbose("Auth code client created", validRequest.correlationId);
|
|
1587
1638
|
return authorizationCodeClient.acquireToken(validRequest);
|
|
@@ -1612,7 +1663,7 @@ class ClientApplication {
|
|
|
1612
1663
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByRefreshToken, validRequest.correlationId);
|
|
1613
1664
|
|
|
1614
1665
|
try {
|
|
1615
|
-
const refreshTokenClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1666
|
+
const refreshTokenClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1616
1667
|
const refreshTokenClient = new RefreshTokenClient(refreshTokenClientConfig);
|
|
1617
1668
|
this.logger.verbose("Refresh token client created", validRequest.correlationId);
|
|
1618
1669
|
return refreshTokenClient.acquireToken(validRequest);
|
|
@@ -1643,7 +1694,7 @@ class ClientApplication {
|
|
|
1643
1694
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent, validRequest.correlationId, validRequest.forceRefresh);
|
|
1644
1695
|
|
|
1645
1696
|
try {
|
|
1646
|
-
const silentFlowClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1697
|
+
const silentFlowClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1647
1698
|
const silentFlowClient = new SilentFlowClient(silentFlowClientConfig);
|
|
1648
1699
|
this.logger.verbose("Silent flow client created", validRequest.correlationId);
|
|
1649
1700
|
return silentFlowClient.acquireToken(validRequest);
|
|
@@ -1676,7 +1727,7 @@ class ClientApplication {
|
|
|
1676
1727
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByUsernamePassword, validRequest.correlationId);
|
|
1677
1728
|
|
|
1678
1729
|
try {
|
|
1679
|
-
const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1730
|
+
const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1680
1731
|
const usernamePasswordClient = new UsernamePasswordClient(usernamePasswordClientConfig);
|
|
1681
1732
|
this.logger.verbose("Username password client created", validRequest.correlationId);
|
|
1682
1733
|
return usernamePasswordClient.acquireToken(validRequest);
|
|
@@ -1722,11 +1773,13 @@ class ClientApplication {
|
|
|
1722
1773
|
*/
|
|
1723
1774
|
|
|
1724
1775
|
|
|
1725
|
-
async buildOauthClientConfiguration(authority, requestCorrelationId, serverTelemetryManager, azureRegionConfiguration) {
|
|
1726
|
-
this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId); //
|
|
1776
|
+
async buildOauthClientConfiguration(authority, requestCorrelationId, serverTelemetryManager, azureRegionConfiguration, azureCloudOptions) {
|
|
1777
|
+
this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId); // precedence - azureCloudInstance + tenant >> authority and request >> config
|
|
1778
|
+
|
|
1779
|
+
const userAzureCloudOptions = azureCloudOptions ? azureCloudOptions : this.config.auth.azureCloudOptions; // using null assertion operator as we ensure that all config values have default values in buildConfiguration()
|
|
1727
1780
|
|
|
1728
1781
|
this.logger.verbose(`building oauth client configuration with the authority: ${authority}`, requestCorrelationId);
|
|
1729
|
-
const discoveredAuthority = await this.createAuthority(authority, azureRegionConfiguration, requestCorrelationId);
|
|
1782
|
+
const discoveredAuthority = await this.createAuthority(authority, azureRegionConfiguration, requestCorrelationId, userAzureCloudOptions);
|
|
1730
1783
|
serverTelemetryManager == null ? void 0 : serverTelemetryManager.updateRegionDiscoveryMetadata(discoveredAuthority.regionDiscoveryMetadata);
|
|
1731
1784
|
return {
|
|
1732
1785
|
authOptions: {
|
|
@@ -1734,6 +1787,9 @@ class ClientApplication {
|
|
|
1734
1787
|
authority: discoveredAuthority,
|
|
1735
1788
|
clientCapabilities: this.config.auth.clientCapabilities
|
|
1736
1789
|
},
|
|
1790
|
+
systemOptions: {
|
|
1791
|
+
proxyUrl: this.config.system.proxyUrl
|
|
1792
|
+
},
|
|
1737
1793
|
loggerOptions: {
|
|
1738
1794
|
logLevel: this.config.system.loggerOptions.logLevel,
|
|
1739
1795
|
loggerCallback: this.config.system.loggerOptions.loggerCallback,
|
|
@@ -1809,8 +1865,10 @@ class ClientApplication {
|
|
|
1809
1865
|
*/
|
|
1810
1866
|
|
|
1811
1867
|
|
|
1812
|
-
async createAuthority(authorityString, azureRegionConfiguration, requestCorrelationId) {
|
|
1813
|
-
this.logger.verbose("createAuthority called", requestCorrelationId);
|
|
1868
|
+
async createAuthority(authorityString, azureRegionConfiguration, requestCorrelationId, azureCloudOptions) {
|
|
1869
|
+
this.logger.verbose("createAuthority called", requestCorrelationId); // build authority string based on auth params - azureCloudInstance is prioritized if provided
|
|
1870
|
+
|
|
1871
|
+
const authorityUrl = Authority.generateAuthority(authorityString, azureCloudOptions);
|
|
1814
1872
|
const authorityOptions = {
|
|
1815
1873
|
protocolMode: this.config.auth.protocolMode,
|
|
1816
1874
|
knownAuthorities: this.config.auth.knownAuthorities,
|
|
@@ -1818,7 +1876,7 @@ class ClientApplication {
|
|
|
1818
1876
|
authorityMetadata: this.config.auth.authorityMetadata,
|
|
1819
1877
|
azureRegionConfiguration
|
|
1820
1878
|
};
|
|
1821
|
-
return await AuthorityFactory.createDiscoveredInstance(
|
|
1879
|
+
return await AuthorityFactory.createDiscoveredInstance(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions);
|
|
1822
1880
|
}
|
|
1823
1881
|
|
|
1824
1882
|
}
|
|
@@ -1871,7 +1929,7 @@ class PublicClientApplication extends ClientApplication {
|
|
|
1871
1929
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
|
|
1872
1930
|
|
|
1873
1931
|
try {
|
|
1874
|
-
const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
|
|
1932
|
+
const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
|
|
1875
1933
|
const deviceCodeClient = new DeviceCodeClient(deviceCodeConfig);
|
|
1876
1934
|
this.logger.verbose("Device code client created", validRequest.correlationId);
|
|
1877
1935
|
return deviceCodeClient.acquireToken(validRequest);
|
|
@@ -1965,13 +2023,13 @@ class ClientAssertion {
|
|
|
1965
2023
|
const issuedAt = TimeUtils.nowSeconds();
|
|
1966
2024
|
this.expirationTime = issuedAt + 600;
|
|
1967
2025
|
const header = {
|
|
1968
|
-
|
|
1969
|
-
|
|
2026
|
+
alg: JwtConstants.RSA_256,
|
|
2027
|
+
x5t: EncodingUtils.base64EncodeUrl(this.thumbprint, "hex")
|
|
1970
2028
|
};
|
|
1971
2029
|
|
|
1972
2030
|
if (this.publicCertificate) {
|
|
1973
2031
|
Object.assign(header, {
|
|
1974
|
-
|
|
2032
|
+
x5c: this.publicCertificate
|
|
1975
2033
|
});
|
|
1976
2034
|
}
|
|
1977
2035
|
|
|
@@ -1984,7 +2042,7 @@ class ClientAssertion {
|
|
|
1984
2042
|
[JwtConstants.JWT_ID]: cryptoProvider.createNewGuid()
|
|
1985
2043
|
};
|
|
1986
2044
|
this.jwt = sign(payload, this.privateKey, {
|
|
1987
|
-
header
|
|
2045
|
+
header
|
|
1988
2046
|
});
|
|
1989
2047
|
return this.jwt;
|
|
1990
2048
|
}
|
|
@@ -2075,7 +2133,7 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2075
2133
|
const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByClientCredential, validRequest.correlationId, validRequest.skipCache);
|
|
2076
2134
|
|
|
2077
2135
|
try {
|
|
2078
|
-
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration);
|
|
2136
|
+
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration, request.azureCloudOptions);
|
|
2079
2137
|
const clientCredentialClient = new ClientCredentialClient(clientCredentialConfig);
|
|
2080
2138
|
this.logger.verbose("Client credential client created", validRequest.correlationId);
|
|
2081
2139
|
return clientCredentialClient.acquireToken(validRequest);
|
|
@@ -2108,7 +2166,7 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2108
2166
|
};
|
|
2109
2167
|
|
|
2110
2168
|
try {
|
|
2111
|
-
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId);
|
|
2169
|
+
const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
|
|
2112
2170
|
const oboClient = new OnBehalfOfClient(clientCredentialConfig);
|
|
2113
2171
|
this.logger.verbose("On behalf of client created", validRequest.correlationId);
|
|
2114
2172
|
return oboClient.acquireToken(validRequest);
|
|
@@ -2155,5 +2213,36 @@ class ConfidentialClientApplication extends ClientApplication {
|
|
|
2155
2213
|
|
|
2156
2214
|
}
|
|
2157
2215
|
|
|
2158
|
-
|
|
2216
|
+
/*
|
|
2217
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2218
|
+
* Licensed under the MIT License.
|
|
2219
|
+
*/
|
|
2220
|
+
class DistributedCachePlugin {
|
|
2221
|
+
constructor(client, partitionManager) {
|
|
2222
|
+
this.client = client;
|
|
2223
|
+
this.partitionManager = partitionManager;
|
|
2224
|
+
}
|
|
2225
|
+
|
|
2226
|
+
async beforeCacheAccess(cacheContext) {
|
|
2227
|
+
const partitionKey = await this.partitionManager.getKey();
|
|
2228
|
+
const cacheData = await this.client.get(partitionKey);
|
|
2229
|
+
cacheContext.tokenCache.deserialize(cacheData);
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
async afterCacheAccess(cacheContext) {
|
|
2233
|
+
if (cacheContext.cacheHasChanged) {
|
|
2234
|
+
const kvStore = cacheContext.tokenCache.getKVStore();
|
|
2235
|
+
const accountEntities = Object.values(kvStore).filter(value => AccountEntity.isAccountEntity(value));
|
|
2236
|
+
|
|
2237
|
+
if (accountEntities.length > 0) {
|
|
2238
|
+
const accountEntity = accountEntities[0];
|
|
2239
|
+
const partitionKey = await this.partitionManager.extractKey(accountEntity);
|
|
2240
|
+
await this.client.set(partitionKey, cacheContext.tokenCache.serialize());
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2247
|
+
export { ClientApplication, ClientAssertion, ConfidentialClientApplication, CryptoProvider, DistributedCachePlugin, NodeStorage, PublicClientApplication, TokenCache, buildAppConfiguration, version };
|
|
2159
2248
|
//# sourceMappingURL=msal-node.esm.js.map
|