@azure/identity 3.3.2-alpha.20231013.2 → 3.3.2

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.

Potentially problematic release.


This version of @azure/identity might be problematic. Click here for more details.

Files changed (58) hide show
  1. package/dist/index.js +216 -103
  2. package/dist/index.js.map +1 -1
  3. package/dist-esm/src/client/identityClient.js.map +1 -1
  4. package/dist-esm/src/credentials/authorizationCodeCredential.js +2 -2
  5. package/dist-esm/src/credentials/authorizationCodeCredential.js.map +1 -1
  6. package/dist-esm/src/credentials/azureCliCredential.js +2 -2
  7. package/dist-esm/src/credentials/azureCliCredential.js.map +1 -1
  8. package/dist-esm/src/credentials/azureDeveloperCliCredential.js +2 -2
  9. package/dist-esm/src/credentials/azureDeveloperCliCredential.js.map +1 -1
  10. package/dist-esm/src/credentials/azurePowerShellCredential.js +2 -2
  11. package/dist-esm/src/credentials/azurePowerShellCredential.js.map +1 -1
  12. package/dist-esm/src/credentials/clientAssertionCredential.js +2 -2
  13. package/dist-esm/src/credentials/clientAssertionCredential.js.map +1 -1
  14. package/dist-esm/src/credentials/clientCertificateCredential.js +3 -3
  15. package/dist-esm/src/credentials/clientCertificateCredential.js.map +1 -1
  16. package/dist-esm/src/credentials/clientSecretCredential.browser.js +3 -3
  17. package/dist-esm/src/credentials/clientSecretCredential.browser.js.map +1 -1
  18. package/dist-esm/src/credentials/clientSecretCredential.js +2 -2
  19. package/dist-esm/src/credentials/clientSecretCredential.js.map +1 -1
  20. package/dist-esm/src/credentials/deviceCodeCredential.js +2 -2
  21. package/dist-esm/src/credentials/deviceCodeCredential.js.map +1 -1
  22. package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js +5 -5
  23. package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js.map +1 -1
  24. package/dist-esm/src/credentials/interactiveBrowserCredential.js +2 -2
  25. package/dist-esm/src/credentials/interactiveBrowserCredential.js.map +1 -1
  26. package/dist-esm/src/credentials/interactiveBrowserCredentialOptions.js.map +1 -1
  27. package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js +14 -4
  28. package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
  29. package/dist-esm/src/credentials/managedIdentityCredential/index.js +11 -3
  30. package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
  31. package/dist-esm/src/credentials/onBehalfOfCredential.js +3 -3
  32. package/dist-esm/src/credentials/onBehalfOfCredential.js.map +1 -1
  33. package/dist-esm/src/credentials/usernamePasswordCredential.browser.js +2 -2
  34. package/dist-esm/src/credentials/usernamePasswordCredential.browser.js.map +1 -1
  35. package/dist-esm/src/credentials/usernamePasswordCredential.js +2 -2
  36. package/dist-esm/src/credentials/usernamePasswordCredential.js.map +1 -1
  37. package/dist-esm/src/credentials/visualStudioCodeCredential.js +2 -2
  38. package/dist-esm/src/credentials/visualStudioCodeCredential.js.map +1 -1
  39. package/dist-esm/src/errors.js.map +1 -1
  40. package/dist-esm/src/msal/browserFlows/msalAuthCode.js +1 -1
  41. package/dist-esm/src/msal/browserFlows/msalAuthCode.js.map +1 -1
  42. package/dist-esm/src/msal/browserFlows/msalBrowserCommon.js +2 -2
  43. package/dist-esm/src/msal/browserFlows/msalBrowserCommon.js.map +1 -1
  44. package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js +2 -2
  45. package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js.map +1 -1
  46. package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js +142 -16
  47. package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js.map +1 -1
  48. package/dist-esm/src/msal/utils.js +4 -3
  49. package/dist-esm/src/msal/utils.js.map +1 -1
  50. package/dist-esm/src/plugins/provider.js.map +1 -1
  51. package/dist-esm/src/util/scopeUtils.js +1 -1
  52. package/dist-esm/src/util/scopeUtils.js.map +1 -1
  53. package/dist-esm/src/util/tenantIdUtils.js +3 -3
  54. package/dist-esm/src/util/tenantIdUtils.js.map +1 -1
  55. package/package.json +15 -14
  56. package/types/identity.d.ts +4 -6
  57. package/dist-esm/src/msal/utils.browser.js +0 -236
  58. package/dist-esm/src/msal/utils.browser.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,9 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var msalCommon = require('@azure/msal-node');
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var msalNode = require('@azure/msal-node');
4
6
  var logger$o = require('@azure/logger');
7
+ var msalCommon = require('@azure/msal-common');
5
8
  var abortController = require('@azure/abort-controller');
6
9
  var coreUtil = require('@azure/core-util');
10
+ var uuid = require('uuid');
7
11
  var coreClient = require('@azure/core-client');
8
12
  var coreRestPipeline = require('@azure/core-rest-pipeline');
9
13
  var coreTracing = require('@azure/core-tracing');
@@ -15,9 +19,14 @@ var https = require('https');
15
19
  var child_process = require('child_process');
16
20
  var crypto = require('crypto');
17
21
  var util = require('util');
22
+ var http = require('http');
18
23
  var open = require('open');
24
+ var stoppable = require('stoppable');
25
+
26
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
27
 
