I´m getting a 401 instead of 403 when using Azure Ad for authentication in aspnetcore.
I've set a global policy to RequireAuthenticatedUser, and it works just fine. When I access a any controller in my app, if the user is not authenticated it returns a 401.
I created a custom policy "AdminOnly" and applied it to a controller:
[Authorize (Policy = "AdminOnly")]
public class WebTestController : Controller
{
If the user, is not authenticated, it redirects to https://login.microsoftonline.com/ as expected. If the user is authenticated and fulfills the policy requirements everything goes well, but if the user does not meet the requirements there's problems, and the problem depends on whether options.AutomaticChallenge = true or false. If true, the app get caught up in a loop:
Pieces from debug output:
Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker: Warning: Authorization failed for the request at filter 'Microsoft.AspNet.Mvc.Filters.AuthorizeFilter'.
Microsoft.AspNet.Authentication.OpenIdConnect.OpenIdConnectMiddleware: Information: AuthenticationScheme: OpenIdConnect was challenged.
Microsoft.AspNet.Mvc.ChallengeResult: Information: Executing ChallengeResult with authentication schemes ().
If options.AutomaticChallenge = false, it returns a 401
Hi,
I´m getting a 401 instead of 403 when using Azure Ad for authentication in aspnetcore.
I've set a global policy to RequireAuthenticatedUser, and it works just fine. When I access a any controller in my app, if the user is not authenticated it returns a 401.
I created a custom policy "AdminOnly" and applied it to a controller:
If the user, is not authenticated, it redirects to https://login.microsoftonline.com/ as expected. If the user is authenticated and fulfills the policy requirements everything goes well, but if the user does not meet the requirements there's problems, and the problem depends on whether options.AutomaticChallenge = true or false. If true, the app get caught up in a loop:
Pieces from debug output:
If options.AutomaticChallenge = false, it returns a 401
Any ideas how can I fix this?
Relevant pieces of Startup.cs