I have two different types of JWTs that my .Net Core 3.1 Web API service can use to authenticate.
The service operations of my controller sometimes require that one or both are present. Sometimes they can be called by anyone (without either JWT).
The only attribute I can see that I can apply to a service operation in my controller is the Authorize
attribute. I have looked into use that attribute (or a custom one), but I am running in to problems.
It seems that the Authorize
attribute cannot change the HTTP Status Code that is returned. In my case, if my service is called without the valid JWT, I need to return a 401 Http Status Code.
How can I conditionally require a service operation in my controller to require authentication and return a 401?