@azure/msal-node 1.5.0 → 1.8.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.
Files changed (43) hide show
  1. package/dist/cache/NodeStorage.d.ts.map +1 -1
  2. package/dist/cache/distributed/DistributedCachePlugin.d.ts +11 -0
  3. package/dist/cache/distributed/DistributedCachePlugin.d.ts.map +1 -0
  4. package/dist/cache/distributed/ICacheClient.d.ts +18 -0
  5. package/dist/cache/distributed/ICacheClient.d.ts.map +1 -0
  6. package/dist/cache/distributed/IPartitionManager.d.ts +33 -0
  7. package/dist/cache/distributed/IPartitionManager.d.ts.map +1 -0
  8. package/dist/cache/serializer/Deserializer.d.ts.map +1 -1
  9. package/dist/cache/serializer/Serializer.d.ts.map +1 -1
  10. package/dist/cache/serializer/SerializerTypes.d.ts +2 -0
  11. package/dist/cache/serializer/SerializerTypes.d.ts.map +1 -1
  12. package/dist/client/ClientApplication.d.ts +8 -4
  13. package/dist/client/ClientApplication.d.ts.map +1 -1
  14. package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
  15. package/dist/client/IConfidentialClientApplication.d.ts +2 -0
  16. package/dist/client/IConfidentialClientApplication.d.ts.map +1 -1
  17. package/dist/client/IPublicClientApplication.d.ts +2 -0
  18. package/dist/client/IPublicClientApplication.d.ts.map +1 -1
  19. package/dist/client/PublicClientApplication.d.ts.map +1 -1
  20. package/dist/config/Configuration.d.ts +10 -2
  21. package/dist/config/Configuration.d.ts.map +1 -1
  22. package/dist/crypto/CryptoProvider.d.ts +3 -1
  23. package/dist/crypto/CryptoProvider.d.ts.map +1 -1
  24. package/dist/crypto/GuidGenerator.d.ts +4 -3
  25. package/dist/crypto/GuidGenerator.d.ts.map +1 -1
  26. package/dist/crypto/HashUtils.d.ts +9 -0
  27. package/dist/crypto/HashUtils.d.ts.map +1 -0
  28. package/dist/crypto/PkceGenerator.d.ts +2 -5
  29. package/dist/crypto/PkceGenerator.d.ts.map +1 -1
  30. package/dist/index.d.ts +4 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/msal-node.cjs.development.js +174 -65
  33. package/dist/msal-node.cjs.development.js.map +1 -1
  34. package/dist/msal-node.cjs.production.min.js +1 -1
  35. package/dist/msal-node.cjs.production.min.js.map +1 -1
  36. package/dist/msal-node.esm.js +170 -68
  37. package/dist/msal-node.esm.js.map +1 -1
  38. package/dist/network/HttpClient.d.ts.map +1 -1
  39. package/dist/packageMetadata.d.ts +1 -1
  40. package/dist/utils/EncodingUtils.d.ts.map +1 -1
  41. package/package.json +4 -17
  42. package/CHANGELOG.json +0 -980
  43. package/CHANGELOG.md +0 -322
@@ -6,6 +6,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
6
6
 
7
7
  var msalCommon = require('@azure/msal-common');
8
8
  var axios = _interopDefault(require('axios'));
9
+ var createHttpsProxyAgent = _interopDefault(require('https-proxy-agent'));
9
10
  var uuid = require('uuid');
10
11
  var crypto = _interopDefault(require('crypto'));
11
12
  var jsonwebtoken = require('jsonwebtoken');
@@ -118,6 +119,13 @@ class HttpClient {
118
119
  /* istanbul ignore next */
119
120
  validateStatus: () => true
120
121
  };
122
+
123
+ if (options && options.proxyUrl) {
124
+ // for axios, this has to be disabled
125
+ request.proxy = false;
126
+ request.httpsAgent = createHttpsProxyAgent(options.proxyUrl);
127
+ }
128
+
121
129
  const response = await axios(request);
122
130
  return {
123
131
  headers: response.headers,
@@ -138,7 +146,7 @@ class HttpClient {
138
146
  url: url,
139
147
 
140
148
  /* istanbul ignore next */
141
- data: options && options.body || "",
149
+ data: options && options.body || msalCommon.Constants.EMPTY_STRING,
142
150
  timeout: cancellationToken,
143
151
 
144
152
  /* istanbul ignore next */
@@ -147,6 +155,13 @@ class HttpClient {
147
155
  /* istanbul ignore next */
148
156
  validateStatus: () => true
149
157
  };
158
+
159
+ if (options && options.proxyUrl) {
160
+ // for axios, this has to be disabled
161
+ request.proxy = false;
162
+ request.httpsAgent = createHttpsProxyAgent(options.proxyUrl);
163
+ }
164
+
150
165
  const response = await axios(request);
151
166
  return {
152
167
  headers: response.headers,
@@ -176,20 +191,24 @@ class NetworkUtils {
176
191
  * Licensed under the MIT License.
177
192
  */
178
193
  const DEFAULT_AUTH_OPTIONS = {
179
- clientId: "",
194
+ clientId: msalCommon.Constants.EMPTY_STRING,
180
195
  authority: msalCommon.Constants.DEFAULT_AUTHORITY,
181
- clientSecret: "",
182
- clientAssertion: "",
196
+ clientSecret: msalCommon.Constants.EMPTY_STRING,
197
+ clientAssertion: msalCommon.Constants.EMPTY_STRING,
183
198
  clientCertificate: {
184
- thumbprint: "",
185
- privateKey: "",
186
- x5c: ""
199
+ thumbprint: msalCommon.Constants.EMPTY_STRING,
200
+ privateKey: msalCommon.Constants.EMPTY_STRING,
201
+ x5c: msalCommon.Constants.EMPTY_STRING
187
202
  },
188
203
  knownAuthorities: [],
189
- cloudDiscoveryMetadata: "",
190
- authorityMetadata: "",
204
+ cloudDiscoveryMetadata: msalCommon.Constants.EMPTY_STRING,
205
+ authorityMetadata: msalCommon.Constants.EMPTY_STRING,
191
206
  clientCapabilities: [],
192
- protocolMode: msalCommon.ProtocolMode.AAD
207
+ protocolMode: msalCommon.ProtocolMode.AAD,
208
+ azureCloudOptions: {
209
+ azureCloudInstance: msalCommon.AzureCloudInstance.None,
210
+ tenant: msalCommon.Constants.EMPTY_STRING
211
+ }
193
212
  };
194
213
  const DEFAULT_CACHE_OPTIONS = {};
195
214
  const DEFAULT_LOGGER_OPTIONS = {
@@ -200,7 +219,14 @@ const DEFAULT_LOGGER_OPTIONS = {
200
219
  };
201
220
  const DEFAULT_SYSTEM_OPTIONS = {
202
221
  loggerOptions: DEFAULT_LOGGER_OPTIONS,
203
- networkClient: /*#__PURE__*/NetworkUtils.getNetworkClient()
222
+ networkClient: /*#__PURE__*/NetworkUtils.getNetworkClient(),
223
+ proxyUrl: msalCommon.Constants.EMPTY_STRING
224
+ };
225
+ const DEFAULT_TELEMETRY_OPTIONS = {
226
+ application: {
227
+ appName: msalCommon.Constants.EMPTY_STRING,
228
+ appVersion: msalCommon.Constants.EMPTY_STRING
229
+ }
204
230
  };
205
231
  /**
206
232
  * Sets the default options when not explicitly configured from app developer
@@ -208,6 +234,7 @@ const DEFAULT_SYSTEM_OPTIONS = {
208
234
  * @param auth - Authentication options
209
235
  * @param cache - Cache options
210
236
  * @param system - System options
237
+ * @param telemetry - Telemetry options
211
238
  *
212
239
  * @returns Configuration
213
240
  * @public
@@ -216,7 +243,8 @@ const DEFAULT_SYSTEM_OPTIONS = {
216
243
  function buildAppConfiguration({
217
244
  auth,
218
245
  cache,
219
- system
246
+ system,
247
+ telemetry
220
248
  }) {
221
249
  return {
222
250
  auth: { ...DEFAULT_AUTH_OPTIONS,
@@ -227,6 +255,9 @@ function buildAppConfiguration({
227
255
  },
228
256
  system: { ...DEFAULT_SYSTEM_OPTIONS,
229
257
  ...system
258
+ },
259
+ telemetry: { ...DEFAULT_TELEMETRY_OPTIONS,
260
+ ...telemetry
230
261
  }
231
262
  };
232
263
  }
@@ -241,7 +272,7 @@ class GuidGenerator {
241
272
  * RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or pseudo-random numbers.
242
273
  * uuidv4 generates guids from cryprtographically-string random
243
274
  */
244
- static generateGuid() {
275
+ generateGuid() {
245
276
  return uuid.v4();
246
277
  }
247
278
  /**
@@ -250,7 +281,7 @@ class GuidGenerator {
250
281
  */
251
282
 
252
283
 
253
- static isGuid(guid) {
284
+ isGuid(guid) {
254
285
  const regexGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
255
286
  return regexGuid.test(guid);
256
287
  }
@@ -278,7 +309,7 @@ class EncodingUtils {
278
309
 
279
310
 
280
311
  static base64EncodeUrl(str, encoding) {
281
- return EncodingUtils.base64Encode(str, encoding).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
312
+ return EncodingUtils.base64Encode(str, encoding).replace(/=/g, msalCommon.Constants.EMPTY_STRING).replace(/\+/g, "-").replace(/\//g, "_");
282
313
  }
283
314
  /**
284
315
  * 'utf8': Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
@@ -308,6 +339,21 @@ class EncodingUtils {
308
339
 
309
340
  }
310
341
 
342
+ /*
343
+ * Copyright (c) Microsoft Corporation. All rights reserved.
344
+ * Licensed under the MIT License.
345
+ */
346
+ class HashUtils {
347
+ /**
348
+ * generate 'SHA256' hash
349
+ * @param buffer
350
+ */
351
+ sha256(buffer) {
352
+ return crypto.createHash(Hash.SHA256).update(buffer).digest();
353
+ }
354
+
355
+ }
356
+
311
357
  /*
312
358
  * Copyright (c) Microsoft Corporation. All rights reserved.
313
359
  * Licensed under the MIT License.
@@ -317,10 +363,15 @@ class EncodingUtils {
317
363
  */
318
364
 
319
365
  class PkceGenerator {
366
+ constructor() {
367
+ this.hashUtils = new HashUtils();
368
+ }
320
369
  /**
321
370
  * generates the codeVerfier and the challenge from the codeVerfier
322
371
  * reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
323
372
  */
373
+
374
+
324
375
  async generatePkceCodes() {
325
376
  const verifier = this.generateCodeVerifier();
326
377
  const challenge = this.generateCodeChallengeFromVerifier(verifier);
@@ -353,7 +404,7 @@ class PkceGenerator {
353
404
  charArr.push(CharSet.CV_CHARSET[index]);
354
405
  }
355
406
 
356
- const verifier = charArr.join("");
407
+ const verifier = charArr.join(msalCommon.Constants.EMPTY_STRING);
357
408
  return EncodingUtils.base64EncodeUrl(verifier);
358
409
  }
359
410
  /**
@@ -363,16 +414,7 @@ class PkceGenerator {
363
414
 
364
415
 
365
416
  generateCodeChallengeFromVerifier(codeVerifier) {
366
- return EncodingUtils.base64EncodeUrl(this.sha256(codeVerifier).toString("base64"), "base64");
367
- }
368
- /**
369
- * generate 'SHA256' hash
370
- * @param buffer
371
- */
372
-
373
-
374
- sha256(buffer) {
375
- return crypto.createHash(Hash.SHA256).update(buffer).digest();
417
+ return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(codeVerifier).toString("base64"), "base64");
376
418
  }
377
419
 
378
420
  }
@@ -391,6 +433,8 @@ class CryptoProvider {
391
433
  constructor() {
392
434
  // Browser crypto needs to be validated first before any other classes can be set.
393
435
  this.pkceGenerator = new PkceGenerator();
436
+ this.guidGenerator = new GuidGenerator();
437
+ this.hashUtils = new HashUtils();
394
438
  }
395
439
  /**
396
440
  * Creates a new random GUID - used to populate state and nonce.
@@ -399,7 +443,7 @@ class CryptoProvider {
399
443
 
400
444
 
401
445
  createNewGuid() {
402
- return GuidGenerator.generateGuid();
446
+ return this.guidGenerator.generateGuid();
403
447
  }
404
448
  /**
405
449
  * Encodes input string to base64.
@@ -465,8 +509,8 @@ class CryptoProvider {
465
509
  */
466
510
 
467
511
 
468
- hashString() {
469
- throw new Error("Method not implemented.");
512
+ async hashString(plainText) {
513
+ return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(plainText).toString("base64"), "base64");
470
514
  }
471
515
 
472
516
  }
@@ -573,7 +617,9 @@ class Deserializer {
573
617
  extendedExpiresOn: serializedAT.extended_expires_on,
574
618
  refreshOn: serializedAT.refresh_on,
575
619
  keyId: serializedAT.key_id,
576
- tokenType: serializedAT.token_type
620
+ tokenType: serializedAT.token_type,
621
+ requestedClaims: serializedAT.requestedClaims,
622
+ requestedClaimsHash: serializedAT.requestedClaimsHash
577
623
  };
578
624
  const accessToken = new msalCommon.AccessTokenEntity();
579
625
  msalCommon.CacheManager.toObject(accessToken, mappedAT);
@@ -737,7 +783,9 @@ class Serializer {
737
783
  extended_expires_on: atEntity.extendedExpiresOn,
738
784
  refresh_on: atEntity.refreshOn,
739
785
  key_id: atEntity.keyId,
740
- token_type: atEntity.tokenType
786
+ token_type: atEntity.tokenType,
787
+ requestedClaims: atEntity.requestedClaims,
788
+ requestedClaimsHash: atEntity.requestedClaimsHash
741
789
  };
742
790
  });
743
791
  return accessTokens;
@@ -876,12 +924,14 @@ class NodeStorage extends msalCommon.CacheManager {
876
924
  inMemoryCacheToCache(inMemoryCache) {
877
925
  // convert in memory cache to a flat Key-Value map
878
926
  let cache = this.getCache();
879
- cache = { ...inMemoryCache.accounts,
927
+ cache = { ...cache,
928
+ ...inMemoryCache.accounts,
880
929
  ...inMemoryCache.idTokens,
881
930
  ...inMemoryCache.accessTokens,
882
931
  ...inMemoryCache.refreshTokens,
883
932
  ...inMemoryCache.appMetadata
884
- };
933
+ }; // convert in memory cache to a flat Key-Value map
934
+
885
935
  return cache;
886
936
  }
887
937
  /**
@@ -1553,7 +1603,7 @@ class TokenCache {
1553
1603
 
1554
1604
  /* eslint-disable header/header */
1555
1605
  const name = "@azure/msal-node";
1556
- const version = "1.5.0";
1606
+ const version = "1.8.0";
1557
1607
 
1558
1608
  /*
1559
1609
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1589,11 +1639,11 @@ class ClientApplication {
1589
1639
  async getAuthCodeUrl(request) {
1590
1640
  this.logger.info("getAuthCodeUrl called", request.correlationId);
1591
1641
  const validRequest = { ...request,
1592
- ...this.initializeBaseRequest(request),
1642
+ ...(await this.initializeBaseRequest(request)),
1593
1643
  responseMode: request.responseMode || msalCommon.ResponseMode.QUERY,
1594
1644
  authenticationScheme: msalCommon.AuthenticationScheme.BEARER
1595
1645
  };
1596
- const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId);
1646
+ const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
1597
1647
  const authorizationCodeClient = new msalCommon.AuthorizationCodeClient(authClientConfig);
1598
1648
  this.logger.verbose("Auth code client created", validRequest.correlationId);
1599
1649
  return authorizationCodeClient.getAuthCodeUrl(validRequest);
@@ -1608,19 +1658,19 @@ class ClientApplication {
1608
1658
  */
1609
1659
 
1610
1660
 
1611
- async acquireTokenByCode(request) {
1661
+ async acquireTokenByCode(request, authCodePayLoad) {
1612
1662
  this.logger.info("acquireTokenByCode called", request.correlationId);
1613
1663
  const validRequest = { ...request,
1614
- ...this.initializeBaseRequest(request),
1664
+ ...(await this.initializeBaseRequest(request)),
1615
1665
  authenticationScheme: msalCommon.AuthenticationScheme.BEARER
1616
1666
  };
1617
1667
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByCode, validRequest.correlationId);
1618
1668
 
1619
1669
  try {
1620
- const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
1670
+ const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
1621
1671
  const authorizationCodeClient = new msalCommon.AuthorizationCodeClient(authClientConfig);
1622
1672
  this.logger.verbose("Auth code client created", validRequest.correlationId);
1623
- return authorizationCodeClient.acquireToken(validRequest);
1673
+ return authorizationCodeClient.acquireToken(validRequest, authCodePayLoad);
1624
1674
  } catch (e) {
1625
1675
  if (e instanceof msalCommon.AuthError) {
1626
1676
  e.setCorrelationId(validRequest.correlationId);
@@ -1642,13 +1692,13 @@ class ClientApplication {
1642
1692
  async acquireTokenByRefreshToken(request) {
1643
1693
  this.logger.info("acquireTokenByRefreshToken called", request.correlationId);
1644
1694
  const validRequest = { ...request,
1645
- ...this.initializeBaseRequest(request),
1695
+ ...(await this.initializeBaseRequest(request)),
1646
1696
  authenticationScheme: msalCommon.AuthenticationScheme.BEARER
1647
1697
  };
1648
1698
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByRefreshToken, validRequest.correlationId);
1649
1699
 
1650
1700
  try {
1651
- const refreshTokenClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
1701
+ const refreshTokenClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
1652
1702
  const refreshTokenClient = new msalCommon.RefreshTokenClient(refreshTokenClientConfig);
1653
1703
  this.logger.verbose("Refresh token client created", validRequest.correlationId);
1654
1704
  return refreshTokenClient.acquireToken(validRequest);
@@ -1673,13 +1723,13 @@ class ClientApplication {
1673
1723
 
1674
1724
  async acquireTokenSilent(request) {
1675
1725
  const validRequest = { ...request,
1676
- ...this.initializeBaseRequest(request),
1726
+ ...(await this.initializeBaseRequest(request)),
1677
1727
  forceRefresh: request.forceRefresh || false
1678
1728
  };
1679
1729
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent, validRequest.correlationId, validRequest.forceRefresh);
1680
1730
 
1681
1731
  try {
1682
- const silentFlowClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
1732
+ const silentFlowClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
1683
1733
  const silentFlowClient = new msalCommon.SilentFlowClient(silentFlowClientConfig);
1684
1734
  this.logger.verbose("Silent flow client created", validRequest.correlationId);
1685
1735
  return silentFlowClient.acquireToken(validRequest);
@@ -1707,12 +1757,12 @@ class ClientApplication {
1707
1757
  async acquireTokenByUsernamePassword(request) {
1708
1758
  this.logger.info("acquireTokenByUsernamePassword called", request.correlationId);
1709
1759
  const validRequest = { ...request,
1710
- ...this.initializeBaseRequest(request)
1760
+ ...(await this.initializeBaseRequest(request))
1711
1761
  };
1712
1762
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByUsernamePassword, validRequest.correlationId);
1713
1763
 
1714
1764
  try {
1715
- const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
1765
+ const usernamePasswordClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
1716
1766
  const usernamePasswordClient = new msalCommon.UsernamePasswordClient(usernamePasswordClientConfig);
1717
1767
  this.logger.verbose("Username password client created", validRequest.correlationId);
1718
1768
  return usernamePasswordClient.acquireToken(validRequest);
@@ -1758,11 +1808,13 @@ class ClientApplication {
1758
1808
  */
1759
1809
 
1760
1810
 
1761
- async buildOauthClientConfiguration(authority, requestCorrelationId, serverTelemetryManager, azureRegionConfiguration) {
1762
- this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId); // using null assertion operator as we ensure that all config values have default values in buildConfiguration()
1811
+ async buildOauthClientConfiguration(authority, requestCorrelationId, serverTelemetryManager, azureRegionConfiguration, azureCloudOptions) {
1812
+ this.logger.verbose("buildOauthClientConfiguration called", requestCorrelationId); // precedence - azureCloudInstance + tenant >> authority and request >> config
1813
+
1814
+ const userAzureCloudOptions = azureCloudOptions ? azureCloudOptions : this.config.auth.azureCloudOptions; // using null assertion operator as we ensure that all config values have default values in buildConfiguration()
1763
1815
 
1764
1816
  this.logger.verbose(`building oauth client configuration with the authority: ${authority}`, requestCorrelationId);
1765
- const discoveredAuthority = await this.createAuthority(authority, azureRegionConfiguration, requestCorrelationId);
1817
+ const discoveredAuthority = await this.createAuthority(authority, azureRegionConfiguration, requestCorrelationId, userAzureCloudOptions);
1766
1818
  serverTelemetryManager == null ? void 0 : serverTelemetryManager.updateRegionDiscoveryMetadata(discoveredAuthority.regionDiscoveryMetadata);
1767
1819
  return {
1768
1820
  authOptions: {
@@ -1770,6 +1822,9 @@ class ClientApplication {
1770
1822
  authority: discoveredAuthority,
1771
1823
  clientCapabilities: this.config.auth.clientCapabilities
1772
1824
  },
1825
+ systemOptions: {
1826
+ proxyUrl: this.config.system.proxyUrl
1827
+ },
1773
1828
  loggerOptions: {
1774
1829
  logLevel: this.config.system.loggerOptions.logLevel,
1775
1830
  loggerCallback: this.config.system.loggerOptions.loggerCallback,
@@ -1787,9 +1842,10 @@ class ClientApplication {
1787
1842
  libraryInfo: {
1788
1843
  sku: Constants.MSAL_SKU,
1789
1844
  version: version,
1790
- cpu: process.arch || "",
1791
- os: process.platform || ""
1845
+ cpu: process.arch || msalCommon.Constants.EMPTY_STRING,
1846
+ os: process.platform || msalCommon.Constants.EMPTY_STRING
1792
1847
  },
1848
+ telemetry: this.config.telemetry,
1793
1849
  persistencePlugin: this.config.cache.cachePlugin,
1794
1850
  serializableCache: this.tokenCache
1795
1851
  };
@@ -1807,14 +1863,19 @@ class ClientApplication {
1807
1863
  */
1808
1864
 
1809
1865
 
1810
- initializeBaseRequest(authRequest) {
1866
+ async initializeBaseRequest(authRequest) {
1811
1867
  this.logger.verbose("initializeRequestScopes called", authRequest.correlationId); // Default authenticationScheme to Bearer, log that POP isn't supported yet
1812
1868
 
1813
1869
  if (authRequest.authenticationScheme && authRequest.authenticationScheme === msalCommon.AuthenticationScheme.POP) {
1814
1870
  this.logger.verbose("Authentication Scheme 'pop' is not supported yet, setting Authentication Scheme to 'Bearer' for request", authRequest.correlationId);
1815
1871
  }
1816
1872
 
1817
- authRequest.authenticationScheme = msalCommon.AuthenticationScheme.BEARER;
1873
+ authRequest.authenticationScheme = msalCommon.AuthenticationScheme.BEARER; // Set requested claims hash if claims were requested
1874
+
1875
+ if (authRequest.claims && !msalCommon.StringUtils.isEmpty(authRequest.claims)) {
1876
+ authRequest.requestedClaimsHash = await this.cryptoProvider.hashString(authRequest.claims);
1877
+ }
1878
+
1818
1879
  return { ...authRequest,
1819
1880
  scopes: [...(authRequest && authRequest.scopes || []), ...msalCommon.OIDC_DEFAULT_SCOPES],
1820
1881
  correlationId: authRequest && authRequest.correlationId || this.cryptoProvider.createNewGuid(),
@@ -1845,8 +1906,10 @@ class ClientApplication {
1845
1906
  */
1846
1907
 
1847
1908
 
1848
- async createAuthority(authorityString, azureRegionConfiguration, requestCorrelationId) {
1849
- this.logger.verbose("createAuthority called", requestCorrelationId);
1909
+ async createAuthority(authorityString, azureRegionConfiguration, requestCorrelationId, azureCloudOptions) {
1910
+ this.logger.verbose("createAuthority called", requestCorrelationId); // build authority string based on auth params - azureCloudInstance is prioritized if provided
1911
+
1912
+ const authorityUrl = msalCommon.Authority.generateAuthority(authorityString, azureCloudOptions);
1850
1913
  const authorityOptions = {
1851
1914
  protocolMode: this.config.auth.protocolMode,
1852
1915
  knownAuthorities: this.config.auth.knownAuthorities,
@@ -1854,7 +1917,15 @@ class ClientApplication {
1854
1917
  authorityMetadata: this.config.auth.authorityMetadata,
1855
1918
  azureRegionConfiguration
1856
1919
  };
1857
- return await msalCommon.AuthorityFactory.createDiscoveredInstance(authorityString, this.config.system.networkClient, this.storage, authorityOptions);
1920
+ return await msalCommon.AuthorityFactory.createDiscoveredInstance(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions);
1921
+ }
1922
+ /**
1923
+ * Clear the cache
1924
+ */
1925
+
1926
+
1927
+ clearCache() {
1928
+ this.storage.clear();
1858
1929
  }
1859
1930
 
1860
1931
  }
@@ -1903,11 +1974,11 @@ class PublicClientApplication extends ClientApplication {
1903
1974
 
1904
1975
  async acquireTokenByDeviceCode(request) {
1905
1976
  this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
1906
- const validRequest = Object.assign(request, this.initializeBaseRequest(request));
1977
+ const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
1907
1978
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
1908
1979
 
1909
1980
  try {
1910
- const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager);
1981
+ const deviceCodeConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
1911
1982
  const deviceCodeClient = new msalCommon.DeviceCodeClient(deviceCodeConfig);
1912
1983
  this.logger.verbose("Device code client created", validRequest.correlationId);
1913
1984
  return deviceCodeClient.acquireToken(validRequest);
@@ -2052,7 +2123,7 @@ class ClientAssertion {
2052
2123
 
2053
2124
  while ((matches = regexToFindCerts.exec(publicCertificate)) !== null) {
2054
2125
  // matches[1] represents the first parens capture group in the regex.
2055
- certs.push(matches[1].replace(/\n/, ""));
2126
+ certs.push(matches[1].replace(/\n/, msalCommon.Constants.EMPTY_STRING));
2056
2127
  }
2057
2128
 
2058
2129
  return certs;
@@ -2102,7 +2173,7 @@ class ConfidentialClientApplication extends ClientApplication {
2102
2173
  async acquireTokenByClientCredential(request) {
2103
2174
  this.logger.info("acquireTokenByClientCredential called", request.correlationId);
2104
2175
  const validRequest = { ...request,
2105
- ...this.initializeBaseRequest(request)
2176
+ ...(await this.initializeBaseRequest(request))
2106
2177
  };
2107
2178
  const azureRegionConfiguration = {
2108
2179
  azureRegion: validRequest.azureRegion,
@@ -2111,7 +2182,7 @@ class ConfidentialClientApplication extends ClientApplication {
2111
2182
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByClientCredential, validRequest.correlationId, validRequest.skipCache);
2112
2183
 
2113
2184
  try {
2114
- const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration);
2185
+ const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, azureRegionConfiguration, request.azureCloudOptions);
2115
2186
  const clientCredentialClient = new msalCommon.ClientCredentialClient(clientCredentialConfig);
2116
2187
  this.logger.verbose("Client credential client created", validRequest.correlationId);
2117
2188
  return clientCredentialClient.acquireToken(validRequest);
@@ -2140,11 +2211,11 @@ class ConfidentialClientApplication extends ClientApplication {
2140
2211
  async acquireTokenOnBehalfOf(request) {
2141
2212
  this.logger.info("acquireTokenOnBehalfOf called", request.correlationId);
2142
2213
  const validRequest = { ...request,
2143
- ...this.initializeBaseRequest(request)
2214
+ ...(await this.initializeBaseRequest(request))
2144
2215
  };
2145
2216
 
2146
2217
  try {
2147
- const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId);
2218
+ const clientCredentialConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, undefined, undefined, request.azureCloudOptions);
2148
2219
  const oboClient = new msalCommon.OnBehalfOfClient(clientCredentialConfig);
2149
2220
  this.logger.verbose("On behalf of client created", validRequest.correlationId);
2150
2221
  return oboClient.acquireToken(validRequest);
@@ -2161,8 +2232,8 @@ class ConfidentialClientApplication extends ClientApplication {
2161
2232
  const clientSecretNotEmpty = !msalCommon.StringUtils.isEmpty(configuration.auth.clientSecret);
2162
2233
  const clientAssertionNotEmpty = !msalCommon.StringUtils.isEmpty(configuration.auth.clientAssertion);
2163
2234
  const certificate = configuration.auth.clientCertificate || {
2164
- thumbprint: "",
2165
- privateKey: ""
2235
+ thumbprint: msalCommon.Constants.EMPTY_STRING,
2236
+ privateKey: msalCommon.Constants.EMPTY_STRING
2166
2237
  };
2167
2238
  const certificateNotEmpty = !msalCommon.StringUtils.isEmpty(certificate.thumbprint) || !msalCommon.StringUtils.isEmpty(certificate.privateKey); // Check that at most one credential is set on the application
2168
2239
 
@@ -2191,6 +2262,37 @@ class ConfidentialClientApplication extends ClientApplication {
2191
2262
 
2192
2263
  }
2193
2264
 
2265
+ /*
2266
+ * Copyright (c) Microsoft Corporation. All rights reserved.
2267
+ * Licensed under the MIT License.
2268
+ */
2269
+ class DistributedCachePlugin {
2270
+ constructor(client, partitionManager) {
2271
+ this.client = client;
2272
+ this.partitionManager = partitionManager;
2273
+ }
2274
+
2275
+ async beforeCacheAccess(cacheContext) {
2276
+ const partitionKey = await this.partitionManager.getKey();
2277
+ const cacheData = await this.client.get(partitionKey);
2278
+ cacheContext.tokenCache.deserialize(cacheData);
2279
+ }
2280
+
2281
+ async afterCacheAccess(cacheContext) {
2282
+ if (cacheContext.cacheHasChanged) {
2283
+ const kvStore = cacheContext.tokenCache.getKVStore();
2284
+ const accountEntities = Object.values(kvStore).filter(value => msalCommon.AccountEntity.isAccountEntity(value));
2285
+
2286
+ if (accountEntities.length > 0) {
2287
+ const accountEntity = accountEntities[0];
2288
+ const partitionKey = await this.partitionManager.extractKey(accountEntity);
2289
+ await this.client.set(partitionKey, cacheContext.tokenCache.serialize());
2290
+ }
2291
+ }
2292
+ }
2293
+
2294
+ }
2295
+
2194
2296
  Object.defineProperty(exports, 'AuthError', {
2195
2297
  enumerable: true,
2196
2298
  get: function () {
@@ -2203,6 +2305,12 @@ Object.defineProperty(exports, 'AuthErrorMessage', {
2203
2305
  return msalCommon.AuthErrorMessage;
2204
2306
  }
2205
2307
  });
2308
+ Object.defineProperty(exports, 'AzureCloudInstance', {
2309
+ enumerable: true,
2310
+ get: function () {
2311
+ return msalCommon.AzureCloudInstance;
2312
+ }
2313
+ });
2206
2314
  Object.defineProperty(exports, 'ClientAuthError', {
2207
2315
  enumerable: true,
2208
2316
  get: function () {
@@ -2285,6 +2393,7 @@ exports.ClientApplication = ClientApplication;
2285
2393
  exports.ClientAssertion = ClientAssertion;
2286
2394
  exports.ConfidentialClientApplication = ConfidentialClientApplication;
2287
2395
  exports.CryptoProvider = CryptoProvider;
2396
+ exports.DistributedCachePlugin = DistributedCachePlugin;
2288
2397
  exports.NodeStorage = NodeStorage;
2289
2398
  exports.PublicClientApplication = PublicClientApplication;
2290
2399
  exports.TokenCache = TokenCache;