I'm building an Api with Jwt token auth, in my refresh token method i validate the token using the official JwtSecurityTokenHandler.ValidateToken() method then i go and get the user from the DB. My question is in the case that the validation was successfull, but the user was not found should i return a 404 user not found or a 401 Unauthorized?
A 404 because
- The correct response for Resource not found
- Because we know the token is valid we can give a more descriptive error without worrying as much abt security
A 401 because
- Consistent error response regardless of reason
- doesn't reveal to much like 404, so its safer
- Since the user was not found during authentication, even if token is valid it is still 401 Unauthorized
link to JwtSecurityTokenHandler.ValidateToken() microsoft docs: https://learn.microsoft.com/en-us/dotnet/api/system.identitymodel.tokens.jwt.jwtsecuritytokenhandler.validatetoken?view=msal-web-dotnet-latest
I'm learning so please go easy, Thank you