@azure/identity 2.1.0-alpha.20220414.1 → 2.1.0-alpha.20220421.1

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 (31) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +36 -8
  3. package/dist/index.js +26 -21
  4. package/dist/index.js.map +1 -1
  5. package/dist-esm/src/client/identityClient.js.map +1 -1
  6. package/dist-esm/src/credentials/authorizationCodeCredential.js +2 -1
  7. package/dist-esm/src/credentials/authorizationCodeCredential.js.map +1 -1
  8. package/dist-esm/src/credentials/azureCliCredential.js +22 -18
  9. package/dist-esm/src/credentials/azureCliCredential.js.map +1 -1
  10. package/dist-esm/src/credentials/azurePowerShellCredential.js.map +1 -1
  11. package/dist-esm/src/credentials/chainedTokenCredential.js.map +1 -1
  12. package/dist-esm/src/credentials/clientSecretCredential.browser.js.map +1 -1
  13. package/dist-esm/src/credentials/environmentCredential.js.map +1 -1
  14. package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js.map +1 -1
  15. package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
  16. package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
  17. package/dist-esm/src/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
  18. package/dist-esm/src/credentials/usernamePasswordCredential.browser.js.map +1 -1
  19. package/dist-esm/src/credentials/visualStudioCodeCredential.js.map +1 -1
  20. package/dist-esm/src/errors.js.map +1 -1
  21. package/dist-esm/src/msal/browserFlows/msalAuthCode.js.map +1 -1
  22. package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js +2 -2
  23. package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js.map +1 -1
  24. package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js.map +1 -1
  25. package/dist-esm/src/msal/nodeFlows/msalClientSecret.js.map +1 -1
  26. package/dist-esm/src/msal/nodeFlows/msalDeviceCode.js.map +1 -1
  27. package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js.map +1 -1
  28. package/dist-esm/src/msal/nodeFlows/msalOnBehalfOf.js.map +1 -1
  29. package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js.map +1 -1
  30. package/dist-esm/src/msal/nodeFlows/msalUsernamePassword.js.map +1 -1
  31. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -8,9 +8,14 @@
8
8
 
9
9
  ### Bugs Fixed
10
10
 
