From f6c92719f59730b5fa903fed0758c66448546e2d Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Mon, 25 Aug 2025 11:25:56 -0400 Subject: [PATCH 1/7] Add RedirectToLogin configured login path --- .../includes/redirecttologin-component.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/aspnetcore/blazor/security/includes/redirecttologin-component.md b/aspnetcore/blazor/security/includes/redirecttologin-component.md index dd068389fa03..ef7bc84c221a 100644 --- a/aspnetcore/blazor/security/includes/redirecttologin-component.md +++ b/aspnetcore/blazor/security/includes/redirecttologin-component.md @@ -8,3 +8,21 @@ The `RedirectToLogin` component (`RedirectToLogin.razor`): 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. [!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)] + +The project template uses a well-known login path (`authentication/login`). When the app relies on a login endpoint discovered from the OIDC discovery document (`/.well-known/openid-configuration`), contains the login path. Change the login redirect in the `RedirectToLogin` component to use the configured path, as the following code demonstrates. + +Add the following directives at the top of the `RedirectToLogin` component: + +```razor +@using Microsoft.Extensions.Options +@inject IOptionsSnapshot> Options +``` + +Modify the component's redirect in the `OnInitialized` method: + +```diff +- Navigation.NavigateToLogin("authentication/login"); ++ Navigation.NavigateToLogin( ++ Options.Get(Microsoft.Extensions.Options.Options.DefaultName) ++ .AuthenticationPaths.LogInPath); +``` From 73b40ec098093abc2744676f83a6769f9915aa8e Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Mon, 25 Aug 2025 11:31:24 -0400 Subject: [PATCH 2/7] Updates --- .../blazor/security/includes/redirecttologin-component.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/blazor/security/includes/redirecttologin-component.md b/aspnetcore/blazor/security/includes/redirecttologin-component.md index ef7bc84c221a..0b394b97c66b 100644 --- a/aspnetcore/blazor/security/includes/redirecttologin-component.md +++ b/aspnetcore/blazor/security/includes/redirecttologin-component.md @@ -9,7 +9,7 @@ Inspect the `RedirectToLogin` component in [reference source](https://github.com [!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)] -The project template uses a well-known login path (`authentication/login`). When the app relies on a login endpoint discovered from the OIDC discovery document (`/.well-known/openid-configuration`), contains the login path. Change the login redirect in the `RedirectToLogin` component to use the configured path, as the following code demonstrates. +The project template uses a well-known login path (`authentication/login`). When the app relies on a login endpoint from the OIDC discovery document (`/.well-known/openid-configuration`), contains the login path. Change the login redirect in the `RedirectToLogin` component to use the configured path, as the following code demonstrates. Add the following directives at the top of the `RedirectToLogin` component: From da9543e8eb70cb88887b974b03f2bb14d3679ae4 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Mon, 25 Aug 2025 11:37:17 -0400 Subject: [PATCH 3/7] Updates Updated the injection of options and modified the redirect logic in the OnInitialized method. --- .../blazor/security/includes/redirecttologin-component.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/aspnetcore/blazor/security/includes/redirecttologin-component.md b/aspnetcore/blazor/security/includes/redirecttologin-component.md index 0b394b97c66b..a3ca0051493a 100644 --- a/aspnetcore/blazor/security/includes/redirecttologin-component.md +++ b/aspnetcore/blazor/security/includes/redirecttologin-component.md @@ -15,14 +15,13 @@ Add the following directives at the top of the `RedirectToLogin` component: ```razor @using Microsoft.Extensions.Options -@inject IOptionsSnapshot> Options +@inject IOptionsSnapshot> RemoteOptions ``` Modify the component's redirect in the `OnInitialized` method: ```diff - Navigation.NavigateToLogin("authentication/login"); -+ Navigation.NavigateToLogin( -+ Options.Get(Microsoft.Extensions.Options.Options.DefaultName) ++ Navigation.NavigateToLogin(RemoteOptions.Get(Options.DefaultName) + .AuthenticationPaths.LogInPath); ``` From 6d8de54315f487575cacb4a23d0497843cf3a555 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Thu, 28 Aug 2025 11:22:48 -0400 Subject: [PATCH 4/7] Updates Updated instructions for customizing the login path in the RedirectToLogin component, including code examples for using IOptionsSnapshot. --- .../includes/redirecttologin-component.md | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/aspnetcore/blazor/security/includes/redirecttologin-component.md b/aspnetcore/blazor/security/includes/redirecttologin-component.md index a3ca0051493a..3ee882ffc6e6 100644 --- a/aspnetcore/blazor/security/includes/redirecttologin-component.md +++ b/aspnetcore/blazor/security/includes/redirecttologin-component.md @@ -7,21 +7,30 @@ The `RedirectToLogin` component (`RedirectToLogin.razor`): 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. +Paths can be customized by the WebAssembly app (, [framework defaults (`dotnet/aspnetcore` reference source)](https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs)). The project template uses the well-known, default login path (`authentication/login`). + [!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)] -The project template uses a well-known login path (`authentication/login`). When the app relies on a login endpoint from the OIDC discovery document (`/.well-known/openid-configuration`), contains the login path. Change the login redirect in the `RedirectToLogin` component to use the configured path, as the following code demonstrates. +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 to obtain the configured value. For example, take this approach when you customize the path with and don't want to duplicate hard-coded string literals across the app's codebase. + + Add the following directives at the top of the `RedirectToLogin` component: -Add the following directives at the top of the `RedirectToLogin` component: + ```razor + @using Microsoft.Extensions.Options + @inject IOptionsSnapshot> RemoteOptions + ``` -```razor -@using Microsoft.Extensions.Options -@inject IOptionsSnapshot> RemoteOptions -``` + Modify the component's redirect in the `OnInitialized` method: -Modify the component's redirect in the `OnInitialized` method: + ```diff + - Navigation.NavigateToLogin("authentication/login"); + + Navigation.NavigateToLogin(RemoteOptions.Get(Options.DefaultName) + + .AuthenticationPaths.LogInPath); + ``` -```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. + From 2e76bfce51cc3ef93fb57c1ca8be9ab458a5bb09 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Thu, 28 Aug 2025 11:25:17 -0400 Subject: [PATCH 5/7] Updates Updated the text to clarify the default login path format. --- .../blazor/security/includes/redirecttologin-component.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/blazor/security/includes/redirecttologin-component.md b/aspnetcore/blazor/security/includes/redirecttologin-component.md index 3ee882ffc6e6..8cc1139d4e8b 100644 --- a/aspnetcore/blazor/security/includes/redirecttologin-component.md +++ b/aspnetcore/blazor/security/includes/redirecttologin-component.md @@ -7,7 +7,7 @@ The `RedirectToLogin` component (`RedirectToLogin.razor`): 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. -Paths can be customized by the WebAssembly app (, [framework defaults (`dotnet/aspnetcore` reference source)](https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs)). The project template uses the well-known, default login path (`authentication/login`). +Paths can be customized by the WebAssembly app (, [framework defaults (`dotnet/aspnetcore` reference source)](https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs)). The project template uses the well-known, default login path `authentication/login`. [!INCLUDE[](~/includes/aspnetcore-repo-ref-source-links.md)] From 2b5b75597b0522a21fcb60c0924e75e21b7f3691 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Thu, 28 Aug 2025 11:32:19 -0400 Subject: [PATCH 6/7] Updates --- .../blazor/security/includes/redirecttologin-component.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aspnetcore/blazor/security/includes/redirecttologin-component.md b/aspnetcore/blazor/security/includes/redirecttologin-component.md index 8cc1139d4e8b..9594f659cfa5 100644 --- a/aspnetcore/blazor/security/includes/redirecttologin-component.md +++ b/aspnetcore/blazor/security/includes/redirecttologin-component.md @@ -7,14 +7,14 @@ The `RedirectToLogin` component (`RedirectToLogin.razor`): 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. -Paths can be customized by the WebAssembly app (, [framework defaults (`dotnet/aspnetcore` reference source)](https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebAssembly/WebAssembly.Authentication/src/RemoteAuthenticationDefaults.cs)). The project template uses the well-known, default login path `authentication/login`. +The login path can be customized by the app (, [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 well-known, default, hard-coded 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 to obtain the configured value. For example, take this approach when you customize the path with and don't want to duplicate hard-coded string literals across the app's codebase. +* Inject to obtain the configured value. For example, take this approach when you customize the path with to avoid hard-coded string literals across the app's codebase. Add the following directives at the top of the `RedirectToLogin` component: From f19eabd1ad957d659463f11ed818ace958c75da1 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Wed, 3 Sep 2025 12:17:01 -0400 Subject: [PATCH 7/7] Apply suggestions from code review Co-authored-by: Mackinnon Buck --- .../blazor/security/includes/redirecttologin-component.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/aspnetcore/blazor/security/includes/redirecttologin-component.md b/aspnetcore/blazor/security/includes/redirecttologin-component.md index 9594f659cfa5..e7d0848fe0e1 100644 --- a/aspnetcore/blazor/security/includes/redirecttologin-component.md +++ b/aspnetcore/blazor/security/includes/redirecttologin-component.md @@ -7,15 +7,14 @@ The `RedirectToLogin` component (`RedirectToLogin.razor`): 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 (, [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 well-known, default, hard-coded login path of `authentication/login`. +The login path can be customized by the app (, [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 to obtain the configured value. For example, take this approach when you customize the path with to avoid hard-coded string literals across the app's codebase. - +* Inject to obtain the configured value. For example, take this approach when you customize the path with . Add the following directives at the top of the `RedirectToLogin` component: ```razor