Skip to content

Conversation

@zhiyuanliang-ms
Copy link
Member

Users running in clouds other than the public cloud must correctly configure ConfigurationClientOptions.Audience when using the ConfigurationClient from the Azure SDK.

There are two main ways users can misconfigure
They do not specify audience when they are running in non-public cloud
They specify audience, and the audience they specify is the wrong one for the cloud is using

In both cases we will get an error when trying to get an Entra ID token that looks like:

"Microsoft.Identity.Client.MsalServiceException: AADSTS500011: The resource principal named https://appconfig.azure.com was not found in the tenant named msazurecloud. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant."

We should handle this error and surface up an improved error message

Audience not provided
If we get this error and audience is not provided we should surface an error message that says audience should be configured and link to our public doc that documents the appropriate audience for each cloud

Audience provided and incorrect
If we get this error and the audience is provided but is wrong, we should surface an error message that the configured audience is wrong and link to our public doc that documents the appropriate audience for each cloud.

Copilot AI review requested due to automatic review settings November 12, 2025 07:33
@github-actions github-actions bot added the App Configuration Azure.ApplicationModel.Configuration label Nov 12, 2025
Copilot finished reviewing on behalf of zhiyuanliang-ms November 12, 2025 07:37
Copy link
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.

Pull Request Overview

This PR adds improved error handling for audience configuration issues in the Azure App Configuration SDK. When users in non-public clouds fail to configure or misconfigure the ConfigurationClientOptions.Audience, they now receive clearer error messages that guide them to the appropriate documentation.

Key Changes:

  • Adds AudienceErrorHandlingPolicy to intercept AADSTS500011 authentication errors and provide context-specific guidance
  • Integrates the new policy into the HTTP pipeline
  • Adds Azure.Identity package dependency for AuthenticationFailedException

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
sdk/appconfiguration/Azure.Data.AppConfiguration/src/AudienceErrorHandlingPolicy.cs New pipeline policy that catches audience-related authentication failures and rethrows with improved error messages
sdk/appconfiguration/Azure.Data.AppConfiguration/src/ConfigurationClient.cs Integrates the new policy into the HTTP pipeline (contains critical bugs)
sdk/appconfiguration/Azure.Data.AppConfiguration/src/Azure.Data.AppConfiguration.csproj Adds Azure.Identity package reference for AuthenticationFailedException
@zhiyuanliang-ms zhiyuanliang-ms force-pushed the zhiyuanliang/audience-error branch from be14225 to 530f325 Compare November 12, 2025 07:56
@github-actions
Copy link

github-actions bot commented Nov 12, 2025

API Change Check

APIView identified API level changes in this PR and created the following API reviews

Azure.Data.AppConfiguration

}

string message = _isAudienceConfigured ? WrongAudienceErrorMessage : NoAudienceErrorMessage;
throw new AuthenticationFailedException(message, ex);
Copy link
Member

Choose a reason for hiding this comment

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

Keep the throw statement in the catch block only. If a helper is needed, return any state back to the catch block and throw.

Otherwise it's not clear that there are multiple throw paths.

{
ProcessNext(message, pipeline);
}
catch (Exception ex)
Copy link
Member

Choose a reason for hiding this comment

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

Should use when clause

{
private readonly bool _isAudienceConfigured;
private const string AadAudienceErrorCode = "AADSTS500011";
private const string NoAudienceErrorMessage = "Unable to authenticate to Azure App Configuration. No authentication token audience was provided. Please set ConfigurationClientOptions.Audience to the appropriate audience for the target cloud. For details on how to configure the authentication token audience visit https://aka.ms/appconfig/client-token-audience.";
Copy link
Member

Choose a reason for hiding this comment

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

Use nameof(ConfigurationClientOptions.Audience)

{
await ProcessNextAsync(message, pipeline).ConfigureAwait(false);
}
catch (Exception ex)
Copy link
Member

@avanigupta avanigupta Nov 13, 2025

Choose a reason for hiding this comment

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

Do we need to catch base Exception or can we catch AuthenticationFailedException/MsalServiceException?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

App Configuration Azure.ApplicationModel.Configuration

3 participants