@azure/identity 2.0.0-alpha.20210930.2 → 2.0.0-alpha.20211007.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 (55) hide show
  1. package/CHANGELOG.md +106 -4
  2. package/README.md +4 -0
  3. package/dist/index.js +131 -113
  4. package/dist/index.js.map +1 -1
  5. package/dist-esm/src/client/identityClient.js +1 -1
  6. package/dist-esm/src/client/identityClient.js.map +1 -1
  7. package/dist-esm/src/credentials/applicationCredential.browser.js +6 -1
  8. package/dist-esm/src/credentials/applicationCredential.browser.js.map +1 -1
  9. package/dist-esm/src/credentials/applicationCredential.js +11 -9
  10. package/dist-esm/src/credentials/applicationCredential.js.map +1 -1
  11. package/dist-esm/src/credentials/authorizationCodeCredential.browser.js.map +1 -1
  12. package/dist-esm/src/credentials/azureCliCredential.browser.js +7 -0
  13. package/dist-esm/src/credentials/azureCliCredential.browser.js.map +1 -1
  14. package/dist-esm/src/credentials/azureCliCredential.js +6 -5
  15. package/dist-esm/src/credentials/azureCliCredential.js.map +1 -1
  16. package/dist-esm/src/credentials/azurePowerShellCredential.browser.js +3 -1
  17. package/dist-esm/src/credentials/azurePowerShellCredential.browser.js.map +1 -1
  18. package/dist-esm/src/credentials/azurePowerShellCredential.js +6 -6
  19. package/dist-esm/src/credentials/azurePowerShellCredential.js.map +1 -1
  20. package/dist-esm/src/credentials/clientCertificateCredential.browser.js +7 -0
  21. package/dist-esm/src/credentials/clientCertificateCredential.browser.js.map +1 -1
  22. package/dist-esm/src/credentials/clientCertificateCredentialOptions.js.map +1 -1
  23. package/dist-esm/src/credentials/clientSecretCredentialOptions.js.map +1 -1
  24. package/dist-esm/src/credentials/defaultAzureCredential.js +15 -11
  25. package/dist-esm/src/credentials/defaultAzureCredential.js.map +1 -1
  26. package/dist-esm/src/credentials/deviceCodeCredential.browser.js +7 -0
  27. package/dist-esm/src/credentials/deviceCodeCredential.browser.js.map +1 -1
  28. package/dist-esm/src/credentials/deviceCodeCredential.js +14 -0
  29. package/dist-esm/src/credentials/deviceCodeCredential.js.map +1 -1
  30. package/dist-esm/src/credentials/environmentCredential.browser.js +7 -0
  31. package/dist-esm/src/credentials/environmentCredential.browser.js.map +1 -1
  32. package/dist-esm/src/credentials/environmentCredential.js +1 -17
  33. package/dist-esm/src/credentials/environmentCredential.js.map +1 -1
  34. package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js +7 -7
  35. package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js.map +1 -1
  36. package/dist-esm/src/credentials/interactiveBrowserCredential.js +7 -7
  37. package/dist-esm/src/credentials/interactiveBrowserCredential.js.map +1 -1
  38. package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js +31 -22
  39. package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
  40. package/dist-esm/src/credentials/onBehalfOfCredential.browser.js +6 -0
  41. package/dist-esm/src/credentials/onBehalfOfCredential.browser.js.map +1 -1
  42. package/dist-esm/src/credentials/usernamePasswordCredential.js +0 -2
  43. package/dist-esm/src/credentials/usernamePasswordCredential.js.map +1 -1
  44. package/dist-esm/src/credentials/visualStudioCodeCredential.browser.js +6 -0
  45. package/dist-esm/src/credentials/visualStudioCodeCredential.browser.js.map +1 -1
  46. package/dist-esm/src/credentials/visualStudioCodeCredential.js +1 -1
  47. package/dist-esm/src/credentials/visualStudioCodeCredential.js.map +1 -1
  48. package/dist-esm/src/index.js +0 -1
  49. package/dist-esm/src/index.js.map +1 -1
  50. package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js +1 -1
  51. package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js.map +1 -1
  52. package/dist-esm/src/msal/nodeFlows/nodeCommon.js +1 -1
  53. package/dist-esm/src/msal/nodeFlows/nodeCommon.js.map +1 -1
  54. package/package.json +1 -1
  55. package/types/identity.d.ts +58 -177
package/CHANGELOG.md CHANGED
@@ -1,20 +1,122 @@
1
1
  # Release History
2
2
 
3
- ## 2.0.0-beta.7 (Unreleased)
3
+ ## 2.0.0 (2021-10-12)
4
+
5
+ After multiple beta releases over the past year, we're proud to announce the general availability of version 2 of the `@azure/identity` package. This version includes the best parts of v1, plus several improvements.
6
+
7
+ This changelog entry showcases the changes that have been made from version 1 of this package. See the [v1-to-v2 migration guide](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/migration-v1-v2.md) for details on how to upgrade your application to use the version 2 of `@azure/identity`.
4
8
 
