-
Notifications
You must be signed in to change notification settings - Fork 241
Add MicrosoftIdentityMessageHandler for flexible HttpClient authentication #3503
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
Merged
jmprieur
merged 13 commits into
master
from
copilot/fix-82eb5023-e802-4c45-8341-57c618f136aa
Oct 10, 2025
Merged
Add MicrosoftIdentityMessageHandler for flexible HttpClient authentication #3503
jmprieur
merged 13 commits into
master
from
copilot/fix-82eb5023-e802-4c45-8341-57c618f136aa
Oct 10, 2025
Conversation
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
…ion plan Co-authored-by: jmprieur <[email protected]>
Co-authored-by: jmprieur <[email protected]>
Co-authored-by: jmprieur <[email protected]>
Copilot
AI
changed the title
[WIP] Spec: Add MicrosoftIdentityMessageHandler using IAuthorizationHeaderProvider for flexible authentication in HttpClient
Add MicrosoftIdentityMessageHandler for flexible HttpClient authentication
Sep 26, 2025
Copilot finished work on behalf of
jmprieur
September 26, 2025 22:10
jmprieur
reviewed
Sep 26, 2025
src/Microsoft.Identity.Web.TokenAcquisition/MicrosoftIdentityMessageHandlerOptions.cs
Outdated
Show resolved
Hide resolved
jmprieur
reviewed
Sep 26, 2025
src/Microsoft.Identity.Web.TokenAcquisition/MicrosoftIdentityMessageHandler.cs
Show resolved
Hide resolved
Copilot finished work on behalf of
jmprieur
September 26, 2025 23:42
Copilot finished work on behalf of
jmprieur
September 27, 2025 00:01
jmprieur
reviewed
Sep 27, 2025
src/Microsoft.Identity.Web.TokenAcquisition/MicrosoftIdentityMessageHandlerOptions.cs
Outdated
Show resolved
Hide resolved
…zationHeaderProviderOptions Co-authored-by: jmprieur <[email protected]>
Copilot finished work on behalf of
jmprieur
September 27, 2025 00:24
…andler integration Co-authored-by: jmprieur <[email protected]>
This was referenced Oct 28, 2025
This was referenced Nov 4, 2025
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.
Implementation Complete: MicrosoftIdentityMessageHandler
Fixes #3502
✅ FULLY IMPLEMENTED - The
MicrosoftIdentityMessageHandlerhas been successfully implemented according to the GitHub issue specification.🎯 Core Implementation
🚀 Key Features Delivered
✅ Flexible Authentication: Uses
IAuthorizationHeaderProviderandAuthorizationHeaderProviderOptions✅ Per-Client Configuration: Default options can be set at handler creation
✅ Per-Request Override: Options can be configured per HTTP request
✅ Modern .NET APIs: Uses
HttpRequestMessage.Options(with fallback for older frameworks)✅ Challenge Handling: Robust WWW-Authenticate challenge detection using MSAL's WwwAuthenticateParameters
✅ Error Handling: Actionable exceptions with clear error messages
✅ Logging Integration: Optional
ILogger<MicrosoftIdentityMessageHandler>support with enhanced logging✅ Performance Optimized: Efficient challenge handling with proper resource management
📖 Usage Examples (All Working)
1. DI Setup:
2. Per-Request Override:
3. Manual Instantiation:
4. Error Handling:
🧪 Testing & Quality
🔧 Technical Highlights
📋 Recent Enhancement (Latest Commit)
✅ Code Review Improvements: Based on comprehensive code review feedback
WwwAuthenticateParameters.GetClaimChallengeFromResponseHeaders()for robust, well-tested challenge parsing📋 Files Added/Modified
src/Microsoft.Identity.Web.TokenAcquisition/MicrosoftIdentityMessageHandler.cssrc/Microsoft.Identity.Web.TokenAcquisition/MicrosoftIdentityMessageHandlerOptions.cssrc/Microsoft.Identity.Web.TokenAcquisition/HttpRequestMessageAuthenticationExtensions.cssrc/Microsoft.Identity.Web.TokenAcquisition/MicrosoftIdentityAuthenticationException.cssrc/Microsoft.Identity.Web.TokenAcquisition/GlobalSuppressions.cstests/Microsoft.Identity.Web.Test/MicrosoftIdentityMessageHandlerNewTests.csThis implementation provides developers with a flexible, composable alternative to DownstreamApi that integrates seamlessly with existing HttpClient-based codebases while leveraging Microsoft Identity Web's complete authentication infrastructure, now enhanced with MSAL's proven WWW-Authenticate parsing and comprehensive logging.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.