Skip to content

Allow a default ITokenRequestCustomizer to be registered#300

Merged
pgermishuys merged 1 commit intomainfrom
pg/http-request-context
Nov 21, 2025
Merged

Allow a default ITokenRequestCustomizer to be registered#300
pgermishuys merged 1 commit intomainfrom
pg/http-request-context

Conversation

@pgermishuys
Copy link
Copy Markdown
Contributor

This is useful to ensure that a single TokenRequestCustomizer can be used for various paths such as ITokenRetrievers as well as the HttpContextExtensions.

This introduces a breaking change in Access Token Management's ITokenRequestCustomizer interface, which changed one if it's parameters from HttpRequestMessage to HttpRequestContext. The change was necessary as we want to allow the customizer to be used in the HttpRequestMessageExtensions from which we only get access to the HttpRequest and not the HttpRequestMessage.

The breaking change could be considered ok as the ITokenRequestCustomizer was introduced in Access Token Management 4.1.0 which does not have a non-preview/RC release.

@pgermishuys pgermishuys marked this pull request as ready for review November 20, 2025 12:18
@pgermishuys pgermishuys requested review from a team and Copilot November 20, 2025 12:18
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.

Pull Request Overview

This PR enables a default ITokenRequestCustomizer to be registered globally and used across multiple token retrieval paths. The primary change is a breaking modification to the ITokenRequestCustomizer interface, which now accepts HttpRequestContext instead of HttpRequestMessage to support customization in contexts where only HttpRequest is available (e.g., HttpContextExtensions).

  • Introduced a new HttpRequestContext struct to abstract HTTP request details
  • Updated the ITokenRequestCustomizer interface signature to use HttpRequestContext
  • Enabled customizer usage in HttpContextExtensions methods (GetUserAccessTokenAsync, GetClientAccessTokenAsync, RevokeRefreshTokenAsync)

Reviewed Changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
HttpRequestContext.cs New struct to represent HTTP request context with method, URI, and headers
ITokenRequestCustomizer.cs Changed interface parameter from HttpRequestMessage to HttpRequestContext
HttpRequestContextExtensions.cs (AccessTokenManagement) Extension method to convert HttpRequestMessage to HttpRequestContext
HttpRequestContextExtensions.cs (OpenIdConnect) Extension method to convert HttpRequest to HttpRequestContext
HttpContextExtensions.cs Added logic to apply token request customization in extension methods
ClientCredentialsTokenRetriever.cs Updated to use new HttpRequestContext when calling customizer
OpenIdConnectUserAccessTokenRetriever.cs Updated to use new HttpRequestContext when calling customizer
OpenIdConnectClientAccessTokenRetriever.cs Updated to use new HttpRequestContext and fixed parameter merging logic
Test files Updated tests to reflect new interface signature and added comprehensive test coverage for the new functionality
Public API verification files Updated to reflect new public HttpRequestContext type and interface changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

This is useful to ensure that a single TokenRequestCustomizer can be
used for various paths such as ITokenRetrievers as well as the
HttpContextExtensions.
@pgermishuys pgermishuys merged commit 3cebfeb into main Nov 21, 2025
3 checks passed
@pgermishuys pgermishuys deleted the pg/http-request-context branch November 21, 2025 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants