@azure/identity 4.0.2-alpha.20240123.2 → 4.1.0-alpha.20240124.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.

package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ var child_process__namespace = /*#__PURE__*/_interopNamespaceDefault(child_proce
44
44
  /**
45
45
  * Current version of the `@azure/identity` package.
46
46
  */
47
- const SDK_VERSION = `4.0.2`;
47
+ const SDK_VERSION = `4.1.0-beta.1`;
48
48
  /**
49
49
  * The default client ID for authentication
50
50
  * @internal
@@ -2767,13 +2767,9 @@ class AzureCliCredential {
2767
2767
  }
2768
2768
  try {
2769
2769
  const responseData = obj.stdout;
2770
- const response = JSON.parse(responseData);
2770
+ const response = this.parseRawResponse(responseData);
2771
2771
  logger$b.getToken.info(formatSuccess(scopes));
2772
- const returnValue = {
2773
- token: response.accessToken,
2774
- expiresOnTimestamp: new Date(response.expiresOn).getTime(),
2775
- };
2776
- return returnValue;
2772
+ return response;
2777
2773
  }
2778
2774
  catch (e) {
2779
2775
  if (obj.stderr) {
@@ -2791,6 +2787,40 @@ class AzureCliCredential {
2791
2787
  }
2792
2788
  });
2793
2789
  }
2790
+ /**
2791
+ * Parses the raw JSON response from the Azure CLI into a usable AccessToken object
2792
+ *
2793
+ * @param rawResponse - The raw JSON response from the Azure CLI
2794
+ * @returns An access token with the expiry time parsed from the raw response
2795
+ *
2796
+ * The expiryTime of the credential's access token, in milliseconds, is calculated as follows:
2797
+ *
2798
+ * When available, expires_on (introduced in Azure CLI v2.54.0) will be preferred. Otherwise falls back to expiresOn.
2799
+ */
2800
+ parseRawResponse(rawResponse) {
2801
+ const response = JSON.parse(rawResponse);
2802
+ const token = response.accessToken;
2803
+ // if available, expires_on will be a number representing seconds since epoch.
2804
+ // ensure it's a number or NaN
2805
+ let expiresOnTimestamp = Number.parseInt(response.expires_on, 10) * 1000;
2806
+ if (!isNaN(expiresOnTimestamp)) {
2807
+ logger$b.getToken.info("expires_on is available and is valid, using it");
2808
+ return {
2809
+ token,
2810
+ expiresOnTimestamp,
2811
+ };
2812
+ }
2813
+ // fallback to the older expiresOn - an RFC3339 date string
2814
+ expiresOnTimestamp = new Date(response.expiresOn).getTime();
2815
+ // ensure expiresOn is well-formatted
2816
+ if (isNaN(expiresOnTimestamp)) {
2817
+ throw new CredentialUnavailableError(`Unexpected response from Azure CLI when getting token. Expected "expiresOn" to be a RFC3339 date string. Got: "${response.expiresOn}"`);
2818
+ }
2819
+ return {
2820
+ token,
2821
+ expiresOnTimestamp,
2822
+ };
2823
+ }
2794
2824
  }
2795
2825
 
2796
2826
  // Copyright (c) Microsoft Corporation.