diff --git a/aspnetcore/blazor/security/includes/redirecttologin-component.md b/aspnetcore/blazor/security/includes/redirecttologin-component.md index a89e36e7ba4d..6c09b834ffbd 100644 --- a/aspnetcore/blazor/security/includes/redirecttologin-component.md +++ b/aspnetcore/blazor/security/includes/redirecttologin-component.md @@ -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 (, [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 . - Add the following directives at the top of the `RedirectToLogin` component: - - ```razor - @using Microsoft.Extensions.Options - @inject IOptionsSnapshot> 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. - diff --git a/aspnetcore/blazor/security/includes/remote-authentication-paths.md b/aspnetcore/blazor/security/includes/remote-authentication-paths.md new file mode 100644 index 000000000000..c807f826da2a --- /dev/null +++ b/aspnetcore/blazor/security/includes/remote-authentication-paths.md @@ -0,0 +1,27 @@ +Remote authentication paths are customized using on the 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 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> 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. diff --git a/aspnetcore/blazor/security/webassembly/hosted-with-azure-active-directory-b2c.md b/aspnetcore/blazor/security/webassembly/hosted-with-azure-active-directory-b2c.md index 43092547e8e2..ed6f6beb5aae 100644 --- a/aspnetcore/blazor/security/webassembly/hosted-with-azure-active-directory-b2c.md +++ b/aspnetcore/blazor/security/webassembly/hosted-with-azure-active-directory-b2c.md @@ -161,6 +161,12 @@ To configure the app to receive the value from the `name` claim type: }); ``` +## Remote authentication paths + +*This section pertains to the solution's **:::no-loc text="Client":::** app.* + +[!INCLUDE[](~/blazor/security/includes/remote-authentication-paths.md)] + ## Parts of the solution This section describes the parts of a solution generated from the Blazor WebAssembly project template and describes how the solution's **:::no-loc text="Client":::** and **:::no-loc text="Server":::** projects are configured for reference. There's no specific guidance to follow in this section for a basic working application if you created the app using the guidance in the [Walkthrough](#walkthrough) section. The guidance in this section is helpful for updating an app to authenticate and authorize users. However, an alternative approach to updating an app is to create a new app from the guidance in the [Walkthrough](#walkthrough) section and moving the app's components, classes, and resources to the new app. diff --git a/aspnetcore/blazor/security/webassembly/hosted-with-identity-server.md b/aspnetcore/blazor/security/webassembly/hosted-with-identity-server.md index e018f6b845fb..f027ce40ade4 100644 --- a/aspnetcore/blazor/security/webassembly/hosted-with-identity-server.md +++ b/aspnetcore/blazor/security/webassembly/hosted-with-identity-server.md @@ -77,6 +77,12 @@ For more information, see the [`dotnet new`](/dotnet/core/tools/dotnet-new) comm [!INCLUDE[](~/blazor/security/includes/run-the-app.md)] +## Remote authentication paths + +*This section pertains to the solution's **:::no-loc text="Client":::** app.* + +[!INCLUDE[](~/blazor/security/includes/remote-authentication-paths.md)] + ## Parts of the solution This section describes the parts of a solution generated from the Blazor WebAssembly project template and describes how the solution's **:::no-loc text="Client":::** and **:::no-loc text="Server":::** projects are configured for reference. There's no specific guidance to follow in this section for a basic working application if you created the app using the guidance in the [Walkthrough](#walkthrough) section. The guidance in this section is helpful for updating an app to authenticate and authorize users. However, an alternative approach to updating an app is to create a new app from the guidance in the [Walkthrough](#walkthrough) section and moving the app's components, classes, and resources to the new app. diff --git a/aspnetcore/blazor/security/webassembly/hosted-with-microsoft-entra-id.md b/aspnetcore/blazor/security/webassembly/hosted-with-microsoft-entra-id.md index a798309d8534..73d4921ffe52 100644 --- a/aspnetcore/blazor/security/webassembly/hosted-with-microsoft-entra-id.md +++ b/aspnetcore/blazor/security/webassembly/hosted-with-microsoft-entra-id.md @@ -165,6 +165,12 @@ To configure the app to receive the value from the `name` claim type: }); ``` +## Remote authentication paths + +*This section pertains to the solution's **:::no-loc text="Client":::** app.* + +[!INCLUDE[](~/blazor/security/includes/remote-authentication-paths.md)] + ## Parts of the solution This section describes the parts of a solution generated from the Blazor WebAssembly project template and describes how the solution's **:::no-loc text="Client":::** and **:::no-loc text="Server":::** projects are configured for reference. There's no specific guidance to follow in this section for a basic working application if you created the app using the guidance in the [Walkthrough](#walkthrough) section. The guidance in this section is helpful for updating an app to authenticate and authorize users. However, an alternative approach to updating an app is to create a new app from the guidance in the [Walkthrough](#walkthrough) section and moving the app's components, classes, and resources to the new app. diff --git a/aspnetcore/blazor/security/webassembly/standalone-with-authentication-library.md b/aspnetcore/blazor/security/webassembly/standalone-with-authentication-library.md index 10676a462767..83730d47b0bc 100644 --- a/aspnetcore/blazor/security/webassembly/standalone-with-authentication-library.md +++ b/aspnetcore/blazor/security/webassembly/standalone-with-authentication-library.md @@ -123,6 +123,10 @@ Use one of the following approaches to run the app: * Press F5. * .NET CLI command shell: Execute the `dotnet watch` (or `dotnet run`) command from the app's folder. +## Remote authentication paths + +[!INCLUDE[](~/blazor/security/includes/remote-authentication-paths.md)] + ## Parts of the app This section describes the parts of an app generated from the Blazor WebAssembly project template and how the app is configured. There's no specific guidance to follow in this section for a basic working application if you created the app using the guidance in the [Walkthrough](#walkthrough) section. The guidance in this section is helpful for updating an app to authenticate and authorize users. However, an alternative approach to updating an app is to create a new app from the guidance in the [Walkthrough](#walkthrough) section and moving the app's components, classes, and resources to the new app. diff --git a/aspnetcore/blazor/security/webassembly/standalone-with-azure-active-directory-b2c.md b/aspnetcore/blazor/security/webassembly/standalone-with-azure-active-directory-b2c.md index a447002b8e24..edcd6a06e22e 100644 --- a/aspnetcore/blazor/security/webassembly/standalone-with-azure-active-directory-b2c.md +++ b/aspnetcore/blazor/security/webassembly/standalone-with-azure-active-directory-b2c.md @@ -105,6 +105,10 @@ Use one of the following approaches to run the app: * Press F5. * .NET CLI command shell: Execute the `dotnet watch` (or `dotnet run`) command from the app's folder. +## Remote authentication paths + +[!INCLUDE[](~/blazor/security/includes/remote-authentication-paths.md)] + ## Parts of the app This section describes the parts of an app generated from the Blazor WebAssembly project template and how the app is configured. There's no specific guidance to follow in this section for a basic working application if you created the app using the guidance in the [Walkthrough](#walkthrough) section. The guidance in this section is helpful for updating an app to authenticate and authorize users. However, an alternative approach to updating an app is to create a new app from the guidance in the [Walkthrough](#walkthrough) section and moving the app's components, classes, and resources to the new app. diff --git a/aspnetcore/blazor/security/webassembly/standalone-with-microsoft-accounts.md b/aspnetcore/blazor/security/webassembly/standalone-with-microsoft-accounts.md index 33b0b8644c70..a173a9e0aca7 100644 --- a/aspnetcore/blazor/security/webassembly/standalone-with-microsoft-accounts.md +++ b/aspnetcore/blazor/security/webassembly/standalone-with-microsoft-accounts.md @@ -79,6 +79,10 @@ Use one of the following approaches to run the app: * Press F5. * .NET CLI command shell: Execute the `dotnet watch` (or `dotnet run`) command from the app's folder. +## Remote authentication paths + +[!INCLUDE[](~/blazor/security/includes/remote-authentication-paths.md)] + ## Parts of the app This section describes the parts of an app generated from the Blazor WebAssembly project template and how the app is configured. There's no specific guidance to follow in this section for a basic working application if you created the app using the guidance in the [Walkthrough](#walkthrough) section. The guidance in this section is helpful for updating an app to authenticate and authorize users. However, an alternative approach to updating an app is to create a new app from the guidance in the [Walkthrough](#walkthrough) section and moving the app's components, classes, and resources to the new app. @@ -199,6 +203,7 @@ The F5. * .NET CLI command shell: Execute the `dotnet watch` (or `dotnet run`) command from the app's folder. +## Remote authentication paths + +[!INCLUDE[](~/blazor/security/includes/remote-authentication-paths.md)] + ## Parts of the app This section describes the parts of an app generated from the Blazor WebAssembly project template and how the app is configured. There's no specific guidance to follow in this section for a basic working application if you created the app using the guidance in the [Walkthrough](#walkthrough) section. The guidance in this section is helpful for updating an app to authenticate and authorize users. However, an alternative approach to updating an app is to create a new app from the guidance in the [Walkthrough](#walkthrough) section and moving the app's components, classes, and resources to the new app.