Understanding
Today I was reading about 401
vs 403
Status Codes. I came across an interesting post on SO which can be seen here.
As per post, my understanding is
401
- Authentication failed.403
- Authorization failed.
Use Case
In .Net Core Web API
, I used UnauthorizedResult
in one of the custom filter (I know filters are not preferred way to go for authorization checks but that is a separate discussion altogether). This ActionResult
do return 401
Status Code however I expected it to return 403 as per above mentioned post as it is Authorization failure and not Authentication. Interface used is also IAuthorizationFilter
.
Question
Should not UnauthorizedResult
return 403
instead of 401
? Am I missing something on above understanding?
Side Note
To solve the problem, I used StatusCodes.Status403Forbidden
to return 403
.