Let’s say that we obtained the JWT from the LOGIN API.
I have an API_ACTION.
From your code (a part of ValidAPIRequest function) I don’t understand how I can I check the JWT obtained from the LOGIN API.
I tried to do this: this is my code. It is always valid even if I dont pass the “Authorization” header or if I pass a wrong JWT. What is wrong?
public class GetTableController : ApiController {
[HttpPost]
public IActionResult Post(object jsonData) {
var security = ResolveSecurity();
if (IsApi()) { // API
myLogger("THIS IS API CALL");
if (ValidApiRequest()) {
myLogger("THIS IS A VALID API REQUEST");
//So here I can run my AUTHENTICATED code block
} else {
myLogger("THIS IS A NOT VALID API REQUEST");
return Ok(new {success=false, message="NO VALID REQUEST"});
}
} else {
myLogger("NO IS API");
return Ok(new {success=false, message="NO VALID REQUEST"});
}
}
}
The security.IsLogged is from Advanced Security of ASP.NET Maker, not related to JWT. To check JWT also,In v2021, you can try using attribute for your controller:
This is my code modified as suggested (ANM 2021)
It gives to me the following error. I haven’t found in ANM source any reference to JwtUserLevel… maybe ApiUserLevel?System.InvalidOperationException: The AuthorizationPolicy named: ‘JwtUserLevel’ was not found.
It should be: (both v2021 and v2022)[Authorize(Policy = “ApiUserLevel”)]You better open your project in Visual Studio 2022 to test and debug your codes directly.