-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[App Configuration] - Add audience error handling policy #53834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zhiyuanliang-ms
wants to merge
11
commits into
Azure:main
Choose a base branch
from
zhiyuanliang-ms:zhiyuanliang/audience-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
530f325
add Audience error handling policy
zhiyuanliang-ms b40d5c6
update
zhiyuanliang-ms e608aaa
not introduce Azure.Identity
zhiyuanliang-ms 8d5d15f
update
zhiyuanliang-ms 4fbea4e
update
zhiyuanliang-ms 56503a5
update
zhiyuanliang-ms 414f6c4
add test
zhiyuanliang-ms 89f2706
Revert "add test"
zhiyuanliang-ms 16d06ee
add unit test
zhiyuanliang-ms b8ee403
update
zhiyuanliang-ms 1743786
update
zhiyuanliang-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
sdk/appconfiguration/Azure.Data.AppConfiguration/src/AudienceErrorHandlingPolicy.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Azure.Core; | ||
| using Azure.Core.Pipeline; | ||
|
|
||
| namespace Azure.Data.AppConfiguration | ||
| { | ||
| /// <summary> | ||
| /// Pipeline policy that provides more helpful errors when Entra ID audience misconfiguration is detected. | ||
| /// </summary> | ||
| internal class AudienceErrorHandlingPolicy : HttpPipelinePolicy | ||
| { | ||
| 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."; | ||
zhiyuanliang-ms marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private const string WrongAudienceErrorMessage = "Unable to authenticate to Azure App Configuration. An incorrect 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."; | ||
|
|
||
| public AudienceErrorHandlingPolicy(bool isAudienceConfigured) | ||
| { | ||
| _isAudienceConfigured = isAudienceConfigured; | ||
| } | ||
|
|
||
| public override void Process(HttpMessage message, ReadOnlyMemory<HttpPipelinePolicy> pipeline) | ||
| { | ||
| try | ||
| { | ||
| ProcessNext(message, pipeline); | ||
| } | ||
| catch (Exception ex) | ||
zhiyuanliang-ms marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| if (ex.Message.Contains(AadAudienceErrorCode)) | ||
| { | ||
| string errorMessage = _isAudienceConfigured ? WrongAudienceErrorMessage : NoAudienceErrorMessage; | ||
| throw new RequestFailedException(errorMessage, ex); | ||
| } | ||
|
|
||
| throw; | ||
| } | ||
| } | ||
|
|
||
| public override async ValueTask ProcessAsync(HttpMessage message, ReadOnlyMemory<HttpPipelinePolicy> pipeline) | ||
| { | ||
| try | ||
| { | ||
| await ProcessNextAsync(message, pipeline).ConfigureAwait(false); | ||
| } | ||
| catch (Exception ex) | ||
avanigupta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| if (ex.Message.Contains(AadAudienceErrorCode)) | ||
| { | ||
| string errorMessage = _isAudienceConfigured ? WrongAudienceErrorMessage : NoAudienceErrorMessage; | ||
| throw new RequestFailedException(errorMessage, ex); | ||
| } | ||
|
|
||
| throw; | ||
| } | ||
| } | ||
| } | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.