To simplify my life I've disabled the authorization policy for all the controllers in a .Net Core 3.1 Web API project when the environment is equal to development by adding some configuration in the startup file.
The controllers are secured by adding [Authorize(AuthenticationSchemes = "Bearer")]
on top of them.
Everything works fine, but there is also some piece of code inside all actions of the controllers that retrieve the username of the logged user to log the request.
Is there a way to check inside the method if the controller requires authorization (I'm in production) or not (I'm in development)?
This will be useful also for unit testing.