-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add ComponentFrameworkEndpointMetadata and ConfigureFrameworkEndpoints to identify and configure Blazor infrastructure endpoints #63821
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
base: main
Are you sure you want to change the base?
Conversation
Greetings human! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo! |
…ure endpoints Co-authored-by: javiercn <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot I have a few comments.
We also want to have an extension method that allows us to configure the framework endpoints easily.
Maybe ConfigureFrameworkEndpoints(endpointBuilder => ...)
that calls Add
to add a convention but first checks if the attribute is there before running the callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the ComponentFrameworkEndpointMetadataTest.cs file. Commit: 1c1c0b9
.MapBlazorHub() | ||
.Finally(builder => | ||
{ | ||
if (builder.Metadata.GetMetadata<ComponentFrameworkEndpointMetadata>() is not null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are errors here src/Components/Server/test/ComponentEndpointRouteBuilderExtensionsTest.cs(142,46): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'IList' does not contain a definition for 'GetMetadata' and no accessible extension method 'GetMetadata' accepting a first argument of type 'IList' could be found (are you missing a using directive or an assembly reference?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the compilation error by using OfType<ComponentFrameworkEndpointMetadata>().Any()
instead of GetMetadata<ComponentFrameworkEndpointMetadata>()
on IList<object>
. Commit: 1c1c0b9
…ameworkEndpoints method Co-authored-by: javiercn <[email protected]>
Added the |
Problem
When configuring Blazor applications, calling
RequireAuthorization()
on the component builder affects all endpoints, including internal infrastructure endpoints like_framework/opaque-redirect
,_blazor/disconnect
, and_blazor/initializers
. This creates a painful developer experience where users need to manually find and reconfigure these framework endpoints to exclude them from authorization requirements.Solution
This PR introduces
ComponentFrameworkEndpointMetadata
, a public sealed marker class that identifies Blazor's infrastructure endpoints, and aConfigureFrameworkEndpoints
extension method that provides a clean API for configuring framework endpoints specifically.New APIs:
Enhanced Developer Experience:
Infrastructure Endpoints Enhanced
The following Blazor framework endpoints now include
ComponentFrameworkEndpointMetadata
:_framework/opaque-redirect
) - Used for enhanced navigation redirects_blazor/disconnect
) - Used for circuit cleanup_blazor/initializers
) - Used for JavaScript initialization_framework/*
) - Used for serving WebAssembly static assetsImplementation Details
ConfigureFrameworkEndpoints
extension method provides a simple way to target framework endpointsThis change provides the "first class support" requested in the issue for targeting framework endpoints without requiring users to understand implementation details or hardcode endpoint patterns.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.