@azure/msal-node 1.6.0 → 1.9.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 (35) hide show
  1. package/README.md +1 -1
  2. package/dist/cache/NodeStorage.d.ts.map +1 -1
  3. package/dist/cache/serializer/Deserializer.d.ts.map +1 -1
  4. package/dist/cache/serializer/Serializer.d.ts.map +1 -1
  5. package/dist/cache/serializer/SerializerTypes.d.ts +2 -0
  6. package/dist/cache/serializer/SerializerTypes.d.ts.map +1 -1
  7. package/dist/client/ClientApplication.d.ts +7 -3
  8. package/dist/client/ClientApplication.d.ts.map +1 -1
  9. package/dist/client/ConfidentialClientApplication.d.ts.map +1 -1
  10. package/dist/client/IConfidentialClientApplication.d.ts +2 -0
  11. package/dist/client/IConfidentialClientApplication.d.ts.map +1 -1
  12. package/dist/client/IPublicClientApplication.d.ts +2 -0
  13. package/dist/client/IPublicClientApplication.d.ts.map +1 -1
  14. package/dist/config/Configuration.d.ts +8 -2
  15. package/dist/config/Configuration.d.ts.map +1 -1
  16. package/dist/crypto/CryptoProvider.d.ts +3 -1
  17. package/dist/crypto/CryptoProvider.d.ts.map +1 -1
  18. package/dist/crypto/GuidGenerator.d.ts +4 -3
  19. package/dist/crypto/GuidGenerator.d.ts.map +1 -1
  20. package/dist/crypto/HashUtils.d.ts +9 -0
  21. package/dist/crypto/HashUtils.d.ts.map +1 -0
  22. package/dist/crypto/PkceGenerator.d.ts +2 -5
  23. package/dist/crypto/PkceGenerator.d.ts.map +1 -1
  24. package/dist/msal-node.cjs.development.js +95 -51
  25. package/dist/msal-node.cjs.development.js.map +1 -1
  26. package/dist/msal-node.cjs.production.min.js +1 -1
  27. package/dist/msal-node.cjs.production.min.js.map +1 -1
  28. package/dist/msal-node.esm.js +95 -51
  29. package/dist/msal-node.esm.js.map +1 -1
  30. package/dist/network/HttpClient.d.ts.map +1 -1
  31. package/dist/packageMetadata.d.ts +1 -1
  32. package/dist/utils/EncodingUtils.d.ts.map +1 -1
  33. package/package.json +3 -3
  34. package/CHANGELOG.json +0 -1027
  35. package/CHANGELOG.md +0 -333
