Reputation: 733
I have a web api project where:
The 1st one is easy as the JWT authentication middleware will handle it but how can I achieve the other 2?
Upvotes: 0
Views: 75
Reputation: 1954
2). Add the [AllowAnonymous] attribute to the endpoint or the controller to turn off authentication for that endpoint/controller.
3). You will need to do a check on the Users Claims (provided you have added the different permissions into there - and the apply logic to your return values depending on those values. If you return an IHttpActionResult like so, you can dynamically change the return values depending on your logic.
public IHttpActionResult GetProduct(int id)
{
var product = products.FirstOrDefault((p) => p.Id == id);
if (product == null)
{
return NotFound();
}
return Ok(product);
}
Upvotes: 1