20
- function _interopNamespaceDefault(e) {
28
+ function _interopNamespace(e) {
29
+ if (e && e.__esModule) return e;
21
30
  var n = Object.create(null);
22
31
  if (e) {
23
32
  Object.keys(e).forEach(function (k) {
@@ -30,12 +39,21 @@ function _interopNamespaceDefault(e) {
30
39
  }
31
40
  });
32
41
  }
33
- n.default = e;
42
+ n["default"] = e;
34
43
  return Object.freeze(n);
35
44
  }
36
45
 
37
- var msalCommon__namespace = /*#__PURE__*/_interopNamespaceDefault(msalCommon);
38
- var child_process__namespace = /*#__PURE__*/_interopNamespaceDefault(child_process);
46
+ var msalNode__namespace = /*#__PURE__*/_interopNamespace(msalNode);
47
+ var msalCommon__namespace = /*#__PURE__*/_interopNamespace(msalCommon);
48
+ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
49
+ var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
50
+ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
51
+ var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
52
+ var child_process__default = /*#__PURE__*/_interopDefaultLegacy(child_process);
53
+ var child_process__namespace = /*#__PURE__*/_interopNamespace(child_process);
54
+ var http__default = /*#__PURE__*/_interopDefaultLegacy(http);
55
+ var open__default = /*#__PURE__*/_interopDefaultLegacy(open);
56
+ var stoppable__default = /*#__PURE__*/_interopDefaultLegacy(stoppable);
39
57
 
40
58
  // Copyright (c) Microsoft Corporation.
41
59
  // Licensed under the MIT license.
@@ -157,7 +175,6 @@ class AuthenticationRequiredError extends Error {
157
175
  }
158
176
 
159
177
  // Copyright (c) Microsoft Corporation.
160
- // Licensed under the MIT license.
161
178
  /**
162
179
  * The AzureLogger used for all clients within the identity package
163
180
  */
@@ -288,7 +305,6 @@ const CACHE_CAE_SUFFIX = ".cae";
288
305
  const CACHE_NON_CAE_SUFFIX = ".nocae";
289
306
 
290
307
  // Copyright (c) Microsoft Corporation.
291
- // Licensed under the MIT license.
292
308
  /**
293
309
  * Latest AuthenticationRecord version
294
310
  * @internal
@@ -407,7 +423,7 @@ class MsalBaseUtilities {
407
423
  * Generates a UUID
408
424
  */
409
425
  generateUuid() {
410
- return coreUtil.randomUUID();
426
+ return uuid.v4();
411
427
  }
412
428
  /**
413
429
  * Handles the MSAL authentication result.
@@ -518,7 +534,6 @@ function deserializeAuthenticationRecord(serializedRecord) {
518
534
  }
519
535
 
520
536
  // Copyright (c) Microsoft Corporation.
521
- // Licensed under the MIT license.
522
537
  function createConfigurationErrorMessage(tenantId) {
523
538
  return `The current credential is not configured to acquire tokens for tenant ${tenantId}. To enable acquiring tokens for this tenant add it to the AdditionallyAllowedTenants on the credential options, or add "*" to AdditionallyAllowedTenants to allow acquiring tokens for any tenant.`;
524
539
  }
@@ -552,13 +567,12 @@ function processMultiTenantRequest(tenantId, getTokenOptions, additionallyAllowe
552
567
  }
553
568
 
554
569
  // Copyright (c) Microsoft Corporation.
555
- // Licensed under the MIT license.
556
570
  /**
557
571
  * @internal
558
572
  */
559
573
  function checkTenantId(logger, tenantId) {
560
- if (!tenantId.match(/^[0-9a-zA-Z-.:/]+$/)) {
561
- const error = new Error("Invalid tenant id provided. You can locate your tenant id by following the instructions listed here: https://docs.microsoft.com/partner-center/find-ids-and-domain-names.");
574
+ if (!tenantId.match(/^[0-9a-zA-Z-.]+$/)) {
575
+ const error = new Error("Invalid tenant id provided. You can locate your tenant id by following the instructions listed here: https://learn.microsoft.com/partner-center/find-ids-and-domain-names.");
562
576
  logger.info(formatError("", error));
563
577
  throw error;
564
578
  }
@@ -582,7 +596,7 @@ function resolveTenantId(logger, tenantId, clientId) {
582
596
  /**
583
597
  * @internal
584
598
  */
585
- function resolveAddionallyAllowedTenantIds(additionallyAllowedTenants) {
599
+ function resolveAdditionallyAllowedTenantIds(additionallyAllowedTenants) {
586
600
  if (!additionallyAllowedTenants || additionallyAllowedTenants.length === 0) {
587
601
  return [];
588
602
  }
@@ -604,7 +618,6 @@ function getIdentityTokenEndpointSuffix(tenantId) {
604
618
  }
605
619
 
606
620
  // Copyright (c) Microsoft Corporation.
607
- // Licensed under the MIT license.
608
621
  /**
609
622
  * Creates a span using the global tracer.
610
623
  * @internal
@@ -625,7 +638,6 @@ const azureArcAPIVersion = "2019-11-01";
625
638
  const azureFabricVersion = "2019-07-01-preview";
626
639
 
627
640
  // Copyright (c) Microsoft Corporation.
628
- // Licensed under the MIT license.
629
641
  /**
630
642
  * Most MSIs send requests to the IMDS endpoint, or a similar endpoint.
631
643
  * These are GET requests that require sending a `resource` parameter on the query.
@@ -676,7 +688,6 @@ function parseExpirationTimestamp(body) {
676
688
  }
677
689
 
678
690
  // Copyright (c) Microsoft Corporation.
679
- // Licensed under the MIT license.
680
691
  const noCorrelationId = "noCorrelationId";
681
692
  /**
682
693
  * @internal
@@ -1021,7 +1032,6 @@ var RegionalAuthority;
1021
1032
  })(RegionalAuthority || (RegionalAuthority = {}));
1022
1033
 
1023
1034
  // Copyright (c) Microsoft Corporation.
1024
- // Licensed under the MIT license.
1025
1035
  /**
1026
1036
  * The current persistence provider, undefined by default.
1027
1037
  * @internal
@@ -1058,7 +1068,7 @@ class MsalNode extends MsalBaseUtilities {
1058
1068
  this.requiresConfidential = false;
1059
1069
  this.msalConfig = this.defaultNodeMsalConfig(options);
1060
1070
  this.tenantId = resolveTenantId(options.logger, options.tenantId, options.clientId);
1061
- this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds((_a = options === null || options === void 0 ? void 0 : options.tokenCredentialOptions) === null || _a === void 0 ? void 0 : _a.additionallyAllowedTenants);
1071
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds((_a = options === null || options === void 0 ? void 0 : options.tokenCredentialOptions) === null || _a === void 0 ? void 0 : _a.additionallyAllowedTenants);
1062
1072
  this.clientId = this.msalConfig.auth.clientId;
1063
1073
  if (options === null || options === void 0 ? void 0 : options.getAssertion) {
1064
1074
  this.getAssertion = options.getAssertion;
@@ -1156,10 +1166,10 @@ class MsalNode extends MsalBaseUtilities {
1156
1166
  };
1157
1167
  }
1158
1168
  if (options === null || options === void 0 ? void 0 : options.enableCae) {
1159
- this.caeApp.public = new msalCommon__namespace.PublicClientApplication(this.msalConfig);
1169
+ this.caeApp.public = new msalNode__namespace.PublicClientApplication(this.msalConfig);
1160
1170
  }
1161
1171
  else {
1162
- this.app.public = new msalCommon__namespace.PublicClientApplication(this.msalConfig);
1172
+ this.app.public = new msalNode__namespace.PublicClientApplication(this.msalConfig);
1163
1173
  }
1164
1174
  if (this.getAssertion) {
1165
1175
  this.msalConfig.auth.clientAssertion = await this.getAssertion();
@@ -1169,10 +1179,10 @@ class MsalNode extends MsalBaseUtilities {
1169
1179
  this.msalConfig.auth.clientAssertion ||
1170
1180
  this.msalConfig.auth.clientCertificate) {
1171
1181
  if (options === null || options === void 0 ? void 0 : options.enableCae) {
1172
- this.caeApp.confidential = new msalCommon__namespace.ConfidentialClientApplication(this.msalConfig);
1182
+ this.caeApp.confidential = new msalNode__namespace.ConfidentialClientApplication(this.msalConfig);
1173
1183
  }
1174
1184
  else {
1175
- this.app.confidential = new msalCommon__namespace.ConfidentialClientApplication(this.msalConfig);
1185
+ this.app.confidential = new msalNode__namespace.ConfidentialClientApplication(this.msalConfig);
1176
1186
  }
1177
1187
  }
1178
1188
  else {
@@ -1303,7 +1313,6 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1303
1313
  }
1304
1314
 
1305
1315
  // Copyright (c) Microsoft Corporation.
1306
- // Licensed under the MIT license.
1307
1316
  const CommonTenantId = "common";
1308
1317
  const AzureAccountClientId = "aebc6443-996d-45c2-90f0-388ff96faa56"; // VSC: 'aebc6443-996d-45c2-90f0-388ff96faa56'
1309
1318
  const logger$m = credentialLogger("VisualStudioCodeCredential");
@@ -1338,10 +1347,10 @@ function getPropertyFromVSCode(property) {
1338
1347
  const settingsPath = ["User", "settings.json"];
1339
1348
  // Eventually we can add more folders for more versions of VSCode.
1340
1349
  const vsCodeFolder = "Code";
1341
- const homedir = os.homedir();
1350
+ const homedir = os__default["default"].homedir();
1342
1351
  function loadProperty(...pathSegments) {
1343
- const fullPath = path.join(...pathSegments, vsCodeFolder, ...settingsPath);
1344
- const settings = JSON.parse(fs.readFileSync(fullPath, { encoding: "utf8" }));
1352
+ const fullPath = path__default["default"].join(...pathSegments, vsCodeFolder, ...settingsPath);
1353
+ const settings = JSON.parse(fs__default["default"].readFileSync(fullPath, { encoding: "utf8" }));
1345
1354
  return settings[property];
1346
1355
  }
1347
1356
  try {
@@ -1398,7 +1407,7 @@ class VisualStudioCodeCredential {
1398
1407
  else {
1399
1408
  this.tenantId = CommonTenantId;
1400
1409
  }
1401
- this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
1410
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
1402
1411
  checkUnsupportedTenant(this.tenantId);
1403
1412
  }
1404
1413
  /**
@@ -1484,7 +1493,6 @@ class VisualStudioCodeCredential {
1484
1493
  }
1485
1494
 
1486
1495
  // Copyright (c) Microsoft Corporation.
1487
- // Licensed under the MIT license.
1488
1496
  /**
1489
1497
  * The context passed to an Identity plugin. This contains objects that
1490
1498
  * plugins can use to set backend implementations.
@@ -1526,7 +1534,6 @@ function useIdentityPlugin(plugin) {
1526
1534
  }
1527
1535
 
1528
1536
  // Copyright (c) Microsoft Corporation.
1529
- // Licensed under the MIT license.
1530
1537
  const msiName$6 = "ManagedIdentityCredential - AppServiceMSI 2017";
1531
1538
  const logger$l = credentialLogger(msiName$6);
1532
1539
  /**
@@ -1594,7 +1601,6 @@ const appServiceMsi2017 = {
1594
1601
  };
1595
1602
 
1596
1603
  // Copyright (c) Microsoft Corporation.
1597
- // Licensed under the MIT license.
1598
1604
  const msiName$5 = "ManagedIdentityCredential - CloudShellMSI";
1599
1605
  const logger$k = credentialLogger(msiName$5);
1600
1606
  /**
@@ -1666,7 +1672,6 @@ const cloudShellMsi = {
1666
1672
  };
1667
1673
 
1668
1674
  // Copyright (c) Microsoft Corporation.
1669
- // Licensed under the MIT license.
1670
1675
  const msiName$4 = "ManagedIdentityCredential - IMDS";
1671
1676
  const logger$j = credentialLogger(msiName$4);
1672
1677
  /**
@@ -1741,20 +1746,21 @@ const imdsMsi = {
1741
1746
  skipQuery: true,
1742
1747
  });
1743
1748
  return tracingClient.withSpan("ManagedIdentityCredential-pingImdsEndpoint", getTokenOptions, async (options) => {
1744
- var _a;
1749
+ var _a, _b;
1745
1750
  requestOptions.tracingOptions = options.tracingOptions;
1746
1751
  // Create a request with a timeout since we expect that
1747
1752
  // not having a "Metadata" header should cause an error to be
1748
1753
  // returned quickly from the endpoint, proving its availability.
1749
1754
  const request = coreRestPipeline.createPipelineRequest(requestOptions);
1750
- // Default to 300 if the default of 0 is used.
1755
+ // Default to 1000 if the default of 0 is used.
1751
1756
  // Negative values can still be used to disable the timeout.
1752
- request.timeout = ((_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.timeout) || 300;
1757
+ request.timeout = ((_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.timeout) || 1000;
1753
1758
  // This MSI uses the imdsEndpoint to get the token, which only uses http://
1754
1759
  request.allowInsecureConnection = true;
1760
+ let response;
1755
1761
  try {
1756
1762
  logger$j.info(`${msiName$4}: Pinging the Azure IMDS endpoint`);
1757
- await identityClient.sendRequest(request);
1763
+ response = await identityClient.sendRequest(request);
1758
1764
  }
1759
1765
  catch (err) {
1760
1766
  // If the request failed, or Node.js was unable to establish a connection,
@@ -1762,9 +1768,18 @@ const imdsMsi = {
1762
1768
  if (coreUtil.isError(err)) {
1763
1769
  logger$j.verbose(`${msiName$4}: Caught error ${err.name}: ${err.message}`);
1764
1770
  }
1771
+ // This is a special case for Docker Desktop which responds with a 403 with a message that contains "A socket operation was attempted to an unreachable network"
1772
+ // rather than just timing out, as expected.
1765
1773
  logger$j.info(`${msiName$4}: The Azure IMDS endpoint is unavailable`);
1766
1774
  return false;
1767
1775
  }
1776
+ if (response.status === 403) {
1777
+ if ((_b = response.bodyAsText) === null || _b === void 0 ? void 0 : _b.includes("A socket operation was attempted to an unreachable network")) {
1778
+ logger$j.info(`${msiName$4}: The Azure IMDS endpoint is unavailable`);
1779
+ logger$j.info(`${msiName$4}: ${response.bodyAsText}`);
1780
+ return false;
1781
+ }
1782
+ }
1768
1783
  // If we received any response, the endpoint is available
1769
1784
  logger$j.info(`${msiName$4}: The Azure IMDS endpoint is available`);
1770
1785
  return true;
@@ -1799,7 +1814,6 @@ const imdsMsi = {
1799
1814
  };
1800
1815
 
1801
1816
  // Copyright (c) Microsoft Corporation.
1802
- // Licensed under the MIT license.
1803
1817
  const msiName$3 = "ManagedIdentityCredential - Azure Arc MSI";
1804
1818
  const logger$i = credentialLogger(msiName$3);
1805
1819
  /**
@@ -1910,7 +1924,6 @@ const arcMsi = {
1910
1924
  };
1911
1925
 
1912
1926
  // Copyright (c) Microsoft Corporation.
1913
- // Licensed under the MIT license.
1914
1927
  /**
1915
1928
  * MSAL client assertion client. Calls to MSAL's confidential application's `acquireTokenByClientCredential` during `doGetToken`.
1916
1929
  * @internal
@@ -1950,7 +1963,6 @@ class MsalClientAssertion extends MsalNode {
1950
1963
  }
1951
1964
 
1952
1965
  // Copyright (c) Microsoft Corporation.
1953
- // Licensed under the MIT license.
1954
1966
  const logger$h = credentialLogger("ClientAssertionCredential");
1955
1967
  /**
1956
1968
  * Authenticates a service principal with a JWT assertion.
@@ -1971,7 +1983,7 @@ class ClientAssertionCredential {
1971
1983
  throw new Error("ClientAssertionCredential: tenantId, clientId, and clientAssertion are required parameters.");
1972
1984
  }
1973
1985
  this.tenantId = tenantId;
1974
- this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
1986
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
1975
1987
  this.clientId = clientId;
1976
1988
  this.options = options;
1977
1989
  this.msalFlow = new MsalClientAssertion(Object.assign(Object.assign({}, options), { logger: logger$h, clientId: this.clientId, tenantId: this.tenantId, tokenCredentialOptions: this.options, getAssertion }));
@@ -1994,7 +2006,6 @@ class ClientAssertionCredential {
1994
2006
  }
1995
2007
 
1996
2008
  // Copyright (c) Microsoft Corporation.
1997
- // Licensed under the MIT license.
1998
2009
  const credentialName$3 = "WorkloadIdentityCredential";
1999
2010
  /**
2000
2011
  * Contains the list of all supported environment variable names so that an
@@ -2093,7 +2104,6 @@ class WorkloadIdentityCredential {
2093
2104
  }
2094
2105
 
2095
2106
  // Copyright (c) Microsoft Corporation.
2096
- // Licensed under the MIT license.
2097
2107
  const msiName$2 = "ManagedIdentityCredential - Token Exchange";
2098
2108
  const logger$f = credentialLogger(msiName$2);
2099
2109
  /**
@@ -2123,7 +2133,6 @@ function tokenExchangeMsi() {
2123
2133
  }
2124
2134
 
2125
2135
  // Copyright (c) Microsoft Corporation.
2126
- // Licensed under the MIT license.
2127
2136
  // This MSI can be easily tested by deploying a container to Azure Service Fabric with the Dockerfile:
2128
2137
  //
2129
2138
  // FROM node:12
@@ -2202,7 +2211,7 @@ const fabricMsi = {
2202
2211
  "IDENTITY_SERVER_THUMBPRINT=[REDACTED].",
2203
2212
  ].join(" "));
2204
2213
  const request = coreRestPipeline.createPipelineRequest(Object.assign({ abortSignal: getTokenOptions.abortSignal }, prepareRequestOptions$1(scopes, clientId, resourceId)));
2205
- request.agent = new https.Agent({
2214
+ request.agent = new https__default["default"].Agent({
2206
2215
  // This is necessary because Service Fabric provides a self-signed certificate.
2207
2216
  // The alternative path is to verify the certificate using the IDENTITY_SERVER_THUMBPRINT env variable.
2208
2217
  rejectUnauthorized: false,
@@ -2213,7 +2222,6 @@ const fabricMsi = {
2213
2222
  };
2214
2223
 
2215
2224
  // Copyright (c) Microsoft Corporation.
2216
- // Licensed under the MIT license.
2217
2225
  const msiName = "ManagedIdentityCredential - AppServiceMSI 2019";
2218
2226
  const logger$d = credentialLogger(msiName);
2219
2227
  /**
@@ -2281,7 +2289,6 @@ const appServiceMsi2019 = {
2281
2289
  };
2282
2290
 
2283
2291
  // Copyright (c) Microsoft Corporation.
2284
- // Licensed under the MIT license.
2285
2292
  const logger$c = credentialLogger("ManagedIdentityCredential");
2286
2293
  /**
2287
2294
  * Attempts authentication using a managed identity available at the deployment environment.
@@ -2289,7 +2296,7 @@ const logger$c = credentialLogger("ManagedIdentityCredential");
2289
2296
  * Azure Kubernetes Services, Azure Service Fabric instances and inside of the Azure Cloud Shell.
2290
2297
  *
2291
2298
  * More information about configuring managed identities can be found here:
2292
- * https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview
2299
+ * https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview
2293
2300
  */
2294
2301
  class ManagedIdentityCredential {
2295
2302
  /**
@@ -2321,9 +2328,8 @@ class ManagedIdentityCredential {
2321
2328
  /** authority host validation and metadata discovery to be skipped in managed identity
2322
2329
  * since this wasn't done previously before adding token cache support
2323
2330
  */
2324
- this.confidentialApp = new msalCommon.ConfidentialClientApplication({
2331
+ this.confidentialApp = new msalNode.ConfidentialClientApplication({
2325
2332
  auth: {
2326
- authority: "https://login.microsoftonline.com/managed_identity",
2327
2333
  clientId: (_a = this.clientId) !== null && _a !== void 0 ? _a : DeveloperSignOnClientId,
2328
2334
  clientSecret: "dummy-secret",
2329
2335
  cloudDiscoveryMetadata: '{"tenant_discovery_endpoint":"https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration","api-version":"1.1","metadata":[{"preferred_network":"login.microsoftonline.com","preferred_cache":"login.windows.net","aliases":["login.microsoftonline.com","login.windows.net","login.microsoft.com","sts.windows.net"]},{"preferred_network":"login.partner.microsoftonline.cn","preferred_cache":"login.partner.microsoftonline.cn","aliases":["login.partner.microsoftonline.cn","login.chinacloudapi.cn"]},{"preferred_network":"login.microsoftonline.de","preferred_cache":"login.microsoftonline.de","aliases":["login.microsoftonline.de"]},{"preferred_network":"login.microsoftonline.us","preferred_cache":"login.microsoftonline.us","aliases":["login.microsoftonline.us","login.usgovcloudapi.net"]},{"preferred_network":"login-us.microsoftonline.com","preferred_cache":"login-us.microsoftonline.com","aliases":["login-us.microsoftonline.com"]}]}',
@@ -2411,7 +2417,7 @@ class ManagedIdentityCredential {
2411
2417
  else {
2412
2418
  const appTokenParameters = {
2413
2419
  correlationId: this.identityClient.getCorrelationId(),
2414
- tenantId: (options === null || options === void 0 ? void 0 : options.tenantId) || "managed_identity",
2420
+ tenantId: (options === null || options === void 0 ? void 0 : options.tenantId) || "organizations",
2415
2421
  scopes: Array.isArray(scopes) ? scopes : [scopes],
2416
2422
  claims: options === null || options === void 0 ? void 0 : options.claims,
2417
2423
  };
@@ -2480,6 +2486,15 @@ class ManagedIdentityCredential {
2480
2486
  if (err.statusCode === 400) {
2481
2487
  throw new CredentialUnavailableError(`${ManagedIdentityCredential.name}: The managed identity endpoint is indicating there's no available identity. Message: ${err.message}`);
2482
2488
  }
2489
+ // This is a special case for Docker Desktop which responds with a 403 with a message that contains "A socket operation was attempted to an unreachable network"
2490
+ // rather than just timing out, as expected.
2491
+ if (err.statusCode === 403 || err.code === 403) {
2492
+ if (err.message.includes("A socket operation was attempted to an unreachable network")) {
2493
+ const error = new CredentialUnavailableError(`${ManagedIdentityCredential.name}: Unavailable. Network unreachable. Message: ${err.message}`);
2494
+ logger$c.getToken.info(formatError(scopes, error));
2495
+ throw error;
2496
+ }
2497
+ }
2483
2498
  // If the error has no status code, we can assume there was no available identity.
2484
2499
  // This will throw silently during any ChainedTokenCredential.
2485
2500
  if (err.statusCode === undefined) {
@@ -2563,7 +2578,6 @@ class ManagedIdentityCredential {
2563
2578
  }
2564
2579
 
2565
2580
  // Copyright (c) Microsoft Corporation.
2566
- // Licensed under the MIT license.
2567
2581
  /**
2568
2582
  * Ensures the scopes value is an array.
2569
2583
  * @internal
@@ -2576,7 +2590,7 @@ function ensureScopes(scopes) {
2576
2590
  * @internal
2577
2591
  */
2578
2592
  function ensureValidScopeForDevTimeCreds(scope, logger) {
2579
- if (!scope.match(/^[0-9a-zA-Z-.:/]+$/)) {
2593
+ if (!scope.match(/^[0-9a-zA-Z-_.:/]+$/)) {
2580
2594
  const error = new Error("Invalid scope was specified by the user or calling client");
2581
2595
  logger.getToken.info(formatError(scope, error));
2582
2596
  throw error;
@@ -2591,7 +2605,6 @@ function getScopeResource(scope) {
2591
2605
  }
2592
2606
 
2593
2607
  // Copyright (c) Microsoft Corporation.
2594
- // Licensed under the MIT license.
2595
2608
  /**
2596
2609
  * Mockable reference to the CLI credential cliCredentialFunctions
2597
2610
  * @internal
@@ -2623,7 +2636,7 @@ const cliCredentialInternals = {
2623
2636
  }
2624
2637
  return new Promise((resolve, reject) => {
2625
2638
  try {
2626
- child_process.execFile("az", [
2639
+ child_process__default["default"].execFile("az", [
2627
2640
  "account",
2628
2641
  "get-access-token",
2629
2642
  "--output",
@@ -2662,7 +2675,7 @@ class AzureCliCredential {
2662
2675
  checkTenantId(logger$b, options === null || options === void 0 ? void 0 : options.tenantId);
2663
2676
  this.tenantId = options === null || options === void 0 ? void 0 : options.tenantId;
2664
2677
  }
2665
- this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
2678
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
2666
2679
  this.timeout = options === null || options === void 0 ? void 0 : options.processTimeoutInMs;
2667
2680
  }
2668
2681
  /**
@@ -2728,7 +2741,6 @@ class AzureCliCredential {
2728
2741
  }
2729
2742
 
2730
2743
  // Copyright (c) Microsoft Corporation.
2731
- // Licensed under the MIT license.
2732
2744
  /**
2733
2745
  * Easy to mock childProcess utils.
2734
2746
  * @internal
@@ -2759,7 +2771,6 @@ const processUtils = {
2759
2771
  };
2760
2772
 
2761
2773
  // Copyright (c) Microsoft Corporation.
2762
- // Licensed under the MIT license.
2763
2774
  const logger$a = credentialLogger("AzurePowerShellCredential");
2764
2775
  const isWindows = process.platform === "win32";
2765
2776
  /**
@@ -2844,7 +2855,7 @@ class AzurePowerShellCredential {
2844
2855
  checkTenantId(logger$a, options === null || options === void 0 ? void 0 : options.tenantId);
2845
2856
  this.tenantId = options === null || options === void 0 ? void 0 : options.tenantId;
2846
2857
  }
2847
- this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
2858
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
2848
2859
  this.timeout = options === null || options === void 0 ? void 0 : options.processTimeoutInMs;
2849
2860
  }
2850
2861
  /**
@@ -2937,7 +2948,6 @@ class AzurePowerShellCredential {
2937
2948
  }
2938
2949
 
2939
2950
  // Copyright (c) Microsoft Corporation.
2940
- // Licensed under the MIT license.
2941
2951
  /**
2942
2952
  * @internal
2943
2953
  */
@@ -3016,7 +3026,6 @@ class ChainedTokenCredential {
3016
3026
  }
3017
3027
 
3018
3028
  // Copyright (c) Microsoft Corporation.
3019
- // Licensed under the MIT license.
3020
3029
  const readFileAsync = util.promisify(fs.readFile);
3021
3030
  /**
3022
3031
  * Tries to asynchronously load a certificate from the given path.
@@ -3122,7 +3131,6 @@ class MsalClientCertificate extends MsalNode {
3122
3131
  }
3123
3132
 
3124
3133
  // Copyright (c) Microsoft Corporation.
3125
- // Licensed under the MIT license.
3126
3134
  const credentialName$2 = "ClientCertificateCredential";
3127
3135
  const logger$8 = credentialLogger(credentialName$2);
3128
3136
  /**
@@ -3130,7 +3138,7 @@ const logger$8 = credentialLogger(credentialName$2);
3130
3138
  * certificate that is assigned to an App Registration. More information
3131
3139
  * on how to configure certificate authentication can be found here:
3132
3140
  *
3133
- * https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-certificate-credentials#register-your-certificate-with-azure-ad
3141
+ * https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-certificate-credentials#register-your-certificate-with-azure-ad
3134
3142
  *
3135
3143
  */
3136
3144
  class ClientCertificateCredential {
@@ -3139,7 +3147,7 @@ class ClientCertificateCredential {
3139
3147
  throw new Error(`${credentialName$2}: tenantId and clientId are required parameters.`);
3140
3148
  }
3141
3149
  this.tenantId = tenantId;
3142
- this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
3150
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
3143
3151
  const configuration = Object.assign({}, (typeof certificatePathOrConfiguration === "string"
3144
3152
  ? {
3145
3153
  certificatePath: certificatePathOrConfiguration,
@@ -3177,7 +3185,6 @@ class ClientCertificateCredential {
3177
3185
  }
3178
3186
 
3179
3187
  // Copyright (c) Microsoft Corporation.
3180
- // Licensed under the MIT license.
3181
3188
  /**
3182
3189
  * MSAL client secret client. Calls to MSAL's confidential application's `acquireTokenByClientCredential` during `doGetToken`.
3183
3190
  * @internal
@@ -3208,7 +3215,6 @@ class MsalClientSecret extends MsalNode {
3208
3215
  }
3209
3216
 
3210
3217
  // Copyright (c) Microsoft Corporation.
3211
- // Licensed under the MIT license.
3212
3218
  const logger$7 = credentialLogger("ClientSecretCredential");
3213
3219
  /**
3214
3220
  * Enables authentication to Azure Active Directory using a client secret
@@ -3234,7 +3240,7 @@ class ClientSecretCredential {
3234
3240
  throw new Error("ClientSecretCredential: tenantId, clientId, and clientSecret are required parameters. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.");
3235
3241
  }
3236
3242
  this.tenantId = tenantId;
3237
- this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
3243
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
3238
3244
  this.msalFlow = new MsalClientSecret(Object.assign(Object.assign({}, options), { logger: logger$7,
3239
3245
  clientId,
3240
3246
  tenantId,
@@ -3258,7 +3264,6 @@ class ClientSecretCredential {
3258
3264
  }
3259
3265
 
3260
3266
  // Copyright (c) Microsoft Corporation.
3261
- // Licensed under the MIT license.
3262
3267
  /**
3263
3268
  * MSAL username and password client. Calls to the MSAL's public application's `acquireTokenByUsernamePassword` during `doGetToken`.
3264
3269
  * @internal
@@ -3289,7 +3294,6 @@ class MsalUsernamePassword extends MsalNode {
3289
3294
  }
3290
3295
 
3291
3296
  // Copyright (c) Microsoft Corporation.
3292
- // Licensed under the MIT license.
3293
3297
  const logger$6 = credentialLogger("UsernamePasswordCredential");
3294
3298
  /**
3295
3299
  * Enables authentication to Azure Active Directory with a user's
@@ -3314,7 +3318,7 @@ class UsernamePasswordCredential {
3314
3318
  throw new Error("UsernamePasswordCredential: tenantId, clientId, username and password are required parameters. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.");
3315
3319
  }
3316
3320
  this.tenantId = tenantId;
3317
- this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
3321
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
3318
3322
  this.msalFlow = new MsalUsernamePassword(Object.assign(Object.assign({}, options), { logger: logger$6,
3319
3323
  clientId,
3320
3324
  tenantId,
@@ -3343,7 +3347,6 @@ class UsernamePasswordCredential {
3343
3347
  }
3344
3348
 
3345
3349
  // Copyright (c) Microsoft Corporation.
3346
- // Licensed under the MIT license.
3347
3350
  /**
3348
3351
  * Contains the list of all supported environment variable names so that an
3349
3352
  * appropriate error message can be generated when no credentials can be
@@ -3456,7 +3459,6 @@ class EnvironmentCredential {
3456
3459
  }
3457
3460
 
3458
3461
  // Copyright (c) Microsoft Corporation.
3459
- // Licensed under the MIT license.
3460
3462
  /**
3461
3463
  * Mockable reference to the Developer CLI credential cliCredentialFunctions
3462
3464
  * @internal
@@ -3488,7 +3490,7 @@ const developerCliCredentialInternals = {
3488
3490
  }
3489
3491
  return new Promise((resolve, reject) => {
3490
3492
  try {
3491
- child_process.execFile("azd", [
3493
+ child_process__default["default"].execFile("azd", [
3492
3494
  "auth",
3493
3495
  "token",
3494
3496
  "--output",
@@ -3548,7 +3550,7 @@ class AzureDeveloperCliCredential {
3548
3550
  checkTenantId(logger$4, options === null || options === void 0 ? void 0 : options.tenantId);
3549
3551
  this.tenantId = options === null || options === void 0 ? void 0 : options.tenantId;
3550
3552
  }
3551
- this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
3553
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
3552
3554
  this.timeout = options === null || options === void 0 ? void 0 : options.processTimeoutInMs;
3553
3555
  }
3554
3556
  /**
@@ -3620,7 +3622,6 @@ class AzureDeveloperCliCredential {
3620
3622
  }
3621
3623
 
3622
3624
  // Copyright (c) Microsoft Corporation.
3623
- // Licensed under the MIT license.
3624
3625
  /**
3625
3626
  * A shim around ManagedIdentityCredential that adapts it to accept
3626
3627
  * `DefaultAzureCredentialOptions`.
@@ -3717,13 +3718,12 @@ class DefaultAzureCredential extends ChainedTokenCredential {
3717
3718
  }
3718
3719
 
3719
3720
  // Copyright (c) Microsoft Corporation.
3720
- // Licensed under the MIT license.
3721
3721
  /**
3722
3722
  * A call to open(), but mockable
3723
3723
  * @internal
3724
3724
  */
3725
3725
  const interactiveBrowserMockable = {
3726
- open,
3726
+ open: open__default["default"],
3727
3727
  };
3728
3728
  /**
3729
3729
  * This MSAL client sets up a web server to listen for redirect callbacks, then calls to the MSAL's public application's `acquireTokenByDeviceCode` during `doGetToken`
@@ -3733,31 +3733,151 @@ const interactiveBrowserMockable = {
3733
3733
  class MsalOpenBrowser extends MsalNode {
3734
3734
  constructor(options) {
3735
3735
  super(options);
3736
- this.loginHint = options.loginHint;
3737
3736
  this.logger = credentialLogger("Node.js MSAL Open Browser");
3737
+ this.redirectUri = options.redirectUri;
3738
+ this.loginHint = options.loginHint;
3739
+ const url = new URL(this.redirectUri);
3740
+ this.port = parseInt(url.port);
3741
+ if (isNaN(this.port)) {
3742
+ this.port = 80;
3743
+ }
3744
+ this.hostname = url.hostname;
3738
3745
  }
3739
- async doGetToken(scopes, options) {
3740
- try {
3741
- const result = await this.getApp("public", options === null || options === void 0 ? void 0 : options.enableCae).acquireTokenInteractive({
3742
- openBrowser: async (url) => {
3743
- await interactiveBrowserMockable.open(url, { wait: true, newInstance: true });
3744
- },
3745
- scopes,
3746
- authority: options === null || options === void 0 ? void 0 : options.authority,
3747
- claims: options === null || options === void 0 ? void 0 : options.claims,
3748
- correlationId: options === null || options === void 0 ? void 0 : options.correlationId,
3749
- loginHint: this.loginHint,
3746
+ async acquireTokenByCode(request, enableCae) {
3747
+ return this.getApp("public", enableCae).acquireTokenByCode(request);
3748
+ }
3749
+ doGetToken(scopes, options) {
3750
+ return new Promise((resolve, reject) => {
3751
+ const socketToDestroy = [];
3752
+ const requestListener = (req, res) => {
3753
+ var _a;
3754
+ if (!req.url) {
3755
+ reject(new Error(`Interactive Browser Authentication Error "Did not receive token with a valid expiration"`));
3756
+ return;
3757
+ }
3758
+ let url;
3759
+ try {
3760
+ url = new URL(req.url, this.redirectUri);
3761
+ }
3762
+ catch (e) {
3763
+ reject(new Error(`Interactive Browser Authentication Error "Did not receive token with a valid expiration"`));
3764
+ return;
3765
+ }
3766
+ const tokenRequest = {
3767
+ code: url.searchParams.get("code"),
3768
+ redirectUri: this.redirectUri,
3769
+ scopes: scopes,
3770
+ authority: options === null || options === void 0 ? void 0 : options.authority,
3771
+ codeVerifier: (_a = this.pkceCodes) === null || _a === void 0 ? void 0 : _a.verifier,
3772
+ };
3773
+ this.acquireTokenByCode(tokenRequest, options === null || options === void 0 ? void 0 : options.enableCae)
3774
+ .then((authResponse) => {
3775
+ if (authResponse === null || authResponse === void 0 ? void 0 : authResponse.account) {
3776
+ this.account = msalToPublic(this.clientId, authResponse.account);
3777
+ }
3778
+ const successMessage = `Authentication Complete. You can close the browser and return to the application.`;
3779
+ if (authResponse && authResponse.expiresOn) {
3780
+ const expiresOnTimestamp = authResponse === null || authResponse === void 0 ? void 0 : authResponse.expiresOn.valueOf();
3781
+ res.writeHead(200);
3782
+ res.end(successMessage);
3783
+ this.logger.getToken.info(formatSuccess(scopes));
3784
+ resolve({
3785
+ expiresOnTimestamp,
3786
+ token: authResponse.accessToken,
3787
+ });
3788
+ }
3789
+ else {
3790
+ const errorMessage = formatError(scopes, `${url.searchParams.get("error")}. ${url.searchParams.get("error_description")}`);
3791
+ res.writeHead(500);
3792
+ res.end(errorMessage);
3793
+ this.logger.getToken.info(errorMessage);
3794
+ reject(new Error(`Interactive Browser Authentication Error "Did not receive token with a valid expiration"`));
3795
+ }
3796
+ cleanup();
3797
+ return;
3798
+ })
3799
+ .catch(() => {
3800
+ const errorMessage = formatError(scopes, `${url.searchParams.get("error")}. ${url.searchParams.get("error_description")}`);
3801
+ res.writeHead(500);
3802
+ res.end(errorMessage);
3803
+ this.logger.getToken.info(errorMessage);
3804
+ reject(new Error(`Interactive Browser Authentication Error "Did not receive token with a valid expiration"`));
3805
+ cleanup();
3806
+ });
3807
+ };
3808
+ const app = http__default["default"].createServer(requestListener);
3809
+ const server = stoppable__default["default"](app);
3810
+ const listen = app.listen(this.port, this.hostname, () => this.logger.info(`InteractiveBrowserCredential listening on port ${this.port}!`));
3811
+ function cleanup() {
3812
+ if (listen) {
3813
+ listen.close();
3814
+ }
3815
+ for (const socket of socketToDestroy) {
3816
+ socket.destroy();
3817
+ }
3818
+ if (server) {
3819
+ server.close();
3820
+ server.stop();
3821
+ }
3822
+ }
3823
+ app.on("connection", (socket) => socketToDestroy.push(socket));
3824
+ app.on("error", (err) => {
3825
+ cleanup();
3826
+ const code = err.code;
3827
+ if (code === "EACCES" || code === "EADDRINUSE") {
3828
+ reject(new CredentialUnavailableError([
3829
+ `InteractiveBrowserCredential: Access denied to port ${this.port}.`,
3830
+ `Try sending a redirect URI with a different port, as follows:`,
3831
+ '`new InteractiveBrowserCredential({ redirectUri: "http://localhost:1337" })`',
3832
+ ].join(" ")));
3833
+ }
3834
+ else {
3835
+ reject(new CredentialUnavailableError(`InteractiveBrowserCredential: Failed to start the necessary web server. Error: ${err.message}`));
3836
+ }
3750
3837
  });
3751
- return this.handleResult(scopes, this.clientId, result || undefined);
3838
+ app.on("listening", () => {
3839
+ const openPromise = this.openAuthCodeUrl(scopes, options);
3840
+ const abortSignal = options === null || options === void 0 ? void 0 : options.abortSignal;
3841
+ if (abortSignal) {
3842
+ abortSignal.addEventListener("abort", () => {
3843
+ cleanup();
3844
+ reject(new Error("Aborted"));
3845
+ });
3846
+ }
3847
+ openPromise.catch((e) => {
3848
+ cleanup();
3849
+ reject(e);
3850
+ });
3851
+ });
3852
+ });
3853
+ }
3854
+ async openAuthCodeUrl(scopeArray, options) {
3855
+ // Initialize CryptoProvider instance
3856
+ const cryptoProvider = new msalNode__namespace.CryptoProvider();
3857
+ // Generate PKCE Codes before starting the authorization flow
3858
+ this.pkceCodes = await cryptoProvider.generatePkceCodes();
3859
+ const authCodeUrlParameters = {
3860
+ scopes: scopeArray,
3861
+ correlationId: options === null || options === void 0 ? void 0 : options.correlationId,
3862
+ redirectUri: this.redirectUri,
3863
+ authority: options === null || options === void 0 ? void 0 : options.authority,
3864
+ claims: options === null || options === void 0 ? void 0 : options.claims,
3865
+ loginHint: this.loginHint,
3866
+ codeChallenge: this.pkceCodes.challenge,
3867
+ codeChallengeMethod: "S256", // Use SHA256 Algorithm
3868
+ };
3869
+ const response = await this.getApp("public", options === null || options === void 0 ? void 0 : options.enableCae).getAuthCodeUrl(authCodeUrlParameters);
3870
+ try {
3871
+ // A new instance on macOS only which allows it to not hang, does not fix the issue on linux
3872
+ await interactiveBrowserMockable.open(response, { wait: true, newInstance: true });
3752
3873
  }
3753
- catch (err) {
3754
- throw this.handleError(scopes, err, options);
3874
+ catch (e) {
3875
+ throw new CredentialUnavailableError(`InteractiveBrowserCredential: Could not open a browser window. Error: ${e.message}`);
3755
3876
  }
3756
3877
  }
3757
3878
  }
3758
3879
 
3759
3880
  // Copyright (c) Microsoft Corporation.
3760
- // Licensed under the MIT license.
3761
3881
  const logger$3 = credentialLogger("InteractiveBrowserCredential");
3762
3882
  /**
3763
3883
  * Enables authentication to Azure Active Directory inside of the web browser
@@ -3781,7 +3901,7 @@ class InteractiveBrowserCredential {
3781
3901
  ? options.redirectUri()
3782
3902
  : options.redirectUri || "http://localhost";
3783
3903
  this.tenantId = options === null || options === void 0 ? void 0 : options.tenantId;
3784
- this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
3904
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
3785
3905
  this.msalFlow = new MsalOpenBrowser(Object.assign(Object.assign({}, options), { tokenCredentialOptions: options, logger: logger$3,
3786
3906
  redirectUri }));
3787
3907
  this.disableAutomaticAuthentication = options === null || options === void 0 ? void 0 : options.disableAutomaticAuthentication;
@@ -3828,7 +3948,6 @@ class InteractiveBrowserCredential {
3828
3948
  }
3829
3949
 
3830
3950
  // Copyright (c) Microsoft Corporation.
3831
- // Licensed under the MIT license.
3832
3951
  /**
3833
3952
  * MSAL device code client. Calls to the MSAL's public application's `acquireTokenByDeviceCode` during `doGetToken`.
3834
3953
  * @internal
@@ -3861,7 +3980,6 @@ class MsalDeviceCode extends MsalNode {
3861
3980
  }
3862
3981
 
3863
3982
  // Copyright (c) Microsoft Corporation.
3864
- // Licensed under the MIT license.
3865
3983
  const logger$2 = credentialLogger("DeviceCodeCredential");
3866
3984
  /**
3867
3985
  * Method that logs the user code from the DeviceCodeCredential.
@@ -3897,7 +4015,7 @@ class DeviceCodeCredential {
3897
4015
  */
3898
4016
  constructor(options) {
3899
4017
  this.tenantId = options === null || options === void 0 ? void 0 : options.tenantId;
3900
- this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
4018
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
3901
4019
  this.msalFlow = new MsalDeviceCode(Object.assign(Object.assign({}, options), { logger: logger$2, userPromptCallback: (options === null || options === void 0 ? void 0 : options.userPromptCallback) || defaultDeviceCodePromptCallback, tokenCredentialOptions: options || {} }));
3902
4020
  this.disableAutomaticAuthentication = options === null || options === void 0 ? void 0 : options.disableAutomaticAuthentication;
3903
4021
  }
@@ -3940,7 +4058,6 @@ class DeviceCodeCredential {
3940
4058
  }
3941
4059
 
3942
4060
  // Copyright (c) Microsoft Corporation.
3943
- // Licensed under the MIT license.
3944
4061
  /**
3945
4062
  * This MSAL client sets up a web server to listen for redirect callbacks, then calls to the MSAL's public application's `acquireTokenByDeviceCode` during `doGetToken`
3946
4063
  * to trigger the authentication flow, and then respond based on the values obtained from the redirect callback
@@ -3984,7 +4101,6 @@ class MsalAuthorizationCode extends MsalNode {
3984
4101
  }
3985
4102
 
3986
4103
  // Copyright (c) Microsoft Corporation.
3987
- // Licensed under the MIT license.
3988
4104
  const logger$1 = credentialLogger("AuthorizationCodeCredential");
3989
4105
  /**
3990
4106
  * Enables authentication to Azure Active Directory using an authorization code
@@ -4016,7 +4132,7 @@ class AuthorizationCodeCredential {
4016
4132
  }
4017
4133
  // TODO: Validate tenant if provided
4018
4134
  this.tenantId = tenantId;
4019
- this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
4135
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
4020
4136
  this.msalFlow = new MsalAuthorizationCode(Object.assign(Object.assign({}, options), { clientSecret,
4021
4137
  clientId,
4022
4138
  tenantId, tokenCredentialOptions: options || {}, logger: logger$1, redirectUri: this.redirectUri, authorizationCode: this.authorizationCode }));
@@ -4040,7 +4156,6 @@ class AuthorizationCodeCredential {
4040
4156
  }
4041
4157
 
4042
4158
  // Copyright (c) Microsoft Corporation.
4043
- // Licensed under the MIT license.
4044
4159
  /**
4045
4160
  * MSAL on behalf of flow. Calls to MSAL's confidential application's `acquireTokenOnBehalfOf` during `doGetToken`.
4046
4161
  * @internal
@@ -4094,11 +4209,10 @@ class MsalOnBehalfOf extends MsalNode {
4094
4209
  }
4095
4210
 
4096
4211
  // Copyright (c) Microsoft Corporation.
4097
- // Licensed under the MIT license.
4098
4212
  const credentialName = "OnBehalfOfCredential";
4099
4213
  const logger = credentialLogger(credentialName);
4100
4214
  /**
4101
- * Enables authentication to Azure Active Directory using the [On Behalf Of flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow).
4215
+ * Enables authentication to Microsoft Entra ID using the [On Behalf Of flow](https://learn.microsoft.com/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow).
4102
4216
  */
4103
4217
  class OnBehalfOfCredential {
4104
4218
  constructor(options) {
@@ -4110,7 +4224,7 @@ class OnBehalfOfCredential {
4110
4224
  throw new Error(`${credentialName}: tenantId, clientId, clientSecret (or certificatePath) and userAssertionToken are required parameters.`);
4111
4225
  }
4112
4226
  this.tenantId = tenantId;
4113
- this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(additionallyAllowedTenantIds);
4227
+ this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(additionallyAllowedTenantIds);
4114
4228
  this.msalFlow = new MsalOnBehalfOf(Object.assign(Object.assign({}, this.options), { logger, tokenCredentialOptions: this.options }));
4115
4229
  }
4116
4230
  /**
@@ -4130,7 +4244,6 @@ class OnBehalfOfCredential {
4130
4244
  }
4131
4245
 
4132
4246
  // Copyright (c) Microsoft Corporation.
4133
- // Licensed under the MIT license.
4134
4247
  /**
4135
4248
  * Returns a new instance of the {@link DefaultAzureCredential}.
4136
4249
  */