-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Blazor WASM remote auth path option config #37012
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
guardrex
merged 5 commits into
main
from
guardrex/blazor-remoteauthenticationapplicationpathsoptions
Apr 16, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bbd787d
Additional coverage on remote auth paths
guardrex 420272c
Updates
guardrex 0953bc9
Apply suggestions from code review
guardrex e38c99d
Apply suggestions from code review
guardrex a02f82e
Clarify URL maintenance in RedirectToLogin component
guardrex 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
29 changes: 1 addition & 28 deletions
29
aspnetcore/blazor/security/includes/redirecttologin-component.md
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 |
|---|---|---|
| @@ -1,35 +1,8 @@ | ||
| The `RedirectToLogin` component (`RedirectToLogin.razor`): | ||
|
|
||
| * Manages redirecting unauthorized users to the login page. | ||
| * The current URL that the user is attempting to access is maintained by so that they can be returned to that page if authentication is successful using: | ||
| * The current URL that the user is attempting to access is maintained so that they can be returned to that page if authentication is successful using: | ||
| * [Navigation history state](xref:blazor/fundamentals/navigation#navigation-history-state) in ASP.NET Core in .NET 7 or later. | ||
| * A query string in ASP.NET Core in .NET 6 or earlier. | ||
|
|
||
| Inspect the `RedirectToLogin` component in [reference source](https://github.com/dotnet/aspnetcore/tree/main/src/ProjectTemplates/Web.ProjectTemplates/content/ComponentsWebAssembly-CSharp). The location of the component changed over time, so use GitHub search tools to locate the component. | ||
|
|
||
| The login path can be customized by the app (<xref:Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationApplicationPathsOptions.LogInPath%2A?displayProperty=nameWithType>, [framework defaults (`dotnet/aspnetcore` reference source)](https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs)). The project template's `RedirectToLogin` component uses the default login path of `authentication/login`. | ||
|
|
||
| [!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)] | ||
|
|
||
| If an app [customizes the login path](xref:blazor/security/webassembly/additional-scenarios#customize-app-routes), take either of the following approaches: | ||
|
|
||
| * Match the path in the hard-coded string in the `RedirectToLogin` component. | ||
| * Inject <xref:Microsoft.AspNetCore.Builder.RemoteAuthenticationOptions> to obtain the configured value. For example, take this approach when you customize the path with <xref:Microsoft.Extensions.DependencyInjection.WebAssemblyAuthenticationServiceCollectionExtensions.AddApiAuthorization%2A>. | ||
| Add the following directives at the top of the `RedirectToLogin` component: | ||
|
|
||
| ```razor | ||
| @using Microsoft.Extensions.Options | ||
| @inject IOptionsSnapshot<RemoteAuthenticationOptions<ApiAuthorizationProviderOptions>> RemoteOptions | ||
| ``` | ||
|
|
||
| Modify the component's redirect in the `OnInitialized` method: | ||
|
|
||
| ```diff | ||
| - Navigation.NavigateToLogin("authentication/login"); | ||
| + Navigation.NavigateToLogin(RemoteOptions.Get(Options.DefaultName) | ||
| + .AuthenticationPaths.LogInPath); | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > If other paths differ from the project template's paths or [framework's default paths](https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs), they should managed in the same fashion. | ||
|
|
27 changes: 27 additions & 0 deletions
27
aspnetcore/blazor/security/includes/remote-authentication-paths.md
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,27 @@ | ||
| Remote authentication paths are customized using <xref:Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationApplicationPathsOptions> on the <xref:Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationOptions%601.AuthenticationPaths%2A?displayProperty=nameWithType> property in the app's `Program` file. For the framework's default path values, see the [`dotnet/aspnetcore` reference source](https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs). | ||
|
|
||
| [!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)] | ||
|
|
||
| If an app [customizes a remote authentication path](xref:blazor/security/webassembly/additional-scenarios#customize-app-routes), take either of the following approaches: | ||
|
|
||
| * Match the path in hard-coded strings around the app. | ||
|
|
||
| * Inject <xref:Microsoft.AspNetCore.Components.WebAssembly.Authentication.RemoteAuthenticationOptions%601?displayProperty=nameWithType> to obtain the configured value around the app. The following example demonstrates the approach for the [`RedirectToLogin` component](#redirecttologin-component). | ||
|
|
||
| Add the following Razor directives to the top of the component's Razor file: | ||
|
|
||
| ```razor | ||
| @using Microsoft.Extensions.Options | ||
| @inject IOptionsSnapshot<RemoteAuthenticationOptions<ApiAuthorizationProviderOptions>> RemoteOptions | ||
| ``` | ||
|
|
||
| Modify the component's redirect in the `OnInitialized` method: | ||
|
|
||
| ```diff | ||
| - Navigation.NavigateToLogin("authentication/login"); | ||
| + Navigation.NavigateToLogin(RemoteOptions.Get(Options.DefaultName) | ||
| + .AuthenticationPaths.LogInPath); | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > If other paths differ from the project template's paths or [framework's default paths](https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs), manage them in the same fashion. | ||
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
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
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
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
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
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
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
Oops, something went wrong.
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.