AzureDeveloperCliCredential: parse new auth error formats#49271
Open
JeffreyCA wants to merge 2 commits into
Open
AzureDeveloperCliCredential: parse new auth error formats#49271JeffreyCA wants to merge 2 commits into
JeffreyCA wants to merge 2 commits into
Conversation
… support new azd formats
Contributor
There was a problem hiding this comment.
Pull request overview
Updates Azure Identity’s AzureDeveloperCliCredential integration to correctly parse and surface errors from newer Azure Developer CLI (azd) versions where stderr moved from legacy consoleMessage JSON to structured {"error":"..."} JSON, ensuring AAD failures are classified as authentication errors rather than “credential unavailable”.
Changes:
- Updated azd stderr parsing to prefer the structured top-level
errorfield, with fallback to the first non-empty legacydata.message. - Adjusted exception classification to dispatch based on the parsed message (avoiding
suggestiontext likeazd auth loginskewing classification). - Added/updated unit tests covering legacy, mixed, and structured azd error formats (including multi-object outputs).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IdentityClientBase.java | Updates azd error parsing and exception dispatch to support structured error output and correct classification. |
| sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientTests.java | Expands and updates tests to cover new structured error formats and revised legacy precedence behavior. |
| sdk/identity/azure-identity/CHANGELOG.md | Documents the azd parsing fix and the corrected exception classification for structured AAD failures. |
Comments suppressed due to low confidence (1)
sdk/identity/azure-identity/CHANGELOG.md:17
- The Unreleased notes now have two bullets describing improved
AzureDeveloperCliCredentialazd error message extraction (one under “Bugs Fixed” and another under “Other Changes”). Consider consolidating or rewording to avoid redundant/possibly confusing release notes for the same behavior change.
- Fixed `AzureDeveloperCliCredential` error parsing for Azure Developer CLI v1.23.7 and later, which previously surfaced the friendly wrapper "Authentication with Azure failed." instead of the underlying error text. The parser now prefers the structured top-level `error` field while preserving fallback behavior for older `consoleMessage` output.
- Structured AAD failures from `azd` (e.g. `invalid_tenant`, `AADSTS*`) now surface as `ClientAuthenticationException` rather than being misclassified as `CredentialUnavailableException`.
- Disabled MSAL's internal retry for Confidential Client, Managed Identity and Public Client Applications.
### Other Changes
- Improved `AzureDeveloperCliCredential` error handling to extract meaningful messages from `azd auth token` JSON output, providing cleaner error messages to users.
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.
Fixes Azure/azure-dev#8039
Related:
Description
Starting with azd v1.23.7,
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)The parsed message is also used for downstream exception classification, so structured AAD failures (e.g.
invalid_tenant,AADSTS*) now correctly surface asClientAuthenticationExceptioninstead of being misclassified asCredentialUnavailableExceptiondue to theazd auth logintext embedded in thesuggestionfield.Testing
Added unit tests in
IdentityClientTests.javacovering each format, theerror-over-consoleMessageprecedence, and the multi-line legacy fallback. Existing tests for the legacy format and downstream error classification (login-required, AADSTS, etc.) continue to pass.Validated manually against multiple versions of
azdwith a small test program that callsgetTokenSyncon anAzureDeveloperCliCredentialinstance with an invalid tenant ID:Without changes - v1.23.6:
Without changes - v1.23.7 and above:
With changes - v1.23.6:
With changes - v1.23.7 and above:
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines