'How to check authorize based on field?
I have a controller method and usually check make Authorize like this:
[HttpGet]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Policy = "Policy")]
public async Task<IActionResult> Get(SomeType someObject)
{
return Ok();
}
Question: I need to Authorize based on RequireAuth field in someObject(passed in method), for example, if someObject.RequireAuth == true, then we need to apply
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Policy = "Policy")]
If someObject.RequireAuth == false, then [AllowAnonymous]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
