@azure/identity 3.2.0-beta.2 → 3.2.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 (26) hide show
  1. package/README.md +11 -3
  2. package/dist/index.js +60 -28
  3. package/dist/index.js.map +1 -1
  4. package/dist-esm/src/constants.js +1 -1
  5. package/dist-esm/src/constants.js.map +1 -1
  6. package/dist-esm/src/credentials/authorityValidationOptions.js.map +1 -1
  7. package/dist-esm/src/credentials/azureCliCredentialOptions.js.map +1 -1
  8. package/dist-esm/src/credentials/azureDeveloperCliCredential.js +31 -11
  9. package/dist-esm/src/credentials/azureDeveloperCliCredential.js.map +1 -1
  10. package/dist-esm/src/credentials/azureDeveloperCliCredentialOptions.js.map +1 -1
  11. package/dist-esm/src/credentials/azurePowerShellCredentialOptions.js.map +1 -1
  12. package/dist-esm/src/credentials/chainedTokenCredential.js +8 -4
  13. package/dist-esm/src/credentials/chainedTokenCredential.js.map +1 -1
  14. package/dist-esm/src/credentials/clientAssertionCredential.js.map +1 -1
  15. package/dist-esm/src/credentials/defaultAzureCredential.js +4 -4
  16. package/dist-esm/src/credentials/defaultAzureCredential.js.map +1 -1
  17. package/dist-esm/src/credentials/defaultAzureCredentialOptions.js.map +1 -1
  18. package/dist-esm/src/credentials/interactiveBrowserCredentialOptions.js.map +1 -1
  19. package/dist-esm/src/credentials/managedIdentityCredential/tokenExchangeMsi.js +1 -1
  20. package/dist-esm/src/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
  21. package/dist-esm/src/credentials/usernamePasswordCredentialOptions.js.map +1 -1
  22. package/dist-esm/src/credentials/workloadIdentityCredential.js +15 -7
  23. package/dist-esm/src/credentials/workloadIdentityCredential.js.map +1 -1
  24. package/dist-esm/src/credentials/workloadIdentityCredentialOptions.js.map +1 -1
  25. package/package.json +2 -2
  26. package/types/identity.d.ts +51 -18
package/README.md CHANGED
@@ -68,9 +68,9 @@ While we recommend using managed identity or service principal authentication in
68
68
 
69
69
  Developers coding outside of an IDE can also use the [Azure Developer CLI][azure_developer_cli] to authenticate. Applications using the `DefaultAzureCredential` or the `AzureDeveloperCliCredential` can then use this account to authenticate calls in their application when running locally.
70
70
 
71
- To authenticate with the [Azure Developer CLI][azure_developer_cli], users can run the command `azd login`. For users running on a system with a default web browser, the Azure Developer CLI will launch the browser to authenticate the user.
71
+ To authenticate with the [Azure Developer CLI][azure_developer_cli], users can run the command `azd auth login`. For users running on a system with a default web browser, the Azure Developer CLI will launch the browser to authenticate the user.
72
72
 
73
- For systems without a default web browser, the `azd login --use-device-code` command will use the device code authentication flow.
73
+ For systems without a default web browser, the `azd auth login --use-device-code` command will use the device code authentication flow.
74
74
 
75
75
  #### Authenticate via the Azure CLI
76
76
 
