I am currently implementing the OAuth2.0 authentication and authorization with AzureAD in my Blazor application, and I’m facing some troubles.
For example, if the logged in user is not authenticated to access the ‘Admin’ page, it gets redirected to https://localhost:7155/MicrosoftIdentity/Account/AccessDenied?ReturnUrl=admin
, and gives me 404 response. What I want it to happen is to get redirected to https://localhost:7155/AccessDenied
instead.
I put the attribute
@attribute[Route("Admin")]
@attribute [Authorize(Policy = "Admin")]
on top of the .razor page that I’m working on right now.
In Routes.razor, I also added the following:
<Found Context="routeData">
<AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" >
<NotAuthorized>
<AccessDenied />
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<AccessDenied />
</NotFound>
Any suggestion/idea would be appreciated.