AzureDeveloperCliCredential: parse new auth error formats#38416
Open
JeffreyCA wants to merge 1 commit intoAzure:mainfrom
Open
AzureDeveloperCliCredential: parse new auth error formats#38416JeffreyCA wants to merge 1 commit intoAzure:mainfrom
JeffreyCA wants to merge 1 commit intoAzure:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates @azure/identity’s AzureDeveloperCliCredential to correctly extract human-readable error text from newer Azure Developer CLI (azd) stderr JSON formats (introduced in azd v1.23.7), preventing raw JSON blobs from surfacing in thrown credential errors.
Changes:
- Enhanced
parseAzdStderrto scan newline-delimited stderr, prefer a structured{ "error": "..." }field, and fall back to the first non-empty legacyconsoleMessage.data.message. - Added unit tests covering all supported azd stderr formats, including the v1.23.7–v1.23.15 two-line case and the v1.24.0+ single-line structured error.
- Documented the fix in the
@azure/identitychangelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| sdk/identity/identity/src/credentials/azureDeveloperCliCredential.ts | Updates stderr parsing to support both legacy consoleMessage JSON and newer structured { error } JSON (including multi-line stderr). |
| sdk/identity/identity/test/internal/node/azureDeveloperCliCredential.spec.ts | Adds unit + integration-style tests validating correct message extraction across azd versions and precedence rules. |
| sdk/identity/identity/CHANGELOG.md | Records the bug fix in the unreleased 4.14.0-beta.4 notes. |
Merged
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Packages impacted by this PR
@azure/identityIssues associated with this PR
Fixes Azure/azure-dev#7857 (parent: Azure/azure-dev#7728)
Describe the problem that is addressed by this PR
Starting with azd v1.23.7 (PR Azure/azure-dev#6827),
azd auth tokenchanged its stderr error format from the legacyconsoleMessageJSON to a structured{"error":"..."}JSON object. The stderr output may also include an extraneous emptyconsoleMessageline preceding the error (fixed in v1.24.0 via Azure/azure-dev#7701).This PR updates
AzureDeveloperCliCredentialerror parsing to handle all three formats:{"type":"consoleMessage","data":{"message":"..."}}{"type":"consoleMessage",...}\n{"error":"..."}(two lines){"error":"..."}(single line)AzureDeveloperCliCredential.parseAzdStderrpreviously only handled the legacy single-lineconsoleMessageshape. On azd v1.23.7+ it would fail to extract the message and surface the raw JSON blob in the credential's error message instead of the underlying AAD error.The parser splits stderr by newline, prefers the structured
errorfield, and falls back to the first non-emptydata.messagefrom a legacyconsoleMessageline. If neither is found the raw text is returned unchanged, preserving existing behaviour for plain-text and malformed output.What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen?
Considered approaches:
\n, attemptsJSON.parseper line, prefers the structurederrorfield, and falls back to the first non-emptydata.message. Handles all three formats in one pass with minimal allocations. Returns the raw stderr unchanged when neither field is present, preserving existing behaviour for plain-text/malformed output.@azure/identitysupports users on older azd installs; silently regressing them is unacceptable.The chosen design also matches the equivalent fixes in
azure-sdk-for-goandazure-sdk-for-net, keeping behaviour consistent across the three SDKs.Are there test cases added in this PR? (If not, why?)
Yes, added unit tests in
sdk/identity/identity/test/internal/node/azureDeveloperCliCredential.spec.tsAlso manually validated with small Node sample app:
Without changes (azd v1.23.7+)
With changes
Provide a list of related PRs (if any)
Command used to generate this PR:**(Applicable only to SDK release request PRs)
N/A
Checklists