11
+ - Fixed a bug that would break the AzureCliCredential if the Azure CLI reported a warning. See: [21075](https://github.com/Azure/azure-sdk-for-js/issues/21075).
12
+ - Fixed a bug in `AuthorizationCodeCredential` where the tenant id was not being used. The `common` tenant was the only tenant being used by this credential.
13
+ - Fixed a bug in `AuthorizationCodeCredential` where the public client was not being used. Due to this bug, without passing in the client secret, this credential would fail.
14
+
11
15
  ### Other Changes
12
16
 
13
17
  - Upgraded to `@azure/core-tracing` version `^1.0.0`.
18
+ - Improved the errors displayed on the `AzureCliCredential`.
14
19
 
15
20
  ## 2.1.0-beta.2 (2022-03-22)
16
21
 
package/README.md CHANGED
@@ -120,12 +120,12 @@ If used from Node.js, the `DefaultAzureCredential` will attempt to authenticate
120
120
 
121
121
  ![DefaultAzureCredential authentication flow][defaultauthflow_image]
122
122
 
123
- - Environment - The `DefaultAzureCredential` will read account information specified via [environment variables](#environment-variables) and use it to authenticate.
124
- - Managed Identity - If the application is deployed to an Azure host with Managed Identity enabled, the `DefaultAzureCredential` will authenticate with that account.
125
- - Visual Studio Code - If the developer has authenticated with the [Visual Studio Code Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account), the `DefaultAzureCredential` will authenticate using that account.
126
- - In `@azure/identity` version 2.0 or later, the [`@azure/identity-vscode`](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity-vscode) package must be installed for the Visual Studio Code authentication to work.
127
- - Azure CLI - If the developer has authenticated an account via the Azure CLI `az login` command, the `DefaultAzureCredential` will authenticate with that account.
128
- - Azure PowerShell - If the developer has authenticated using the Azure PowerShell module `Connect-AzAccount` command, the `DefaultAzureCredential` will authenticate with that account.
123
+ 1. **Environment** - The `DefaultAzureCredential` will read account information specified via [environment variables](#environment-variables) and use it to authenticate.
124
+ 1. **Managed Identity** - If the application is deployed to an Azure host with Managed Identity enabled, the `DefaultAzureCredential` will authenticate with that account.
125
+ 1. **Visual Studio Code** - If the developer has authenticated with the [Visual Studio Code Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account), the `DefaultAzureCredential` will authenticate using that account.
126
+ - In `@azure/identity` version 2.0 or later, the [`@azure/identity-vscode`](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity-vscode) package must be installed for the Visual Studio Code authentication to work.
127
+ 1. **Azure CLI** - If the developer has authenticated an account via the Azure CLI `az login` command, the `DefaultAzureCredential` will authenticate with that account.
128
+ 1. **Azure PowerShell** - If the developer has authenticated using the Azure PowerShell module `Connect-AzAccount` command, the `DefaultAzureCredential` will authenticate with that account.
129
129
 
130
130
  ## Plugins
131
131
 
@@ -284,7 +284,10 @@ Credentials raise `AuthenticationError` when they fail to authenticate. This cla
284
284
 
285
285
  ### Logging
286
286
 
287
- Enabling logging may help uncover useful information about failures. To see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. You can read this environment variable from the *.env* file by explicitly specifying a file path:
287
+ Enabling logging may help uncover useful information about failures.
288
+
289
+ To see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`.
290
+ You can read this environment variable from the *.env* file by explicitly specifying a file path:
288
291
 
289
292
  ```javascript
290
293
  require("dotenv").config({ path: ".env" });
@@ -297,6 +300,31 @@ import { setLogLevel } from "@azure/logger";
297
300
 
298
301
  setLogLevel("info");
299
302
  ```
303
+
304
+ In cases where the authenticate code might be running in an environment with more than one credential available,
305
+ the `@azure/identity` package offers a unique form of logging. On the optional parameters for every credential,
306
+ developers can set `allowLoggingAccountIdentifiers` to true in the
307
+ `loggingOptions` to log information specific to the authenticated account after
308
+ each successful authentication, including the Client ID, the Tenant ID, the
309
+ Object ID of the authenticated user, and if possible the User Principal Name.
310
+
311
+ For example, using the `DefaultAzureCredential`:
312
+
313
+ ```js
314
+ import { setLogLevel } from "@azure/logger";
315
+
316
+ setLogLevel("info");
317
+
318
+ const credential = new DefaultAzureCredential({
319
+ loggingOptions: { allowLoggingAccountIdentifiers: true }
320
+ });
321
+ ```
322
+
323
+ Once that credential authenticates, the following message will appear in the logs (with the real information instead of `HIDDEN`):
324
+
325
+ ```
326
+ azure:identity:info [Authenticated account] Client ID: HIDDEN. Tenant ID: HIDDEN. User Principal Name: HIDDEN. Object ID (user): HIDDEN
327
+ ```
300
328
 
301
329
  For assistance with troubleshooting, see the [troubleshooting guide](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/TROUBLESHOOTING.md).
302
330
 
@@ -338,6 +366,6 @@ If you'd like to contribute to this library, please read the [contributing guide
338
366
  [azureclilogin_image]: https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/identity/identity/images/AzureCliLogin.png
339
367
  [azureclilogindevicecode_image]: https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/identity/identity/images/AzureCliLoginDeviceCode.png
340
368
  [azurepowershelllogin_image]: https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/identity/identity/images/AzurePowerShellLogin.png
341
- [defaultauthflow_image]: https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/identity/identity/images/DefaultAzureCredentialAuthenticationFlow.png
369
+ [defaultauthflow_image]: https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/identity/identity/images/mermaidjs/DefaultAzureCredentialAuthFlow.svg
342
370
 
343
371
  ![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fidentity%2Fidentity%2FREADME.png)
package/dist/index.js CHANGED
@@ -1541,29 +1541,25 @@ class AzureCliCredential {
1541
1541
  logger$h.getToken.info(`Using the scope ${scope}`);
1542
1542
  ensureValidScope(scope, logger$h);
1543
1543
  const resource = getScopeResource(scope);
1544
- let responseData = "";
1545
1544
  return tracingClient.withSpan(`${this.constructor.name}.getToken`, options, async () => {
1545
+ var _a, _b, _c, _d;
1546
1546
  try {
1547
1547
  const obj = await cliCredentialInternals.getAzureCliAccessToken(resource, tenantId);
1548
- if (obj.stderr) {
1549
- const isLoginError = obj.stderr.match("(.*)az login(.*)");
1550
- const isNotInstallError = obj.stderr.match("az:(.*)not found") || obj.stderr.startsWith("'az' is not recognized");
1551
- if (isNotInstallError) {
1552
- const error = new CredentialUnavailableError("Azure CLI could not be found. Please visit https://aka.ms/azure-cli for installation instructions and then, once installed, authenticate to your Azure account using 'az login'.");
1553
- logger$h.getToken.info(formatError(scopes, error));
1554
- throw error;
1555
- }
1556
- else if (isLoginError) {
1557
- const error = new CredentialUnavailableError("Please run 'az login' from a command prompt to authenticate before using this credential.");
1558
- logger$h.getToken.info(formatError(scopes, error));
1559
- throw error;
1560
- }
1561
- const error = new CredentialUnavailableError(obj.stderr);
1548
+ const specificScope = (_a = obj.stderr) === null || _a === void 0 ? void 0 : _a.match("(.*)az login --scope(.*)");
1549
+ const isLoginError = ((_b = obj.stderr) === null || _b === void 0 ? void 0 : _b.match("(.*)az login(.*)")) && !specificScope;
1550
+ const isNotInstallError = ((_c = obj.stderr) === null || _c === void 0 ? void 0 : _c.match("az:(.*)not found")) || ((_d = obj.stderr) === null || _d === void 0 ? void 0 : _d.startsWith("'az' is not recognized"));
1551
+ if (isNotInstallError) {
1552
+ const error = new CredentialUnavailableError("Azure CLI could not be found. Please visit https://aka.ms/azure-cli for installation instructions and then, once installed, authenticate to your Azure account using 'az login'.");
1562
1553
  logger$h.getToken.info(formatError(scopes, error));
1563
1554
  throw error;
1564
1555
  }
1565
- else {
1566
- responseData = obj.stdout;
1556
+ if (isLoginError) {
1557
+ const error = new CredentialUnavailableError("Please run 'az login' from a command prompt to authenticate before using this credential.");
1558
+ logger$h.getToken.info(formatError(scopes, error));
1559
+ throw error;
1560
+ }
1561
+ try {
1562
+ const responseData = obj.stdout;
1567
1563
  const response = JSON.parse(responseData);
1568
1564
  logger$h.getToken.info(formatSuccess(scopes));
1569
1565
  const returnValue = {
@@ -1572,9 +1568,17 @@ class AzureCliCredential {
1572
1568
  };
1573
1569
  return returnValue;
1574
1570
  }
1571
+ catch (e) {
1572
+ if (obj.stderr) {
1573
+ throw new CredentialUnavailableError(obj.stderr);
1574
+ }
1575
+ throw e;
1576
+ }
1575
1577
  }
1576
1578
  catch (err) {
1577
- const error = new Error(err.message || "Unknown error while trying to retrieve the access token");
1579
+ const error = err.name === "CredentialUnavailableError"
1580
+ ? err
1581
+ : new Error(err.message || "Unknown error while trying to retrieve the access token");
1578
1582
  logger$h.getToken.info(formatError(scopes, error));
1579
1583
  throw error;
1580
1584
  }
@@ -3440,12 +3444,12 @@ class MsalAuthorizationCode extends MsalNode {
3440
3444
  }
3441
3445
  async getAuthCodeUrl(options) {
3442
3446
  await this.init();
3443
- return this.confidentialApp.getAuthCodeUrl(options);
3447
+ return (this.confidentialApp || this.publicApp).getAuthCodeUrl(options);
3444
3448
  }
3445
3449
  async doGetToken(scopes, options) {
3446
3450
  var _a;
3447
3451
  try {
3448
- const result = await ((_a = this.confidentialApp) === null || _a === void 0 ? void 0 : _a.acquireTokenByCode({
3452
+ const result = await ((_a = (this.confidentialApp || this.publicApp)) === null || _a === void 0 ? void 0 : _a.acquireTokenByCode({
3449
3453
  scopes,
3450
3454
  redirectUri: this.redirectUri,
3451
3455
  code: this.authorizationCode,
@@ -3494,7 +3498,8 @@ class AuthorizationCodeCredential {
3494
3498
  options = redirectUriOrOptions;
3495
3499
  }
3496
3500
  this.msalFlow = new MsalAuthorizationCode(Object.assign(Object.assign({}, options), { clientSecret,
3497
- clientId, tokenCredentialOptions: options || {}, logger: logger$1, redirectUri: this.redirectUri, authorizationCode: this.authorizationCode }));
3501
+ clientId,
3502
+ tenantId, tokenCredentialOptions: options || {}, logger: logger$1, redirectUri: this.redirectUri, authorizationCode: this.authorizationCode }));
3498
3503
  }
3499
3504
  /**
3500
3505
  * Authenticates with Azure Active Directory and returns an access token if successful.