I recently set up an auth service within my Blazor MAUI .NET 8 application. The server side code seems to be working well however in my client it seems to not be configured correctly. Whenever I log in as one of the users, I get this error:
Microsoft.AspNetCore.Authorization.DefaultAuthorizationService: Information: Authorization failed. These requirements were not met:
DenyAnonymousAuthorizationRequirement: Requires an authenticated user.
This is my login component:
@inherits LayoutComponentBase
@inject IAuthService AuthService
@inject NavigationManager NavManager
@inject AuthenticationStateProvider AuthStateProvider
@using Components.Models.DTO
@using global::UCMaps.UCMaps
<AuthorizeView>
<Authorized>
</Authorized>
<NotAuthorized>
<LoginForm OnLoginSuccess="HandleLoginSuccess" />
</NotAuthorized>
</AuthorizeView>
@code {
private async Task HandleLoginSuccess()
{
await AuthService.GetAuthenticationStateAsync();
StateHasChanged();
}
}
This is where the error occurs.
In my loginform, it takes in basic user and password to which it calls the AuthService’s Login function, which properly handles the user’s JWT token. Whenever I call my NotifyAuthenticationStateChanged function and debug, I can see that it gives IsAuthenticated = true. The problem is though the rest of my application seems to still remain in an unauthorized stage. I believe that it could be due to a configuration error in my MauiProgram.cs, but it’s hard to find much documentation for Bz Maui net 8 on the topic of authorization.
Here is my github for reference: https://github.com/JaredWalden00/UCMaps