AzureDeveloperCliCredential: parse new auth error formats - #49271
AzureDeveloperCliCredential: parse new auth error formats#49271JeffreyCA wants to merge 2 commits into
Conversation
… support new azd formats
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.
|
Hi @JeffreyCA. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days. |
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