5
9
  ### Features Added
6
10
 
7
- ### Breaking Changes
11
+ #### Plugin API
12
+
13
+ Identity v2 provides a top-level `useIdentityPlugin` function, which allows using two new plugin packages:
14
+
15
+ - [@azure/identity-vscode](https://www.npmjs.com/package/@azure/identity-vscode), which provides the dependencies of `VisualStudioCodeCredential` and enables it.
16
+ - If the `@azure/identity-vscode` plugin isn't used through the `useIdentityPlugin` function, the `VisualStudioCodeCredential` exposed by Identity v2 will throw a `CredentialUnavailableError`.
17
+ - [@azure/identity-cache-persistence](https://www.npmjs.com/package/@azure/identity-cache-persistence), which provides persistent token caching.
18
+
19
+ Most credentials on Identity v2 now support the persistent token caching feature. Such credentials include the property [tokenCachePersistenceOptions](https://docs.microsoft.com/javascript/api/@azure/identity/tokencachepersistenceoptions) in the constructor options which can be used to enable this feature.
20
+
21
+ The following example showcases how to enable persistence caching by first enabling the `@azure/identity-cache-persistence` plugin with `useIdentityPlugin(cachePersistencePlugin)`, and then passing the `tokenCachePersistenceOptions` through the constructor of the `DeviceCodeCredential`:
22
+
23
+ ```ts
24
+ import { cachePersistencePlugin } from "@azure/identity-cache-persistence";
25
+ import { useIdentityPlugin, DeviceCodeCredential } from "@azure/identity";
26
+
27
+ useIdentityPlugin(cachePersistencePlugin);
28
+
29
+ async function main() {
30
+ const credential = new DeviceCodeCredential({
31
+ tokenCachePersistenceOptions: {
32
+ enabled: true
33
+ }
34
+ });
35
+ }
36
+ ```
37
+
38
+ #### New credentials
39
+
40
+ Identity v2 includes three new credential types:
41
+
42
+ - `AzurePowerShellCredential`, which re-uses any account previously authenticated with the `Az.Account` PowerShell module.
43
+ - `ApplicationCredential`, which is a simplified `DefaultAzureCredential` that only includes `EnvironmentCredential` and `ManagedIdentityCredential`.
44
+ - `OnBehalfOfCredential`, which enables the [On-Behalf-Of authentication flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow).
45
+
46
+ #### New features in all credentials
47
+
48
+ Identity v2 enables:
49
+
50
+ - Support for claims challenges resulting from [Continuous Access Enforcement (CAE)](https://docs.microsoft.com/azure/active-directory/conditional-access/concept-continuous-access-evaluation) and [Conditional Access authentication context](https://techcommunity.microsoft.com/t5/azure-active-directory-identity/granular-conditional-access-for-sensitive-data-and-actions/ba-p/1751775).
51
+ - By default, credentials of Identity v2 will produce tokens that can be used to trigger the challenge authentication flows. After these tokens expire, the next HTTP requests to Azure will fail, but the response will contain information to re-authenticate.
52
+ - To disable this behavior, set the environment variable `AZURE_IDENTITY_DISABLE_CP1` to any value. For more about claims challenges, see [Claims challenges, claims requests, and client capabilities](https://docs.microsoft.com/azure/active-directory/develop/claims-challenge).
53
+ - Support for multi-tenant authentication on all credentials except `ManagedIdentityCredential`.
54
+ - At the moment, applications needing multi-tenancy support will need to call to the credentials' `getToken` directly, sending the new `tenantId` property.
55
+ - A sample with more context will be provided in a future date.
56
+ - To disable it, set the environment variable `AZURE_IDENTITY_DISABLE_MULTITENANTAUTH`. For more about multitenancy, see [Identity management in multitenant apps](https://docs.microsoft.com/azure/architecture/multitenant-identity/).
57
+
58
+ #### New features in InteractiveBrowserCredential and DeviceCodeCredential
59
+
60
+ You can now control when the credential requests user input with the new `disableAutomaticAuthentication` option added to the options you pass to the credential constructors.
61
+
62
+ - When enabled, this option stops the `getToken()` method from requesting user input in case the credential is unable to authenticate silently.
63
+ - If `getToken()` fails to authenticate without user interaction, and `disableAutomaticAuthentication` has been set to true, a new error will be thrown: `AuthenticationRequired`. You may use this error to identify scenarios when manual authentication needs to be triggered (with `authenticate()`, as described in the next point).
64
+
65
+ A new method `authenticate()` is added to these credentials which is similar to `getToken()`, but it does not read the `disableAutomaticAuthentication` option described above.
66
+
67
+ - Use this to get an `AuthenticationRecord` which you can then use to create new credentials that will re-use the token information.
68
+ - The `AuthenticationRecord` object has a `serialize()` method that allows an authenticated account to be stored as a string and re-used in another credential at any time. Use the new helper function `deserializeAuthenticationRecord` to de-serialize this string.
69
+ - `authenticate()` might succeed and still return `undefined` if we're unable to pick just one account record from the cache. This might happen if the cache is being used by more than one credential, or if multiple users have authenticated using the same Client ID and Tenant ID. To ensure consistency on a program with many users, please keep track of the `AuthenticationRecord` and provide them in the constructors of the credentials on initialization.
70
+
71
+ Learn more via the below samples
72
+ - [Samples around controlling user interaction](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#control-user-interaction).
73
+ - [Samples around persisting user authentication data](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#persist-user-authentication-data).
74
+
75
+ #### New features in ManagedIdentityCredential
76
+
77
+ In Identity v2, the `ManagedIdentityCredential` retries with exponential back-off when a request for a token fails with a 404 status code. This change only applies to environments with available IMDS endpoints.
78
+
79
+ Azure Service Fabric support hasn't been added on the initial version 2 of Identity. Subscribe to [issue #12420](https://github.com/Azure/azure-sdk-for-js/issues/12420) for updates on this feature.
80
+
81
+ #### Other features
82
+
83
+ - The Node.js version of `InteractiveBrowserCredential` has [Proof Key for Code Exchange (PKCE)](https://datatracker.ietf.org/doc/html/rfc7636) enabled by default.
84
+ - `InteractiveBrowserCredential` has a new `loginHint` constructor option, which allows a username to be pre-selected for interactive logins.
85
+ - In `AzureCliCredential`, we allow specifying a `tenantId` in the parameters through the `AzureCliCredentialOptions`.
86
+ - A new error, named `AuthenticationRequiredError`, has been added. This error shows up when a credential fails to authenticate silently.
87
+ - Errors and logged exceptions may point to the new [troubleshooting guidelines](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/Troubleshooting.md).
88
+ - On all of the credentials we're providing, the initial authentication attempt in the lifetime of your app will include an additional request to first discover relevant endpoint metadata information from Azure.
89
+
90
+ ### Breaking changes
91
+
92
+ #### Breaking changes from v1
93
+
94
+ - For `ClientCertificateCredential` specifically, the validity of the PEM certificate is evaluated on `getToken` and not on the constructor.
95
+ - We have also renamed the error `CredentialUnavailable` to `CredentialUnavailableError`, to align with the naming convention used for error classes in the Azure SDKs in JavaScript.
96
+ - In v1 of Identity some `getToken` calls could resolve with `null` in the case the authentication request succeeded with a malformed output. In v2, issues with the `getToken` method will always throw errors.
97
+ - Breaking changes to InteractiveBrowserCredential
98
+ - The `InteractiveBrowserCredential` will use the [Auth Code Flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-auth-code-flow) with [PKCE](https://tools.ietf.org/html/rfc7636) rather than [Implicit Grant Flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-implicit-grant-flow) to better support browsers with enhanced security restrictions. Learn how to migrate in the [migration guide](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/migration-v1-v2.md). Read more about the latest `InteractiveBrowserCredential` [here](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/interactive-browser-credential.md).
99
+ - The default client ID used for `InteractiveBrowserCredential` was viable only in Node.js and not for the browser. Therefore, on v2 client ID is a required parameter when using this credential in browser apps.
100
+ - Identity v2 also removes the `postLogoutRedirectUri` from the options to the constructor for `InteractiveBrowserCredential`. This option wasn't being used. Instead of using this option, use MSAL directly. For more information, see [Authenticating with the @azure/msal-browser Public Client](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-with-the-azuremsal-browser-public-client).
101
+ - In Identity v2, `VisualStudioCodeCredential` throws a `CredentialUnavailableError` unless the new [@azure/identity-vscode](https://www.npmjs.com/package/@azure/identity-vscode) plugin is used.
8
102
 
9
103
  #### Breaking Changes from 2.0.0-beta.4
10
104
 
11
105
  - Removed the `allowMultiTenantAuthentication` option from all of the credentials. Multi-tenant authentication is now enabled by default. On Node.js, it can be disabled with the `AZURE_IDENTITY_DISABLE_MULTITENANTAUTH` environment variable.
12
-
106
+ - Removed support for specific Azure regions on `ClientSecretCredential` and `ClientCertificateCredential. This feature will be added back on the next beta.
13
107
 
14
108
  ### Bugs Fixed
15
109
 
110
+ - `ClientSecretCredential`, `ClientCertificateCredential`, and `UsernamePasswordCredential` throw if the required parameters aren't provided (even in JavaScript).
111
+ - Fixed a bug that caused `AzureCliCredential` to fail when a custom tenant ID was provided.
112
+ - Caught up with the bug fixes for Azure POD Identity that were implemented on version 1.5.1.
113
+
16
114
  ### Other Changes
17
115
 
116
+ Identity v2 no longer includes native dependencies (neither ordinary, peer, nor optional dependencies). Previous distributions of `@azure/identity` included an optional dependency on `keytar`, which caused issues for some users in restrictive environments.
117
+
118
+ Identity v2 for JavaScript now also depends on the latest available versions of `@azure/msal-common`, `@azure/msal-node`, and `@azure/msal-browser`. Our goal is to always be up-to-date with the MSAL versions.
119
+
18
120
  ## 2.0.0-beta.6 (2021-09-09)
19
121
 
20
122
  ### Features Added
@@ -172,7 +274,7 @@ This update marks the preview for the first major version update of the `@azure/
172
274
  - This feature uses DPAPI on Windows, it tries to use the Keychain on OSX and the Keyring on Linux.
173
275
  - To learn more on the usage, please refer to our docs on the `TokenCachePersistenceOptions` interface.
174
276
  - **IMPORTANT:** As part of this beta, this feature is only supported in Node 10, 12 and 14.
175
- - Changes to `InteractiveBrowserCredential`, `DeviceCodeCredential`, and `UsernamePasswordCredential`:
277
+ - Changes to `InteractiveBrowserCredential` and `DeviceCodeCredential`:
176
278
  - You can now control when the credential requests user input with the new `disableAutomaticAuthentication` option added to the options you pass to the credential constructors.
177
279
  - When enabled, this option stops the `getToken()` method from requesting user input in case the credential is unable to authenticate silently.
178
280
  - If `getToken()` fails to authenticate without user interaction, and `disableAutomaticAuthentication` has been set to true, a new error will be thrown: `AuthenticationRequired`. You may use this error to identify scenarios when manual authentication needs to be triggered (with `authenticate()`, as described in the next point).
package/README.md CHANGED
@@ -14,6 +14,10 @@ Key links:
14
14
 
15
15
  ## Getting started
16
16
 
17
+ ### Migrate from v1 to v2 of @azure/identity
18
+
19
+ If you're using v1 of `@azure/identity`, see the [migration guide](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/migration-v1-v2.md) to update to v2.
20
+
17
21
  ### Currently supported environments
18
22
 
19
23
  - [LTS versions of Node.js](https://nodejs.org/about/releases/)
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ var fs__default = _interopDefault(fs);
18
18
  var os = _interopDefault(require('os'));
19
19
  var path = _interopDefault(require('path'));
20
20
  var child_process = require('child_process');
21
+ var child_process__default = _interopDefault(child_process);
21
22
  var crypto = require('crypto');
22
23
  var util = require('util');
23
24
  var http = _interopDefault(require('http'));
@@ -315,7 +316,7 @@ function getIdentityClientAuthorityHost(options) {
315
316
  class IdentityClient extends coreClient.ServiceClient {
316
317
  constructor(options) {
317
318
  var _a;
318
- const packageDetails = `azsdk-js-identity/2.0.0-beta.7`;
319
+ const packageDetails = `azsdk-js-identity/2.0.0`;
319
320
  const userAgentPrefix = ((_a = options === null || options === void 0 ? void 0 : options.userAgentOptions) === null || _a === void 0 ? void 0 : _a.userAgentPrefix)
320
321
  ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
321
322
  : `${packageDetails}`;
@@ -738,6 +739,40 @@ function deserializeAuthenticationRecord(serializedRecord) {
738
739
  }
739
740
 
740
741
  // Copyright (c) Microsoft Corporation.
742
+ // Licensed under the MIT license.
743
+ /**
744
+ * @internal
745
+ */
746
+ const multiTenantDisabledErrorMessage = "A getToken request was attempted with a tenant different than the tenant configured at the initialization of the credential, but multi-tenant authentication has been disabled by the environment variable AZURE_IDENTITY_DISABLE_MULTITENANTAUTH.";
747
+ /**
748
+ * @internal
749
+ */
750
+ const multiTenantADFSErrorMessage = "A new tenant Id can't be assigned through the GetTokenOptions when a credential has been originally configured to use the tenant `adfs`.";
751
+ /**
752
+ * Of getToken contains a tenantId, this functions allows picking this tenantId as the appropriate for authentication,
753
+ * unless multitenant authentication has been disabled through the AZURE_IDENTITY_DISABLE_MULTITENANTAUTH (on Node.js),
754
+ * or unless the original tenant Id is `adfs`.
755
+ * @internal
756
+ */
757
+ function processMultiTenantRequest(tenantId, getTokenOptions) {
758
+ if (!(getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.tenantId)) {
759
+ return tenantId;
760
+ }
761
+ if (process.env.AZURE_IDENTITY_DISABLE_MULTITENANTAUTH) {
762
+ throw new Error(multiTenantDisabledErrorMessage);
763
+ }
764
+ if (tenantId === "adfs") {
765
+ throw new Error(multiTenantADFSErrorMessage);
766
+ }
767
+ return getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.tenantId;
768
+ }
769
+
770
+ // Copyright (c) Microsoft Corporation.
771
+ // Licensed under the MIT license.
772
+ /**
773
+ * Helps specify a regional authority, or "AutoDiscoverRegion" to auto-detect the region.
774
+ */
775
+ var RegionalAuthority;
741
776
  (function (RegionalAuthority) {
742
777
  /** Instructs MSAL to attempt to discover the region */
743
778
  RegionalAuthority["AutoDiscoverRegion"] = "AutoDiscoverRegion";
@@ -845,36 +880,7 @@ function deserializeAuthenticationRecord(serializedRecord) {
845
880
  RegionalAuthority["GovernmentUSDodEast"] = "usdodeast";
846
881
  /** Uses the {@link RegionalAuthority} for the Azure 'usdodcentral' region. */
847
882
  RegionalAuthority["GovernmentUSDodCentral"] = "usdodcentral";
848
- })(exports.RegionalAuthority || (exports.RegionalAuthority = {}));
849
-
850
- // Copyright (c) Microsoft Corporation.
851
- // Licensed under the MIT license.
852
- /**
853
- * @internal
854
- */
855
- const multiTenantDisabledErrorMessage = "A getToken request was attempted with a tenant different than the tenant configured at the initialization of the credential, but multi-tenant authentication has been disabled by the environment variable AZURE_IDENTITY_DISABLE_MULTITENANTAUTH.";
856
- /**
857
- * @internal
858
- */
859
- const multiTenantADFSErrorMessage = "A new tenant Id can't be assigned through the GetTokenOptions when a credential has been originally configured to use the tenant `adfs`.";
860
- /**
861
- * Of getToken contains a tenantId, this functions allows picking this tenantId as the appropriate for authentication,
862
- * unless multitenant authentication has been disabled through the AZURE_IDENTITY_DISABLE_MULTITENANTAUTH (on Node.js),
863
- * or unless the original tenant Id is `adfs`.
864
- * @internal
865
- */
866
- function processMultiTenantRequest(tenantId, getTokenOptions) {
867
- if (!(getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.tenantId)) {
868
- return tenantId;
869
- }
870
- if (process.env.AZURE_IDENTITY_DISABLE_MULTITENANTAUTH) {
871
- throw new Error(multiTenantDisabledErrorMessage);
872
- }
873
- if (tenantId === "adfs") {
874
- throw new Error(multiTenantADFSErrorMessage);
875
- }
876
- return getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.tenantId;
877
- }
883
+ })(RegionalAuthority || (RegionalAuthority = {}));
878
884
 
879
885
  // Copyright (c) Microsoft Corporation.
880
886
  /**
@@ -921,7 +927,7 @@ class MsalNode extends MsalBaseUtilities {
921
927
  ].join(" "));
922
928
  }
923
929
  this.azureRegion = (_c = options.regionalAuthority) !== null && _c !== void 0 ? _c : process.env.AZURE_REGIONAL_AUTHORITY_NAME;
924
- if (this.azureRegion === exports.RegionalAuthority.AutoDiscoverRegion) {
930
+ if (this.azureRegion === RegionalAuthority.AutoDiscoverRegion) {
925
931
  this.azureRegion = "AUTO_DISCOVER";
926
932
  }
927
933
  }
@@ -1141,7 +1147,7 @@ function getPropertyFromVSCode(property) {
1141
1147
  }
1142
1148
  }
1143
1149
  /**
1144
- * Connect to Azure using the credential provided by the VSCode extension 'Azure Account'.
1150
+ * Connects to Azure using the credential provided by the VSCode extension 'Azure Account'.
1145
1151
  * Once the user has logged in via the extension, this credential can share the same refresh token
1146
1152
  * that is cached by the extension.
1147
1153
  */
@@ -1428,14 +1434,14 @@ const cliCredentialInternals = {
1428
1434
  }
1429
1435
  return new Promise((resolve, reject) => {
1430
1436
  try {
1431
- child_process.execFile("az", [
1437
+ child_process__default.execFile("az", [
1432
1438
  "account",
1433
1439
  "get-access-token",
1434
1440
  "--output",
1435
1441
  "json",
1436
1442
  "--resource",
1437
- ...tenantSection,
1438
- resource
1443
+ resource,
1444
+ ...tenantSection
1439
1445
  ], { cwd: cliCredentialInternals.getSafeWorkingDir() }, (error, stdout, stderr) => {
1440
1446
  resolve({ stdout: stdout, stderr: stderr, error });
1441
1447
  });
@@ -1452,13 +1458,14 @@ const logger$3 = credentialLogger("AzureCliCredential");
1452
1458
  * via the Azure CLI ('az') commandline tool.
1453
1459
  * To do so, it will read the user access token and expire time
1454
1460
  * with Azure CLI command "az account get-access-token".
1455
- * To be able to use this credential, ensure that you have already logged
1456
- * in via the 'az' tool using the command "az login" from the commandline.
1457
1461
  */
1458
1462
  class AzureCliCredential {
1459
1463
  /**
1460
1464
  * Creates an instance of the {@link AzureCliCredential}.
1461
1465
  *
1466
+ * To use this credential, ensure that you have already logged
1467
+ * in via the 'az' tool using the command "az login" from the commandline.
1468
+ *
1462
1469
  * @param options - Options, to optionally allow multi-tenant requests.
1463
1470
  */
1464
1471
  constructor(options) {
@@ -1618,17 +1625,17 @@ if (isWindows) {
1618
1625
  * This credential will use the currently logged-in user information from the
1619
1626
  * Azure PowerShell module. To do so, it will read the user access token and
1620
1627
  * expire time with Azure PowerShell command `Get-AzAccessToken -ResourceUrl {ResourceScope}`
1621
- *
1622
- * To be able to use this credential:
1623
- * - Install the Azure Az PowerShell module with:
1624
- * `Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force`.
1625
- * - You have already logged in to Azure PowerShell using the command
1626
- * `Connect-AzAccount` from the command line.
1627
1628
  */
1628
1629
  class AzurePowerShellCredential {
1629
1630
  /**
1630
1631
  * Creates an instance of the {@link AzurePowershellCredential}.
1631
1632
  *
1633
+ * To use this credential:
1634
+ * - Install the Azure Az PowerShell module with:
1635
+ * `Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force`.
1636
+ * - You have already logged in to Azure PowerShell using the command
1637
+ * `Connect-AzAccount` from the command line.
1638
+ *
1632
1639
  * @param options - Options, to optionally allow multi-tenant requests.
1633
1640
  */
1634
1641
  constructor(options) {
@@ -1957,8 +1964,6 @@ const logger$7 = credentialLogger("UsernamePasswordCredential");
1957
1964
  * trust so you should only use it when other, more secure credential
1958
1965
  * types can't be used.
1959
1966
  */
1960
- // We'll be using InteractiveCredential as the base of this class, which requires us to support authenticate(),
1961
- // to reduce the number of times we send the password over the network.
1962
1967
  class UsernamePasswordCredential {
1963
1968
  /**
1964
1969
  * Creates an instance of the UsernamePasswordCredential with the details
@@ -2020,23 +2025,7 @@ const AllSupportedEnvironmentVariables = [
2020
2025
  const logger$8 = credentialLogger("EnvironmentCredential");
2021
2026
  /**
2022
2027
  * Enables authentication to Azure Active Directory using client secret
2023
- * details configured in the following environment variables:
2024
- *
2025
- * Required environment variables:
2026
- * - `AZURE_TENANT_ID`: The Azure Active Directory tenant (directory) ID.
2027
- * - `AZURE_CLIENT_ID`: The client (application) ID of an App Registration in the tenant.
2028
- *
2029
- * Environment variables used for client credential authentication:
2030
- * - `AZURE_CLIENT_SECRET`: A client secret that was generated for the App Registration.
2031
- * - `AZURE_CLIENT_CERTIFICATE_PATH`: The path to a PEM certificate to use during the authentication, instead of the client secret.
2032
- *
2033
- * Alternatively, users can provide environment variables for username and password authentication:
2034
- * - `AZURE_USERNAME`: Username to authenticate with.
2035
- * - `AZURE_PASSWORD`: Password to authenticate with.
2036
- *
2037
- * This credential ultimately uses a {@link ClientSecretCredential} to
2038
- * perform the authentication using these details. Please consult the
2039
- * documentation of that class for more details.
2028
+ * details configured in environment variables
2040
2029
  */
2041
2030
  class EnvironmentCredential {
2042
2031
  /**
@@ -2273,7 +2262,7 @@ function expiresInParser$2(requestBody) {
2273
2262
  if (requestBody.expires_on) {
2274
2263
  // Use the expires_on timestamp if it's available
2275
2264
  const expires = +requestBody.expires_on * 1000;
2276
- logger$b.info(`${msiName$2}: IMDS using expires_on: ${expires} (original value: ${requestBody.expires_on})`);
2265
+ logger$b.info(`${msiName$2}: Using expires_on: ${expires} (original value: ${requestBody.expires_on})`);
2277
2266
  return expires;
2278
2267
  }
2279
2268
  else {
@@ -2283,29 +2272,41 @@ function expiresInParser$2(requestBody) {
2283
2272
  return expires;
2284
2273
  }
2285
2274
  }
2286
- function prepareRequestOptions$2(scopes, clientId) {
2275
+ function prepareRequestOptions$2(scopes, clientId, options) {
2287
2276
  var _a;
2288
2277
  const resource = mapScopesToResource(scopes);
2289
2278
  if (!resource) {
2290
2279
  throw new Error(`${msiName$2}: Multiple scopes are not supported.`);
2291
2280
  }
2292
- const queryParameters = {
2293
- resource,
2294
- "api-version": imdsApiVersion
2295
- };
2296
- if (clientId) {
2297
- queryParameters.client_id = clientId;
2281
+ const { skipQuery, skipMetadataHeader } = options || {};
2282
+ let query = "";
2283
+ // Pod Identity will try to process this request even if the Metadata header is missing.
2284
+ // We can exclude the request query to ensure no IMDS endpoint tries to process the ping request.
2285
+ if (!skipQuery) {
2286
+ const queryParameters = {
2287
+ resource,
2288
+ "api-version": imdsApiVersion
2289
+ };
2290
+ if (clientId) {
2291
+ queryParameters.client_id = clientId;
2292
+ }
2293
+ const params = new URLSearchParams(queryParameters);
2294
+ query = `?${params.toString()}`;
2298
2295
  }
2299
- const params = new URLSearchParams(queryParameters);
2300
- const query = params.toString();
2301
2296
  const url = new URL(imdsEndpointPath, (_a = process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST) !== null && _a !== void 0 ? _a : imdsHost);
2297
+ const rawHeaders = {
2298
+ Accept: "application/json",
2299
+ Metadata: "true"
2300
+ };
2301
+ // Remove the Metadata header to invoke a request error from some IMDS endpoints.
2302
+ if (skipMetadataHeader) {
2303
+ delete rawHeaders.Metadata;
2304
+ }
2302
2305
  return {
2303
- url: `${url}?${query}`,
2306
+ // In this case, the `?` should be added in the "query" variable `skipQuery` is not set.
2307
+ url: `${url}${query}`,
2304
2308
  method: "GET",
2305
- headers: coreRestPipeline.createHttpHeaders({
2306
- Accept: "application/json",
2307
- Metadata: "true"
2308
- })
2309
+ headers: coreRestPipeline.createHttpHeaders(rawHeaders)
2309
2310
  };
2310
2311
  }
2311
2312
  // 800ms -> 1600ms -> 3200ms
@@ -2327,13 +2328,10 @@ const imdsMsi = {
2327
2328
  if (process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST) {
2328
2329
  return true;
2329
2330
  }
2330
- const requestOptions = prepareRequestOptions$2(resource, clientId);
2331
- // This will always be populated, but let's make TypeScript happy
2332
- if (requestOptions.headers) {
2333
- // Remove the Metadata header to invoke a request error from
2334
- // IMDS endpoint
2335
- requestOptions.headers.delete("Metadata");
2336
- }
2331
+ const requestOptions = prepareRequestOptions$2(resource, clientId, {
2332
+ skipMetadataHeader: true,
2333
+ skipQuery: true
2334
+ });
2337
2335
  requestOptions.tracingOptions = options.tracingOptions;
2338
2336
  try {
2339
2337
  // Create a request with a timeout since we expect that
@@ -2753,22 +2751,26 @@ const defaultCredentials = [
2753
2751
  ];
2754
2752
  /**
2755
2753
  * Provides a default {@link ChainedTokenCredential} configuration that should
2756
- * work for most applications that use the Azure SDK. The following credential
2757
- * types will be tried, in order:
2758
- *
2759
- * - {@link EnvironmentCredential}
2760
- * - {@link ManagedIdentityCredential}
2761
- * - {@link VisualStudioCodeCredential}
2762
- * - {@link AzureCliCredential}
2763
- * - {@link AzurePowerShellCredential}
2764
- *
2765
- * Consult the documentation of these credential types for more information
2766
- * on how they attempt authentication.
2754
+ * work for most applications that use the Azure SDK.
2767
2755
  */
2768
2756
  class DefaultAzureCredential extends ChainedTokenCredential {
2769
2757
  /**
2770
2758
  * Creates an instance of the DefaultAzureCredential class.
2771
2759
  *
2760
+ * This credential provides a default {@link ChainedTokenCredential} configuration that should
2761
+ * work for most applications that use the Azure SDK.
2762
+ *
2763
+ * The following credential types will be tried, in order:
2764
+ *
2765
+ * - {@link EnvironmentCredential}
2766
+ * - {@link ManagedIdentityCredential}
2767
+ * - {@link VisualStudioCodeCredential}
2768
+ * - {@link AzureCliCredential}
2769
+ * - {@link AzurePowerShellCredential}
2770
+ *
2771
+ * Consult the documentation of these credential types for more information
2772
+ * on how they attempt authentication.
2773
+ *
2772
2774
  * **Note**: `VisualStudioCodeCredential` is provided by a plugin package:
2773
2775
  * `@azure/identity-vscode`. If this package is not installed and registered
2774
2776
  * using the plugin API (`useIdentityPlugin`), then authentication using
@@ -2931,18 +2933,18 @@ const logger$f = credentialLogger("InteractiveBrowserCredential");
2931
2933
  /**
2932
2934
  * Enables authentication to Azure Active Directory inside of the web browser
2933
2935
  * using the interactive login flow.
2934
- *
2935
- * This credential uses the [Authorization Code Flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-auth-code-flow).
2936
- * On Node.js, it will open a browser window while it listens for a redirect response from the authentication service.
2937
- * On browsers, it authenticates via popups. The `loginStyle` optional parameter can be set to `redirect` to authenticate by redirecting the user to an Azure secure login page, which then will redirect the user back to the web application where the authentication started.
2938
- *
2939
- * For Node.js, if a `clientId` is provided, the Azure Active Directory application will need to be configured to have a "Mobile and desktop applications" redirect endpoint.
2940
- * Follow our guide on [setting up Redirect URIs for Desktop apps that calls to web APIs](https://docs.microsoft.com/azure/active-directory/develop/scenario-desktop-app-registration#redirect-uris).
2941
2936
  */
2942
2937
  class InteractiveBrowserCredential {
2943
2938
  /**
2944
2939
  * Creates an instance of InteractiveBrowserCredential with the details needed.
2945
2940
  *
2941
+ * This credential uses the [Authorization Code Flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-auth-code-flow).
2942
+ * On Node.js, it will open a browser window while it listens for a redirect response from the authentication service.
2943
+ * On browsers, it authenticates via popups. The `loginStyle` optional parameter can be set to `redirect` to authenticate by redirecting the user to an Azure secure login page, which then will redirect the user back to the web application where the authentication started.
2944
+ *
2945
+ * For Node.js, if a `clientId` is provided, the Azure Active Directory application will need to be configured to have a "Mobile and desktop applications" redirect endpoint.
2946
+ * Follow our guide on [setting up Redirect URIs for Desktop apps that calls to web APIs](https://docs.microsoft.com/azure/active-directory/develop/scenario-desktop-app-registration#redirect-uris).
2947
+ *
2946
2948
  * @param options - Options for configuring the client which makes the authentication requests.
2947
2949
  */
2948
2950
  constructor(options = {}) {
@@ -3044,6 +3046,20 @@ class DeviceCodeCredential {
3044
3046
  * Creates an instance of DeviceCodeCredential with the details needed
3045
3047
  * to initiate the device code authorization flow with Azure Active Directory.
3046
3048
  *
3049
+ * A message will be logged, giving users a code that they can use to authenticate once they go to https://microsoft.com/devicelogin
3050
+ *
3051
+ * Developers can configure how this message is shown by passing a custom `userPromptCallback`:
3052
+ *
3053
+ * ```js
3054
+ * const credential = new DeviceCodeCredential({
3055
+ * tenantId: env.AZURE_TENANT_ID,
3056
+ * clientId: env.AZURE_CLIENT_ID,
3057
+ * userPromptCallback: (info) => {
3058
+ * console.log("CUSTOMIZED PROMPT CALLBACK", info.message);
3059
+ * }
3060
+ * });
3061
+ * ```
3062
+ *
3047
3063
  * @param options - Options for configuring the client which makes the authentication requests.
3048
3064
  */
3049
3065
  constructor(options) {
@@ -3096,7 +3112,7 @@ class DeviceCodeCredential {
3096
3112
  class MsalAuthorizationCode extends MsalNode {
3097
3113
  constructor(options) {
3098
3114
  super(options);
3099
- this.logger = credentialLogger("NodeJS MSAL Authorization Code");
3115
+ this.logger = credentialLogger("Node.js MSAL Authorization Code");
3100
3116
  this.redirectUri = options.redirectUri;
3101
3117
  this.authorizationCode = options.authorizationCode;
3102
3118
  if (options.clientSecret) {
@@ -3181,20 +3197,22 @@ const ApplicationCredentials = [
3181
3197
  ];
3182
3198
  /**
3183
3199
  * Provides a default {@link ChainedTokenCredential} configuration that should
3184
- * work for most applications that use the Azure SDK. The following credential
3185
- * types will be tried, in order:
3186
- *
3187
- * - {@link EnvironmentCredential}
3188
- * - {@link ManagedIdentityCredential}
3189
-
3190
- *
3191
- * Consult the documentation of these credential types for more information
3192
- * on how they attempt authentication.
3200
+ * work for most applications that use the Azure SDK.
3193
3201
  */
3194
3202
  class ApplicationCredential extends ChainedTokenCredential {
3195
3203
  /**
3196
3204
  * Creates an instance of the ApplicationCredential class.
3197
3205
  *
3206
+ * The ApplicationCredential provides a default {@link ChainedTokenCredential} configuration that should
3207
+ * work for most applications that use the Azure SDK. The following credential
3208
+ * types will be tried, in order:
3209
+ *
3210
+ * - {@link EnvironmentCredential}
3211
+ * - {@link ManagedIdentityCredential}
3212
+ *
3213
+ * Consult the documentation of these credential types for more information
3214
+ * on how they attempt authentication.
3215
+ *
3198
3216
  * @param options - Optional parameters. See {@link ApplicationCredentialOptions}.
3199
3217
  */
3200
3218
  constructor(options) {