@@ -146,7 +146,7 @@ class HttpClient {
146
146
  url: url,
147
147
 
148
148
  /* istanbul ignore next */
149
- data: options && options.body || "",
149
+ data: options && options.body || msalCommon.Constants.EMPTY_STRING,
150
150
  timeout: cancellationToken,
151
151
 
152
152
  /* istanbul ignore next */
@@ -191,23 +191,23 @@ class NetworkUtils {
191
191
  * Licensed under the MIT License.
192
192
  */
193
193
  const DEFAULT_AUTH_OPTIONS = {
194
- clientId: "",
194
+ clientId: msalCommon.Constants.EMPTY_STRING,
195
195
  authority: msalCommon.Constants.DEFAULT_AUTHORITY,
196
- clientSecret: "",
197
- clientAssertion: "",
196
+ clientSecret: msalCommon.Constants.EMPTY_STRING,
197
+ clientAssertion: msalCommon.Constants.EMPTY_STRING,
198
198
  clientCertificate: {
199
- thumbprint: "",
200
- privateKey: "",
201
- x5c: ""
199
+ thumbprint: msalCommon.Constants.EMPTY_STRING,
200
+ privateKey: msalCommon.Constants.EMPTY_STRING,
201
+ x5c: msalCommon.Constants.EMPTY_STRING
202
202
  },
203
203
  knownAuthorities: [],
204
- cloudDiscoveryMetadata: "",
205
- authorityMetadata: "",
204
+ cloudDiscoveryMetadata: msalCommon.Constants.EMPTY_STRING,
205
+ authorityMetadata: msalCommon.Constants.EMPTY_STRING,
206
206
  clientCapabilities: [],
207
207
  protocolMode: msalCommon.ProtocolMode.AAD,
208
208
  azureCloudOptions: {
209
209
  azureCloudInstance: msalCommon.AzureCloudInstance.None,
210
- tenant: ""
210
+ tenant: msalCommon.Constants.EMPTY_STRING
211
211
  }
212
212
  };
213
213
  const DEFAULT_CACHE_OPTIONS = {};
@@ -220,7 +220,13 @@ const DEFAULT_LOGGER_OPTIONS = {
220
220
  const DEFAULT_SYSTEM_OPTIONS = {
221
221
  loggerOptions: DEFAULT_LOGGER_OPTIONS,
222
222
  networkClient: /*#__PURE__*/NetworkUtils.getNetworkClient(),
223
- proxyUrl: ""
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
+ }
224
230
  };
225
231
  /**
226
232
  * Sets the default options when not explicitly configured from app developer
@@ -228,6 +234,7 @@ const DEFAULT_SYSTEM_OPTIONS = {
228
234
  * @param auth - Authentication options
229
235
  * @param cache - Cache options
230
236
  * @param system - System options
237
+ * @param telemetry - Telemetry options
231
238
  *
232
239
  * @returns Configuration
233
240
  * @public
@@ -236,7 +243,8 @@ const DEFAULT_SYSTEM_OPTIONS = {
236
243
  function buildAppConfiguration({
237
244
  auth,
238
245
  cache,
239
- system
246
+ system,
247
+ telemetry
240
248
  }) {
241
249
  return {
242
250
  auth: { ...DEFAULT_AUTH_OPTIONS,
@@ -247,6 +255,9 @@ function buildAppConfiguration({
247
255
  },
248
256
  system: { ...DEFAULT_SYSTEM_OPTIONS,
249
257
  ...system
258
+ },
259
+ telemetry: { ...DEFAULT_TELEMETRY_OPTIONS,
260
+ ...telemetry
250
261
  }
251
262
  };
252
263
  }
@@ -261,7 +272,7 @@ class GuidGenerator {
261
272
  * RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or pseudo-random numbers.
262
273
  * uuidv4 generates guids from cryprtographically-string random
263
274
  */
264
- static generateGuid() {
275
+ generateGuid() {
265
276
  return uuid.v4();
266
277
  }
267
278
  /**
@@ -270,7 +281,7 @@ class GuidGenerator {
270
281
  */
271
282
 
272
283
 
273
- static isGuid(guid) {
284
+ isGuid(guid) {
274
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;
275
286
  return regexGuid.test(guid);
276
287
  }
@@ -298,7 +309,7 @@ class EncodingUtils {
298
309
 
299
310
 
300
311
  static base64EncodeUrl(str, encoding) {
301
- 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, "_");
302
313
  }
303
314
  /**
304
315
  * 'utf8': Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
@@ -328,6 +339,21 @@ class EncodingUtils {
328
339
 
329
340
  }
330
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
+
331
357
  /*
332
358
  * Copyright (c) Microsoft Corporation. All rights reserved.
333
359
  * Licensed under the MIT License.
@@ -337,10 +363,15 @@ class EncodingUtils {
337
363
  */
338
364
 
339
365
  class PkceGenerator {
366
+ constructor() {
367
+ this.hashUtils = new HashUtils();
368
+ }
340
369
  /**
341
370
  * generates the codeVerfier and the challenge from the codeVerfier
342
371
  * reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
343
372
  */
373
+
374
+
344
375
  async generatePkceCodes() {
345
376
  const verifier = this.generateCodeVerifier();
346
377
  const challenge = this.generateCodeChallengeFromVerifier(verifier);
@@ -373,7 +404,7 @@ class PkceGenerator {
373
404
  charArr.push(CharSet.CV_CHARSET[index]);
374
405
  }
375
406
 
376
- const verifier = charArr.join("");
407
+ const verifier = charArr.join(msalCommon.Constants.EMPTY_STRING);
377
408
  return EncodingUtils.base64EncodeUrl(verifier);
378
409
  }
379
410
  /**
@@ -383,16 +414,7 @@ class PkceGenerator {
383
414
 
384
415
 
385
416
  generateCodeChallengeFromVerifier(codeVerifier) {
386
- return EncodingUtils.base64EncodeUrl(this.sha256(codeVerifier).toString("base64"), "base64");
387
- }
388
- /**
389
- * generate 'SHA256' hash
390
- * @param buffer
391
- */
392
-
393
-
394
- sha256(buffer) {
395
- return crypto.createHash(Hash.SHA256).update(buffer).digest();
417
+ return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(codeVerifier).toString("base64"), "base64");
396
418
  }
397
419
 
398
420
  }
@@ -411,6 +433,8 @@ class CryptoProvider {
411
433
  constructor() {
412
434
  // Browser crypto needs to be validated first before any other classes can be set.
413
435
  this.pkceGenerator = new PkceGenerator();
436
+ this.guidGenerator = new GuidGenerator();
437
+ this.hashUtils = new HashUtils();
414
438
  }
415
439
  /**
416
440
  * Creates a new random GUID - used to populate state and nonce.
@@ -419,7 +443,7 @@ class CryptoProvider {
419
443
 
420
444
 
421
445
  createNewGuid() {
422
- return GuidGenerator.generateGuid();
446
+ return this.guidGenerator.generateGuid();
423
447
  }
424
448
  /**
425
449
  * Encodes input string to base64.
@@ -485,8 +509,8 @@ class CryptoProvider {
485
509
  */
486
510
 
487
511
 
488
- hashString() {
489
- throw new Error("Method not implemented.");
512
+ async hashString(plainText) {
513
+ return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(plainText).toString("base64"), "base64");
490
514
  }
491
515
 
492
516
  }
@@ -593,7 +617,9 @@ class Deserializer {
593
617
  extendedExpiresOn: serializedAT.extended_expires_on,
594
618
  refreshOn: serializedAT.refresh_on,
595
619
  keyId: serializedAT.key_id,
596
- tokenType: serializedAT.token_type
620
+ tokenType: serializedAT.token_type,
621
+ requestedClaims: serializedAT.requestedClaims,
622
+ requestedClaimsHash: serializedAT.requestedClaimsHash
597
623
  };
598
624
  const accessToken = new msalCommon.AccessTokenEntity();
599
625
  msalCommon.CacheManager.toObject(accessToken, mappedAT);
@@ -757,7 +783,9 @@ class Serializer {
757
783
  extended_expires_on: atEntity.extendedExpiresOn,
758
784
  refresh_on: atEntity.refreshOn,
759
785
  key_id: atEntity.keyId,
760
- token_type: atEntity.tokenType
786
+ token_type: atEntity.tokenType,
787
+ requestedClaims: atEntity.requestedClaims,
788
+ requestedClaimsHash: atEntity.requestedClaimsHash
761
789
  };
762
790
  });
763
791
  return accessTokens;
@@ -896,12 +924,14 @@ class NodeStorage extends msalCommon.CacheManager {
896
924
  inMemoryCacheToCache(inMemoryCache) {
897
925
  // convert in memory cache to a flat Key-Value map
898
926
  let cache = this.getCache();
899
- cache = { ...inMemoryCache.accounts,
927
+ cache = { ...cache,
928
+ ...inMemoryCache.accounts,
900
929
  ...inMemoryCache.idTokens,
901
930
  ...inMemoryCache.accessTokens,
902
931
  ...inMemoryCache.refreshTokens,
903
932
  ...inMemoryCache.appMetadata
904
- };
933
+ }; // convert in memory cache to a flat Key-Value map
934
+
905
935
  return cache;
906
936
  }
907
937
  /**
@@ -1573,7 +1603,7 @@ class TokenCache {
1573
1603
 
1574
1604
  /* eslint-disable header/header */
1575
1605
  const name = "@azure/msal-node";
1576
- const version = "1.6.0";
1606
+ const version = "1.9.0";
1577
1607
 
1578
1608
  /*
1579
1609
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1609,7 +1639,7 @@ class ClientApplication {
1609
1639
  async getAuthCodeUrl(request) {
1610
1640
  this.logger.info("getAuthCodeUrl called", request.correlationId);
1611
1641
  const validRequest = { ...request,
1612
- ...this.initializeBaseRequest(request),
1642
+ ...(await this.initializeBaseRequest(request)),
1613
1643
  responseMode: request.responseMode || msalCommon.ResponseMode.QUERY,
1614
1644
  authenticationScheme: msalCommon.AuthenticationScheme.BEARER
1615
1645
  };
@@ -1628,10 +1658,10 @@ class ClientApplication {
1628
1658
  */
1629
1659
 
1630
1660
 
1631
- async acquireTokenByCode(request) {
1661
+ async acquireTokenByCode(request, authCodePayLoad) {
1632
1662
  this.logger.info("acquireTokenByCode called", request.correlationId);
1633
1663
  const validRequest = { ...request,
1634
- ...this.initializeBaseRequest(request),
1664
+ ...(await this.initializeBaseRequest(request)),
1635
1665
  authenticationScheme: msalCommon.AuthenticationScheme.BEARER
1636
1666
  };
1637
1667
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByCode, validRequest.correlationId);
@@ -1640,7 +1670,7 @@ class ClientApplication {
1640
1670
  const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
1641
1671
  const authorizationCodeClient = new msalCommon.AuthorizationCodeClient(authClientConfig);
1642
1672
  this.logger.verbose("Auth code client created", validRequest.correlationId);
1643
- return authorizationCodeClient.acquireToken(validRequest);
1673
+ return authorizationCodeClient.acquireToken(validRequest, authCodePayLoad);
1644
1674
  } catch (e) {
1645
1675
  if (e instanceof msalCommon.AuthError) {
1646
1676
  e.setCorrelationId(validRequest.correlationId);
@@ -1662,7 +1692,7 @@ class ClientApplication {
1662
1692
  async acquireTokenByRefreshToken(request) {
1663
1693
  this.logger.info("acquireTokenByRefreshToken called", request.correlationId);
1664
1694
  const validRequest = { ...request,
1665
- ...this.initializeBaseRequest(request),
1695
+ ...(await this.initializeBaseRequest(request)),
1666
1696
  authenticationScheme: msalCommon.AuthenticationScheme.BEARER
1667
1697
  };
1668
1698
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByRefreshToken, validRequest.correlationId);
@@ -1693,7 +1723,7 @@ class ClientApplication {
1693
1723
 
1694
1724
  async acquireTokenSilent(request) {
1695
1725
  const validRequest = { ...request,
1696
- ...this.initializeBaseRequest(request),
1726
+ ...(await this.initializeBaseRequest(request)),
1697
1727
  forceRefresh: request.forceRefresh || false
1698
1728
  };
1699
1729
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent, validRequest.correlationId, validRequest.forceRefresh);
@@ -1727,7 +1757,7 @@ class ClientApplication {
1727
1757
  async acquireTokenByUsernamePassword(request) {
1728
1758
  this.logger.info("acquireTokenByUsernamePassword called", request.correlationId);
1729
1759
  const validRequest = { ...request,
1730
- ...this.initializeBaseRequest(request)
1760
+ ...(await this.initializeBaseRequest(request))
1731
1761
  };
1732
1762
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByUsernamePassword, validRequest.correlationId);
1733
1763
 
@@ -1812,9 +1842,10 @@ class ClientApplication {
1812
1842
  libraryInfo: {
1813
1843
  sku: Constants.MSAL_SKU,
1814
1844
  version: version,
1815
- cpu: process.arch || "",
1816
- os: process.platform || ""
1845
+ cpu: process.arch || msalCommon.Constants.EMPTY_STRING,
1846
+ os: process.platform || msalCommon.Constants.EMPTY_STRING
1817
1847
  },
1848
+ telemetry: this.config.telemetry,
1818
1849
  persistencePlugin: this.config.cache.cachePlugin,
1819
1850
  serializableCache: this.tokenCache
1820
1851
  };
@@ -1832,14 +1863,19 @@ class ClientApplication {
1832
1863
  */
1833
1864
 
1834
1865
 
1835
- initializeBaseRequest(authRequest) {
1866
+ async initializeBaseRequest(authRequest) {
1836
1867
  this.logger.verbose("initializeRequestScopes called", authRequest.correlationId); // Default authenticationScheme to Bearer, log that POP isn't supported yet
1837
1868
 
1838
1869
  if (authRequest.authenticationScheme && authRequest.authenticationScheme === msalCommon.AuthenticationScheme.POP) {
1839
1870
  this.logger.verbose("Authentication Scheme 'pop' is not supported yet, setting Authentication Scheme to 'Bearer' for request", authRequest.correlationId);
1840
1871
  }
1841
1872
 
1842
- 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
+
1843
1879
  return { ...authRequest,
1844
1880
  scopes: [...(authRequest && authRequest.scopes || []), ...msalCommon.OIDC_DEFAULT_SCOPES],
1845
1881
  correlationId: authRequest && authRequest.correlationId || this.cryptoProvider.createNewGuid(),
@@ -1883,6 +1919,14 @@ class ClientApplication {
1883
1919
  };
1884
1920
  return await msalCommon.AuthorityFactory.createDiscoveredInstance(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions);
1885
1921
  }
1922
+ /**
1923
+ * Clear the cache
1924
+ */
1925
+
1926
+
1927
+ clearCache() {
1928
+ this.storage.clear();
1929
+ }
1886
1930
 
1887
1931
  }
1888
1932
 
@@ -1930,7 +1974,7 @@ class PublicClientApplication extends ClientApplication {
1930
1974
 
1931
1975
  async acquireTokenByDeviceCode(request) {
1932
1976
  this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
1933
- const validRequest = Object.assign(request, this.initializeBaseRequest(request));
1977
+ const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
1934
1978
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
1935
1979
 
1936
1980
  try {
@@ -2079,7 +2123,7 @@ class ClientAssertion {
2079
2123
 
2080
2124
  while ((matches = regexToFindCerts.exec(publicCertificate)) !== null) {
2081
2125
  // matches[1] represents the first parens capture group in the regex.
2082
- certs.push(matches[1].replace(/\n/, ""));
2126
+ certs.push(matches[1].replace(/\n/, msalCommon.Constants.EMPTY_STRING));
2083
2127
  }
2084
2128
 
2085
2129
  return certs;
@@ -2129,7 +2173,7 @@ class ConfidentialClientApplication extends ClientApplication {
2129
2173
  async acquireTokenByClientCredential(request) {
2130
2174
  this.logger.info("acquireTokenByClientCredential called", request.correlationId);
2131
2175
  const validRequest = { ...request,
2132
- ...this.initializeBaseRequest(request)
2176
+ ...(await this.initializeBaseRequest(request))
2133
2177
  };
2134
2178
  const azureRegionConfiguration = {
2135
2179
  azureRegion: validRequest.azureRegion,
@@ -2167,7 +2211,7 @@ class ConfidentialClientApplication extends ClientApplication {
2167
2211
  async acquireTokenOnBehalfOf(request) {
2168
2212
  this.logger.info("acquireTokenOnBehalfOf called", request.correlationId);
2169
2213
  const validRequest = { ...request,
2170
- ...this.initializeBaseRequest(request)
2214
+ ...(await this.initializeBaseRequest(request))
2171
2215
  };
2172
2216
 
2173
2217
  try {
@@ -2188,8 +2232,8 @@ class ConfidentialClientApplication extends ClientApplication {
2188
2232
  const clientSecretNotEmpty = !msalCommon.StringUtils.isEmpty(configuration.auth.clientSecret);
2189
2233
  const clientAssertionNotEmpty = !msalCommon.StringUtils.isEmpty(configuration.auth.clientAssertion);
2190
2234
  const certificate = configuration.auth.clientCertificate || {
2191
- thumbprint: "",
2192
- privateKey: ""
2235
+ thumbprint: msalCommon.Constants.EMPTY_STRING,
2236
+ privateKey: msalCommon.Constants.EMPTY_STRING
2193
2237
  };
2194
2238
  const certificateNotEmpty = !msalCommon.StringUtils.isEmpty(certificate.thumbprint) || !msalCommon.StringUtils.isEmpty(certificate.privateKey); // Check that at most one credential is set on the application
2195
2239