@@ -133,7 +133,7 @@ If used from Node.js, the `DefaultAzureCredential` will attempt to authenticate
133
133
  1. **Environment** - The `DefaultAzureCredential` will read account information specified via [environment variables](#environment-variables) and use it to authenticate.
134
134
  1. **Workload Identity** - If the application is deployed to Azure Kubernetes Service with Managed Identity enabled, `DefaultAzureCredential` will authenticate with it.
135
135
  1. **Managed Identity** - If the application is deployed to an Azure host with Managed Identity enabled, the `DefaultAzureCredential` will authenticate with that account.
136
- 1. **Azure Developer CLI** - If the developer has authenticated an account via the Azure Developer CLI `azd login` command, the `DefaultAzureCredential` will authenticate with that account.
136
+ 1. **Azure Developer CLI** - If the developer has authenticated an account via the Azure Developer CLI `azd auth login` command, the `DefaultAzureCredential` will authenticate with that account.
137
137
  1. **Azure CLI** - If the developer has authenticated an account via the Azure CLI `az login` command, the `DefaultAzureCredential` will authenticate with that account.
138
138
  1. **Azure PowerShell** - If the developer has authenticated using the Azure PowerShell module `Connect-AzAccount` command, the `DefaultAzureCredential` will authenticate with that account.
139
139
 
@@ -298,6 +298,14 @@ Not all credentials require this configuration. Credentials that authenticate th
298
298
 
299
299
  Configuration is attempted in the above order. For example, if values for a client secret and certificate are both present, the client secret will be used.
300
300
 
301
+ ## Token caching
302
+ Token caching is a feature provided by the Azure Identity library that allows apps to:
303
+ - Cache tokens in memory (default) and on disk (opt-in).
304
+ - Improve resilience and performance.
305
+ - Reduce the number of requests made to Azure AD to obtain access tokens.
306
+
307
+ The Azure Identity library offers both in-memory and persistent disk caching. For more details, see the [token caching documentation](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/TOKEN_CACHING.md).
308
+
301
309
  ## Troubleshooting
302
310
 
303
311
  ### Error handling
package/dist/index.js CHANGED
@@ -257,7 +257,7 @@ function credentialLogger(title, log = logger$n) {
257
257
  /**
258
258
  * Current version of the `@azure/identity` package.
259
259
  */
260
- const SDK_VERSION = `3.2.0-beta.2`;
260
+ const SDK_VERSION = `3.2.1`;
261
261
  /**
262
262
  * The default client ID for authentication
263
263
  * @internal
@@ -1970,9 +1970,18 @@ const SupportedWorkloadEnvironmentVariables = [
1970
1970
  ];
1971
1971
  const logger$g = credentialLogger(credentialName$3);
1972
1972
  /**
1973
- * WorkloadIdentityCredential supports Azure workload identity authentication on Kubernetes.
1974
- * Refer to <a href="https://learn.microsoft.com/azure/aks/workload-identity-overview">Azure Active Directory Workload Identity</a>
1975
- * for more information.
1973
+ * Workload Identity authentication is a feature in Azure that allows applications running on virtual machines (VMs)
1974
+ * to access other Azure resources without the need for a service principal or managed identity. With Workload Identity
1975
+ * authentication, applications authenticate themselves using their own identity, rather than using a shared service
1976
+ * principal or managed identity. Under the hood, Workload Identity authentication uses the concept of Service Account
1977
+ * Credentials (SACs), which are automatically created by Azure and stored securely in the VM. By using Workload
1978
+ * Identity authentication, you can avoid the need to manage and rotate service principals or managed identities for
1979
+ * each application on each VM. Additionally, because SACs are created automatically and managed by Azure, you don't
1980
+ * need to worry about storing and securing sensitive credentials themselves.
1981
+ * The WorkloadIdentityCredential supports Azure workload identity authentication on Azure Kubernetes and acquires
1982
+ * a token using the SACs available in the Azure Kubernetes environment.
1983
+ * Refer to <a href="https://learn.microsoft.com/azure/aks/workload-identity-overview">Azure Active Directory
1984
+ * Workload Identity</a> for more information.
1976
1985
  */
1977
1986
  class WorkloadIdentityCredential {
1978
1987
  /**
@@ -1986,12 +1995,11 @@ class WorkloadIdentityCredential {
1986
1995
  // Logging environment variables for error details
1987
1996
  const assignedEnv = processEnvVars(SupportedWorkloadEnvironmentVariables).assigned.join(", ");
1988
1997
  logger$g.info(`Found the following environment variables: ${assignedEnv}`);
1989
- const workloadIdentityCredentialOptions = options;
1998
+ const workloadIdentityCredentialOptions = options !== null && options !== void 0 ? options : {};
1990
1999
  const tenantId = workloadIdentityCredentialOptions.tenantId || process.env.AZURE_TENANT_ID;
1991
2000
  const clientId = workloadIdentityCredentialOptions.clientId || process.env.AZURE_CLIENT_ID;
1992
2001
  this.federatedTokenFilePath =
1993
- workloadIdentityCredentialOptions.federatedTokenFilePath ||
1994
- process.env.AZURE_FEDERATED_TOKEN_FILE;
2002
+ workloadIdentityCredentialOptions.tokenFilePath || process.env.AZURE_FEDERATED_TOKEN_FILE;
1995
2003
  if (tenantId) {
1996
2004
  checkTenantId(logger$g, tenantId);
1997
2005
  }
@@ -2014,7 +2022,7 @@ class WorkloadIdentityCredential {
2014
2022
  In DefaultAzureCredential and ManagedIdentityCredential, these can be provided as environment variables -
2015
2023
  "AZURE_TENANT_ID",
2016
2024
  "AZURE_CLIENT_ID",
2017
- "AZURE_FEDERATED_TOKEN_FILE"`;
2025
+ "AZURE_FEDERATED_TOKEN_FILE". See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot `;
2018
2026
  logger$g.info(errorMessage);
2019
2027
  throw new CredentialUnavailableError(errorMessage);
2020
2028
  }
@@ -2066,7 +2074,7 @@ function tokenExchangeMsi() {
2066
2074
  async getToken(configuration, getTokenOptions = {}) {
2067
2075
  const { scopes, clientId } = configuration;
2068
2076
  const identityClientTokenCredentialOptions = {};
2069
- const workloadIdentityCredential = new WorkloadIdentityCredential(Object.assign(Object.assign({ clientId, tenantId: process.env.AZURE_TENANT_ID, federatedTokenFilePath: process.env.AZURE_FEDERATED_TOKEN_FILE }, identityClientTokenCredentialOptions), { disableInstanceDiscovery: true }));
2077
+ const workloadIdentityCredential = new WorkloadIdentityCredential(Object.assign(Object.assign({ clientId, tenantId: process.env.AZURE_TENANT_ID, tokenFilePath: process.env.AZURE_FEDERATED_TOKEN_FILE }, identityClientTokenCredentialOptions), { disableInstanceDiscovery: true }));
2070
2078
  const token = await workloadIdentityCredential.getToken(scopes, getTokenOptions);
2071
2079
  return token;
2072
2080
  },
@@ -2893,14 +2901,18 @@ class ChainedTokenCredential {
2893
2901
  * `TokenCredential` implementation might make.
2894
2902
  */
2895
2903
  async getToken(scopes, options = {}) {
2904
+ const { token } = await this.getTokenInternal(scopes, options);
2905
+ return token;
2906
+ }
2907
+ async getTokenInternal(scopes, options = {}) {
2896
2908
  let token = null;
2897
- let successfulCredentialName = "";
2909
+ let successfulCredential;
2898
2910
  const errors = [];
2899
2911
  return tracingClient.withSpan("ChainedTokenCredential.getToken", options, async (updatedOptions) => {
2900
2912
  for (let i = 0; i < this._sources.length && token === null; i++) {
2901
2913
  try {
2902
2914
  token = await this._sources[i].getToken(scopes, updatedOptions);
2903
- successfulCredentialName = this._sources[i].constructor.name;
2915
+ successfulCredential = this._sources[i];
2904
2916
  }
2905
2917
  catch (err) {
2906
2918
  if (err.name === "CredentialUnavailableError" ||
@@ -2918,11 +2930,11 @@ class ChainedTokenCredential {
2918
2930
  logger$9.getToken.info(formatError(scopes, err));
2919
2931
  throw err;
2920
2932
  }
2921
- logger$9.getToken.info(`Result for ${successfulCredentialName}: ${formatSuccess(scopes)}`);
2933
+ logger$9.getToken.info(`Result for ${successfulCredential.constructor.name}: ${formatSuccess(scopes)}`);
2922
2934
  if (token === null) {
2923
2935
  throw new CredentialUnavailableError("Failed to retrieve a valid token");
2924
2936
  }
2925
- return token;
2937
+ return { token, successfulCredential };
2926
2938
  });
2927
2939
  }
2928
2940
  }
@@ -3415,17 +3427,36 @@ const developerCliCredentialInternals = {
3415
3427
  };
3416
3428
  const logger$4 = credentialLogger("AzureDeveloperCliCredential");
3417
3429
  /**
3418
- * This credential will use the currently logged-in user login information
3419
- * via the Azure Developer CLI ('az') commandline tool.
3420
- * To do so, it will read the user access token and expire time
3421
- * with Azure Developer CLI command "azd auth token".
3430
+ * Azure Developer CLI is a command-line interface tool that allows developers to create, manage, and deploy
3431
+ * resources in Azure. It's built on top of the Azure CLI and provides additional functionality specific
3432
+ * to Azure developers. It allows users to authenticate as a user and/or a service principal against
3433
+ * <a href="https://learn.microsoft.com/azure/active-directory/fundamentals/">Azure Active Directory (Azure AD)
3434
+ * </a>. The AzureDeveloperCliCredential authenticates in a development environment and acquires a token on behalf of
3435
+ * the logged-in user or service principal in the Azure Developer CLI. It acts as the Azure Developer CLI logged in user or
3436
+ * service principal and executes an Azure CLI command underneath to authenticate the application against
3437
+ * Azure Active Directory.
3438
+ *
3439
+ * <h2> Configure AzureDeveloperCliCredential </h2>
3440
+ *
3441
+ * To use this credential, the developer needs to authenticate locally in Azure Developer CLI using one of the
3442
+ * commands below:
3443
+ *
3444
+ * <ol>
3445
+ * <li>Run "azd auth login" in Azure Developer CLI to authenticate interactively as a user.</li>
3446
+ * <li>Run "azd auth login --client-id clientID --client-secret clientSecret
3447
+ * --tenant-id tenantID" to authenticate as a service principal.</li>
3448
+ * </ol>
3449
+ *
3450
+ * You may need to repeat this process after a certain time period, depending on the refresh token validity in your
3451
+ * organization. Generally, the refresh token validity period is a few weeks to a few months.
3452
+ * AzureDeveloperCliCredential will prompt you to sign in again.
3422
3453
  */
3423
3454
  class AzureDeveloperCliCredential {
3424
3455
  /**
3425
3456
  * Creates an instance of the {@link AzureDeveloperCliCredential}.
3426
3457
  *
3427
3458
  * To use this credential, ensure that you have already logged
3428
- * in via the 'azd' tool using the command "azd login" from the commandline.
3459
+ * in via the 'azd' tool using the command "azd auth login" from the commandline.
3429
3460
  *
3430
3461
  * @param options - Options, to optionally allow multi-tenant requests.
3431
3462
  */
@@ -3453,19 +3484,20 @@ class AzureDeveloperCliCredential {
3453
3484
  }
3454
3485
  logger$4.getToken.info(`Using the scopes ${scopes}`);
3455
3486
  return tracingClient.withSpan(`${this.constructor.name}.getToken`, options, async () => {
3456
- var _a, _b, _c;
3487
+ var _a, _b, _c, _d;
3457
3488
  try {
3458
3489
  const obj = await developerCliCredentialInternals.getAzdAccessToken(scopeList, tenantId, this.timeout);
3459
- const isNotLoggedInError = (_a = obj.stderr) === null || _a === void 0 ? void 0 : _a.match("not logged in, run `azd login` to login");
3460
- const isNotInstallError = ((_b = obj.stderr) === null || _b === void 0 ? void 0 : _b.match("azd:(.*)not found")) ||
3461
- ((_c = obj.stderr) === null || _c === void 0 ? void 0 : _c.startsWith("'azd' is not recognized"));
3490
+ const isNotLoggedInError = ((_a = obj.stderr) === null || _a === void 0 ? void 0 : _a.match("not logged in, run `azd login` to login")) ||
3491
+ ((_b = obj.stderr) === null || _b === void 0 ? void 0 : _b.match("not logged in, run `azd auth login` to login"));
3492
+ const isNotInstallError = ((_c = obj.stderr) === null || _c === void 0 ? void 0 : _c.match("azd:(.*)not found")) ||
3493
+ ((_d = obj.stderr) === null || _d === void 0 ? void 0 : _d.startsWith("'azd' is not recognized"));
3462
3494
  if (isNotInstallError || (obj.error && obj.error.code === "ENOENT")) {
3463
- const error = new CredentialUnavailableError("Azure Developer CLI could not be found. Please visit https://aka.ms/azure-dev for installation instructions and then, once installed, authenticate to your Azure account using 'azd login'.");
3495
+ const error = new CredentialUnavailableError("Azure Developer CLI couldn't be found. To mitigate this issue, see the troubleshooting guidelines at https://aka.ms/azsdk/js/identity/azdevclicredential/troubleshoot.");
3464
3496
  logger$4.getToken.info(formatError(scopes, error));
3465
3497
  throw error;
3466
3498
  }
3467
3499
  if (isNotLoggedInError) {
3468
- const error = new CredentialUnavailableError("Please run 'azd login' from a command prompt to authenticate before using this credential.");
3500
+ const error = new CredentialUnavailableError("Please run 'azd auth login' from a command prompt to authenticate before using this credential. For more information, see the troubleshooting guidelines at https://aka.ms/azsdk/js/identity/azdevclicredential/troubleshoot.");
3469
3501
  logger$4.getToken.info(formatError(scopes, error));
3470
3502
  throw error;
3471
3503
  }
@@ -3546,7 +3578,7 @@ class DefaultWorkloadIdentityCredential extends WorkloadIdentityCredential {
3546
3578
  const workloadFile = process.env.AZURE_FEDERATED_TOKEN_FILE;
3547
3579
  const tenantId = (_c = options === null || options === void 0 ? void 0 : options.tenantId) !== null && _c !== void 0 ? _c : process.env.AZURE_TENANT_ID;
3548
3580
  if (workloadFile && workloadIdentityClientId) {
3549
- const workloadIdentityCredentialOptions = Object.assign(Object.assign({}, options), { tenantId, clientId: workloadIdentityClientId, federatedTokenFilePath: workloadFile });
3581
+ const workloadIdentityCredentialOptions = Object.assign(Object.assign({}, options), { tenantId, clientId: workloadIdentityClientId, tokenFilePath: workloadFile });
3550
3582
  super(workloadIdentityCredentialOptions);
3551
3583
  }
3552
3584
  else if (tenantId) {
@@ -3560,17 +3592,17 @@ class DefaultWorkloadIdentityCredential extends WorkloadIdentityCredential {
3560
3592
  }
3561
3593
  class DefaultAzureDeveloperCliCredential extends AzureDeveloperCliCredential {
3562
3594
  constructor(options) {
3563
- super(Object.assign({ processTimeoutInMs: options === null || options === void 0 ? void 0 : options.developerCredentialTimeOutInMs }, options));
3595
+ super(Object.assign({ processTimeoutInMs: options === null || options === void 0 ? void 0 : options.processTimeoutInMs }, options));
3564
3596
  }
3565
3597
  }
3566
3598
  class DefaultAzureCliCredential extends AzureCliCredential {
3567
3599
  constructor(options) {
3568
- super(Object.assign({ processTimeoutInMs: options === null || options === void 0 ? void 0 : options.developerCredentialTimeOutInMs }, options));
3600
+ super(Object.assign({ processTimeoutInMs: options === null || options === void 0 ? void 0 : options.processTimeoutInMs }, options));
3569
3601
  }
3570
3602
  }
3571
3603
  class DefaultAzurePowershellCredential extends AzurePowerShellCredential {
3572
3604
  constructor(options) {
3573
- super(Object.assign({ processTimeoutInMs: options === null || options === void 0 ? void 0 : options.developerCredentialTimeOutInMs }, options));
3605
+ super(Object.assign({ processTimeoutInMs: options === null || options === void 0 ? void 0 : options.processTimeoutInMs }, options));
3574
3606
  }
3575
3607
  }
3576
3608
  const defaultCredentials = [