For a Blazor server hosted page - is it possible to require authentication? Based on the following documentation:
https://docs.microsoft.com/en-au/aspnet/core/security/authorization/policies?view=aspnetcore-3.0
I've added the following to my Startup.cs
:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion( CompatibilityVersion.Version_2_2 );
services.AddAuthorization(options =>
{
options.AddPolicy("Private", policy => policy.RequireAuthenticatedUser() );
});
}
And here's what I've put at the top of the fetchdata
page:
@page "/fetchdata"
@using HollyTest.Data
@inject WeatherForecastService ForecastService
@attribute [Authorize(Policy="Private")]
<h1>Weather forecast</h1>
<p>This component demonstrates fetching data from a service.</p>
Can someone tell me if I'm on the right track?