@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
@@ -141,7 +141,7 @@ class HttpClient {
141
141
  url: url,
142
142
 
143
143
  /* istanbul ignore next */
144
- data: options && options.body || "",
144
+ data: options && options.body || Constants$1.EMPTY_STRING,
145
145
  timeout: cancellationToken,
146
146
 
147
147
  /* istanbul ignore next */
@@ -186,23 +186,23 @@ class NetworkUtils {
186
186
  * Licensed under the MIT License.
187
187
  */
188
188
  const DEFAULT_AUTH_OPTIONS = {
189
- clientId: "",
189
+ clientId: Constants$1.EMPTY_STRING,
190
190
  authority: Constants$1.DEFAULT_AUTHORITY,
191
- clientSecret: "",
192
- clientAssertion: "",
191
+ clientSecret: Constants$1.EMPTY_STRING,
192
+ clientAssertion: Constants$1.EMPTY_STRING,
193
193
  clientCertificate: {
194
- thumbprint: "",
195
- privateKey: "",
196
- x5c: ""
194
+ thumbprint: Constants$1.EMPTY_STRING,
195
+ privateKey: Constants$1.EMPTY_STRING,
196
+ x5c: Constants$1.EMPTY_STRING
197
197
  },
198
198
  knownAuthorities: [],
199
- cloudDiscoveryMetadata: "",
200
- authorityMetadata: "",
199
+ cloudDiscoveryMetadata: Constants$1.EMPTY_STRING,
200
+ authorityMetadata: Constants$1.EMPTY_STRING,
201
201
  clientCapabilities: [],
202
202
  protocolMode: ProtocolMode.AAD,
203
203
  azureCloudOptions: {
204
204
  azureCloudInstance: AzureCloudInstance.None,
205
- tenant: ""
205
+ tenant: Constants$1.EMPTY_STRING
206
206
  }
207
207
  };
208
208
  const DEFAULT_CACHE_OPTIONS = {};
@@ -215,7 +215,13 @@ const DEFAULT_LOGGER_OPTIONS = {
215
215
  const DEFAULT_SYSTEM_OPTIONS = {
216
216
  loggerOptions: DEFAULT_LOGGER_OPTIONS,
217
217
  networkClient: /*#__PURE__*/NetworkUtils.getNetworkClient(),
218
- proxyUrl: ""
218
+ proxyUrl: Constants$1.EMPTY_STRING
219
+ };
220
+ const DEFAULT_TELEMETRY_OPTIONS = {
221
+ application: {
222
+ appName: Constants$1.EMPTY_STRING,
223
+ appVersion: Constants$1.EMPTY_STRING
224
+ }
219
225
  };
220
226
  /**
221
227
  * Sets the default options when not explicitly configured from app developer
@@ -223,6 +229,7 @@ const DEFAULT_SYSTEM_OPTIONS = {
223
229
  * @param auth - Authentication options
224
230
  * @param cache - Cache options
225
231
  * @param system - System options
232
+ * @param telemetry - Telemetry options
226
233
  *
227
234
  * @returns Configuration
228
235
  * @public
@@ -231,7 +238,8 @@ const DEFAULT_SYSTEM_OPTIONS = {
231
238
  function buildAppConfiguration({
232
239
  auth,
233
240
  cache,
234
- system
241
+ system,
242
+ telemetry
235
243
  }) {
236
244
  return {
237
245
  auth: { ...DEFAULT_AUTH_OPTIONS,
@@ -242,6 +250,9 @@ function buildAppConfiguration({
242
250
  },
243
251
  system: { ...DEFAULT_SYSTEM_OPTIONS,
244
252
  ...system
253
+ },
254
+ telemetry: { ...DEFAULT_TELEMETRY_OPTIONS,
255
+ ...telemetry
245
256
  }
246
257
  };
247
258
  }
@@ -256,7 +267,7 @@ class GuidGenerator {
256
267
  * RFC4122: The version 4 UUID is meant for generating UUIDs from truly-random or pseudo-random numbers.
257
268
  * uuidv4 generates guids from cryprtographically-string random
258
269
  */
259
- static generateGuid() {
270
+ generateGuid() {
260
271
  return v4();
261
272
  }
262
273
  /**
@@ -265,7 +276,7 @@ class GuidGenerator {
265
276
  */
266
277
 
267
278
 
268
- static isGuid(guid) {
279
+ isGuid(guid) {
269
280
  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;
270
281
  return regexGuid.test(guid);
271
282
  }
@@ -293,7 +304,7 @@ class EncodingUtils {
293
304
 
294
305
 
295
306
  static base64EncodeUrl(str, encoding) {
296
- return EncodingUtils.base64Encode(str, encoding).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
307
+ return EncodingUtils.base64Encode(str, encoding).replace(/=/g, Constants$1.EMPTY_STRING).replace(/\+/g, "-").replace(/\//g, "_");
297
308
  }
298
309
  /**
299
310
  * 'utf8': Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
@@ -323,6 +334,21 @@ class EncodingUtils {
323
334
 
324
335
  }
325
336
 
337
+ /*
338
+ * Copyright (c) Microsoft Corporation. All rights reserved.
339
+ * Licensed under the MIT License.
340
+ */
341
+ class HashUtils {
342
+ /**
343
+ * generate 'SHA256' hash
344
+ * @param buffer
345
+ */
346
+ sha256(buffer) {
347
+ return crypto.createHash(Hash.SHA256).update(buffer).digest();
348
+ }
349
+
350
+ }
351
+
326
352
  /*
327
353
  * Copyright (c) Microsoft Corporation. All rights reserved.
328
354
  * Licensed under the MIT License.
@@ -332,10 +358,15 @@ class EncodingUtils {
332
358
  */
333
359
 
334
360
  class PkceGenerator {
361
+ constructor() {
362
+ this.hashUtils = new HashUtils();
363
+ }
335
364
  /**
336
365
  * generates the codeVerfier and the challenge from the codeVerfier
337
366
  * reference: https://tools.ietf.org/html/rfc7636#section-4.1 and https://tools.ietf.org/html/rfc7636#section-4.2
338
367
  */
368
+
369
+
339
370
  async generatePkceCodes() {
340
371
  const verifier = this.generateCodeVerifier();
341
372
  const challenge = this.generateCodeChallengeFromVerifier(verifier);
@@ -368,7 +399,7 @@ class PkceGenerator {
368
399
  charArr.push(CharSet.CV_CHARSET[index]);
369
400
  }
370
401
 
371
- const verifier = charArr.join("");
402
+ const verifier = charArr.join(Constants$1.EMPTY_STRING);
372
403
  return EncodingUtils.base64EncodeUrl(verifier);
373
404
  }
374
405
  /**
@@ -378,16 +409,7 @@ class PkceGenerator {
378
409
 
379
410
 
380
411
  generateCodeChallengeFromVerifier(codeVerifier) {
381
- return EncodingUtils.base64EncodeUrl(this.sha256(codeVerifier).toString("base64"), "base64");
382
- }
383
- /**
384
- * generate 'SHA256' hash
385
- * @param buffer
386
- */
387
-
388
-
389
- sha256(buffer) {
390
- return crypto.createHash(Hash.SHA256).update(buffer).digest();
412
+ return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(codeVerifier).toString("base64"), "base64");
391
413
  }
392
414
 
393
415
  }
@@ -406,6 +428,8 @@ class CryptoProvider {
406
428
  constructor() {
407
429
  // Browser crypto needs to be validated first before any other classes can be set.
408
430
  this.pkceGenerator = new PkceGenerator();
431
+ this.guidGenerator = new GuidGenerator();
432
+ this.hashUtils = new HashUtils();
409
433
  }
410
434
  /**
411
435
  * Creates a new random GUID - used to populate state and nonce.
@@ -414,7 +438,7 @@ class CryptoProvider {
414
438
 
415
439
 
416
440
  createNewGuid() {
417
- return GuidGenerator.generateGuid();
441
+ return this.guidGenerator.generateGuid();
418
442
  }
419
443
  /**
420
444
  * Encodes input string to base64.
@@ -480,8 +504,8 @@ class CryptoProvider {
480
504
  */
481
505
 
482
506
 
483
- hashString() {
484
- throw new Error("Method not implemented.");
507
+ async hashString(plainText) {
508
+ return EncodingUtils.base64EncodeUrl(this.hashUtils.sha256(plainText).toString("base64"), "base64");
485
509
  }
486
510
 
487
511
  }
@@ -588,7 +612,9 @@ class Deserializer {
588
612
  extendedExpiresOn: serializedAT.extended_expires_on,
589
613
  refreshOn: serializedAT.refresh_on,
590
614
  keyId: serializedAT.key_id,
591
- tokenType: serializedAT.token_type
615
+ tokenType: serializedAT.token_type,
616
+ requestedClaims: serializedAT.requestedClaims,
617
+ requestedClaimsHash: serializedAT.requestedClaimsHash
592
618
  };
593
619
  const accessToken = new AccessTokenEntity();
594
620
  CacheManager.toObject(accessToken, mappedAT);
@@ -752,7 +778,9 @@ class Serializer {
752
778
  extended_expires_on: atEntity.extendedExpiresOn,
753
779
  refresh_on: atEntity.refreshOn,
754
780
  key_id: atEntity.keyId,
755
- token_type: atEntity.tokenType
781
+ token_type: atEntity.tokenType,
782
+ requestedClaims: atEntity.requestedClaims,
783
+ requestedClaimsHash: atEntity.requestedClaimsHash
756
784
  };
757
785
  });
758
786
  return accessTokens;
@@ -891,12 +919,14 @@ class NodeStorage extends CacheManager {
891
919
  inMemoryCacheToCache(inMemoryCache) {
892
920
  // convert in memory cache to a flat Key-Value map
893
921
  let cache = this.getCache();
894
- cache = { ...inMemoryCache.accounts,
922
+ cache = { ...cache,
923
+ ...inMemoryCache.accounts,
895
924
  ...inMemoryCache.idTokens,
896
925
  ...inMemoryCache.accessTokens,
897
926
  ...inMemoryCache.refreshTokens,
898
927
  ...inMemoryCache.appMetadata
899
- };
928
+ }; // convert in memory cache to a flat Key-Value map
929
+
900
930
  return cache;
901
931
  }
902
932
  /**
@@ -1568,7 +1598,7 @@ class TokenCache {
1568
1598
 
1569
1599
  /* eslint-disable header/header */
1570
1600
  const name = "@azure/msal-node";
1571
- const version = "1.6.0";
1601
+ const version = "1.9.0";
1572
1602
 
1573
1603
  /*
1574
1604
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1604,7 +1634,7 @@ class ClientApplication {
1604
1634
  async getAuthCodeUrl(request) {
1605
1635
  this.logger.info("getAuthCodeUrl called", request.correlationId);
1606
1636
  const validRequest = { ...request,
1607
- ...this.initializeBaseRequest(request),
1637
+ ...(await this.initializeBaseRequest(request)),
1608
1638
  responseMode: request.responseMode || ResponseMode.QUERY,
1609
1639
  authenticationScheme: AuthenticationScheme.BEARER
1610
1640
  };
@@ -1623,10 +1653,10 @@ class ClientApplication {
1623
1653
  */
1624
1654
 
1625
1655
 
1626
- async acquireTokenByCode(request) {
1656
+ async acquireTokenByCode(request, authCodePayLoad) {
1627
1657
  this.logger.info("acquireTokenByCode called", request.correlationId);
1628
1658
  const validRequest = { ...request,
1629
- ...this.initializeBaseRequest(request),
1659
+ ...(await this.initializeBaseRequest(request)),
1630
1660
  authenticationScheme: AuthenticationScheme.BEARER
1631
1661
  };
1632
1662
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByCode, validRequest.correlationId);
@@ -1635,7 +1665,7 @@ class ClientApplication {
1635
1665
  const authClientConfig = await this.buildOauthClientConfiguration(validRequest.authority, validRequest.correlationId, serverTelemetryManager, undefined, request.azureCloudOptions);
1636
1666
  const authorizationCodeClient = new AuthorizationCodeClient(authClientConfig);
1637
1667
  this.logger.verbose("Auth code client created", validRequest.correlationId);
1638
- return authorizationCodeClient.acquireToken(validRequest);
1668
+ return authorizationCodeClient.acquireToken(validRequest, authCodePayLoad);
1639
1669
  } catch (e) {
1640
1670
  if (e instanceof AuthError) {
1641
1671
  e.setCorrelationId(validRequest.correlationId);
@@ -1657,7 +1687,7 @@ class ClientApplication {
1657
1687
  async acquireTokenByRefreshToken(request) {
1658
1688
  this.logger.info("acquireTokenByRefreshToken called", request.correlationId);
1659
1689
  const validRequest = { ...request,
1660
- ...this.initializeBaseRequest(request),
1690
+ ...(await this.initializeBaseRequest(request)),
1661
1691
  authenticationScheme: AuthenticationScheme.BEARER
1662
1692
  };
1663
1693
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByRefreshToken, validRequest.correlationId);
@@ -1688,7 +1718,7 @@ class ClientApplication {
1688
1718
 
1689
1719
  async acquireTokenSilent(request) {
1690
1720
  const validRequest = { ...request,
1691
- ...this.initializeBaseRequest(request),
1721
+ ...(await this.initializeBaseRequest(request)),
1692
1722
  forceRefresh: request.forceRefresh || false
1693
1723
  };
1694
1724
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenSilent, validRequest.correlationId, validRequest.forceRefresh);
@@ -1722,7 +1752,7 @@ class ClientApplication {
1722
1752
  async acquireTokenByUsernamePassword(request) {
1723
1753
  this.logger.info("acquireTokenByUsernamePassword called", request.correlationId);
1724
1754
  const validRequest = { ...request,
1725
- ...this.initializeBaseRequest(request)
1755
+ ...(await this.initializeBaseRequest(request))
1726
1756
  };
1727
1757
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByUsernamePassword, validRequest.correlationId);
1728
1758
 
@@ -1807,9 +1837,10 @@ class ClientApplication {
1807
1837
  libraryInfo: {
1808
1838
  sku: Constants.MSAL_SKU,
1809
1839
  version: version,
1810
- cpu: process.arch || "",
1811
- os: process.platform || ""
1840
+ cpu: process.arch || Constants$1.EMPTY_STRING,
1841
+ os: process.platform || Constants$1.EMPTY_STRING
1812
1842
  },
1843
+ telemetry: this.config.telemetry,
1813
1844
  persistencePlugin: this.config.cache.cachePlugin,
1814
1845
  serializableCache: this.tokenCache
1815
1846
  };
@@ -1827,14 +1858,19 @@ class ClientApplication {
1827
1858
  */
1828
1859
 
1829
1860
 
1830
- initializeBaseRequest(authRequest) {
1861
+ async initializeBaseRequest(authRequest) {
1831
1862
  this.logger.verbose("initializeRequestScopes called", authRequest.correlationId); // Default authenticationScheme to Bearer, log that POP isn't supported yet
1832
1863
 
1833
1864
  if (authRequest.authenticationScheme && authRequest.authenticationScheme === AuthenticationScheme.POP) {
1834
1865
  this.logger.verbose("Authentication Scheme 'pop' is not supported yet, setting Authentication Scheme to 'Bearer' for request", authRequest.correlationId);
1835
1866
  }
1836
1867
 
1837
- authRequest.authenticationScheme = AuthenticationScheme.BEARER;
1868
+ authRequest.authenticationScheme = AuthenticationScheme.BEARER; // Set requested claims hash if claims were requested
1869
+
1870
+ if (authRequest.claims && !StringUtils.isEmpty(authRequest.claims)) {
1871
+ authRequest.requestedClaimsHash = await this.cryptoProvider.hashString(authRequest.claims);
1872
+ }
1873
+
1838
1874
  return { ...authRequest,
1839
1875
  scopes: [...(authRequest && authRequest.scopes || []), ...OIDC_DEFAULT_SCOPES],
1840
1876
  correlationId: authRequest && authRequest.correlationId || this.cryptoProvider.createNewGuid(),
@@ -1878,6 +1914,14 @@ class ClientApplication {
1878
1914
  };
1879
1915
  return await AuthorityFactory.createDiscoveredInstance(authorityUrl, this.config.system.networkClient, this.storage, authorityOptions);
1880
1916
  }
1917
+ /**
1918
+ * Clear the cache
1919
+ */
1920
+
1921
+
1922
+ clearCache() {
1923
+ this.storage.clear();
1924
+ }
1881
1925
 
1882
1926
  }
1883
1927
 
@@ -1925,7 +1969,7 @@ class PublicClientApplication extends ClientApplication {
1925
1969
 
1926
1970
  async acquireTokenByDeviceCode(request) {
1927
1971
  this.logger.info("acquireTokenByDeviceCode called", request.correlationId);
1928
- const validRequest = Object.assign(request, this.initializeBaseRequest(request));
1972
+ const validRequest = Object.assign(request, await this.initializeBaseRequest(request));
1929
1973
  const serverTelemetryManager = this.initializeServerTelemetryManager(ApiId.acquireTokenByDeviceCode, validRequest.correlationId);
1930
1974
 
1931
1975
  try {
@@ -2074,7 +2118,7 @@ class ClientAssertion {
2074
2118
 
2075
2119
  while ((matches = regexToFindCerts.exec(publicCertificate)) !== null) {
2076
2120
  // matches[1] represents the first parens capture group in the regex.
2077
- certs.push(matches[1].replace(/\n/, ""));
2121
+ certs.push(matches[1].replace(/\n/, Constants$1.EMPTY_STRING));
2078
2122
  }
2079
2123
 
2080
2124
  return certs;
@@ -2124,7 +2168,7 @@ class ConfidentialClientApplication extends ClientApplication {
2124
2168
  async acquireTokenByClientCredential(request) {
2125
2169
  this.logger.info("acquireTokenByClientCredential called", request.correlationId);
2126
2170
  const validRequest = { ...request,
2127
- ...this.initializeBaseRequest(request)
2171
+ ...(await this.initializeBaseRequest(request))
2128
2172
  };
2129
2173
  const azureRegionConfiguration = {
2130
2174
  azureRegion: validRequest.azureRegion,
@@ -2162,7 +2206,7 @@ class ConfidentialClientApplication extends ClientApplication {
2162
2206
  async acquireTokenOnBehalfOf(request) {
2163
2207
  this.logger.info("acquireTokenOnBehalfOf called", request.correlationId);
2164
2208
  const validRequest = { ...request,
2165
- ...this.initializeBaseRequest(request)
2209
+ ...(await this.initializeBaseRequest(request))
2166
2210
  };
2167
2211
 
2168
2212
  try {
@@ -2183,8 +2227,8 @@ class ConfidentialClientApplication extends ClientApplication {
2183
2227
  const clientSecretNotEmpty = !StringUtils.isEmpty(configuration.auth.clientSecret);
2184
2228
  const clientAssertionNotEmpty = !StringUtils.isEmpty(configuration.auth.clientAssertion);
2185
2229
  const certificate = configuration.auth.clientCertificate || {
2186
- thumbprint: "",
2187
- privateKey: ""
2230
+ thumbprint: Constants$1.EMPTY_STRING,
2231
+ privateKey: Constants$1.EMPTY_STRING
2188
2232
  };
2189
2233
  const certificateNotEmpty = !StringUtils.isEmpty(certificate.thumbprint) || !StringUtils.isEmpty(certificate.privateKey); // Check that at most one credential is set on the application
2190
2234