I am trying to use the ServerAuthenticationStateProvider in my current project, since we are using Blazor Server. Before we just used the base AuthenticationStateProvider, which also seems to work with Windows Identity. ServerAuthenticationStateProvider does not work properly though.
I register the provider in Program.cs
builder.Services.AddServerSideBlazor();builder.Services.AddScoped<ServerAuthenticationStateProvider>();In my components (*.razor.cs) I use it like this:
[Inject] public ServerAuthenticationStateProvider AuthenticationStateProvider { get; set; } = default!;But this throws an exception when accessing the page with a component:
System.InvalidOperationException: GetAuthenticationStateAsync was called before SetAuthenticationState. at Microsoft.AspNetCore.Components.Server.ServerAuthenticationStateProvider.GetAuthenticationStateAsync()I am not sure why this error happens. The Microsoft docs are also not clear on how to use this ServerAuthenticationStateProvider, so it might be doing something wrong.