Skip to content

Parse new azd auth error formats in AzureDeveloperCliCredential#46711

Merged
JeffreyCA merged 2 commits intoAzure:mainfrom
JeffreyCA:jeffreyca/azd-cred-err-parse
May 6, 2026
Merged

Parse new azd auth error formats in AzureDeveloperCliCredential#46711
JeffreyCA merged 2 commits intoAzure:mainfrom
JeffreyCA:jeffreyca/azd-cred-err-parse

Conversation

@JeffreyCA
Copy link
Copy Markdown
Contributor

@JeffreyCA JeffreyCA commented May 5, 2026

Fixes Azure/azure-dev#7859 (parent: Azure/azure-dev#7728)

Related:

Description

Starting with azd v1.23.7 (PR Azure/azure-dev#6827), azd auth token changed its stderr error format from the legacy consoleMessage JSON to a structured {"error":"..."} JSON object. The stderr output may also include an extraneous empty consoleMessage line preceding the error (fixed in v1.24.0 via Azure/azure-dev#7701).

This PR updates AzureDeveloperCliCredential error parsing to handle all three formats:

azd version stderr format
pre-v1.23.7 {"type":"consoleMessage","data":{"message":"..."}}
v1.23.7 – v1.23.15 {"type":"consoleMessage",...}\n{"error":"..."} (two lines)
v1.24.0+ {"error":"..."} (single line)

Validation

In addition to unit tests, validated manually with small Python script:

credential = AzureDeveloperCliCredential(tenant_id="invalid-tenant")

try:
    token = credential.get_token("https://management.azure.com/.default")
    print(f"Unexpected success. Token expires at: {token.expires_on}")
except ClientAuthenticationError as ex:
    pass

Without changes (v1.23.6)

AzureDeveloperCliCredential.get_token failed: ERROR: fetching token: failed to authenticate:
(invalid_tenant) AADSTS90002: Tenant 'invalid-tenant' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant. Trace ID: <redacted> Correlation ID: <redacted> Timestamp: 2026-05-05 00:38:02Z

Without changes (v1.23.7+)

AzureDeveloperCliCredential.get_token failed: Authentication with Azure failed.

With changes (all versions)

AzureDeveloperCliCredential.get_token failed: ERROR: fetching token: failed to authenticate:
(invalid_tenant) AADSTS90002: Tenant 'invalid-tenant' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant. Trace ID: <redacted> Correlation ID: <redacted> Timestamp: 2026-05-05 00:38:37Z

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Member

@pvaneck pvaneck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall. Looks like you just need to run black formatting locally (azpysdk black) for the Analyze check. Also, with "error" being preferred, is "suggestion" also something worth surfacing still?

@github-project-automation github-project-automation Bot moved this from Untriaged to In Progress in Azure Identity SDK Improvements May 5, 2026
@JeffreyCA
Copy link
Copy Markdown
Contributor Author

LGTM overall. Looks like you just need to run black formatting locally (azpysdk black) for the Analyze check. Also, with "error" being preferred, is "suggestion" also something worth surfacing still?

Thanks, I went ahead and removed the suggestion logic since I think preferring the error makes more sense and is more helpful for understanding what exactly went wrong (exact AADSTS code and message) than the suggestion (which is usually something like re-running azd auth login). It also aligns with how the other languages' SDKs like Go and .NET behave.

@JeffreyCA JeffreyCA merged commit 2240bf9 into Azure:main May 6, 2026
20 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Azure Identity SDK Improvements May 6, 2026
@JeffreyCA JeffreyCA deleted the jeffreyca/azd-cred-err-parse branch May 6, 2026 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

Update AzureDeveloperCLICredential error message parsing in azure-sdk-for-python

4 participants