Skip to content

Instantly share code, notes, and snippets.

@jinhduong
Created July 24, 2018 08:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jinhduong/eef85ea9974808e80aefc8ffc99c8b38 to your computer and use it in GitHub Desktop.
aspnetcore authorization
namespace Demo.WebApi.Controllers
{
// SIMPLE AUTHORIZATION
[Authorize]
[Route("api/[controller]")]
public class AccountController : Controller
{
public AccountController()
{
}
// ROLE-BASED AUTHORIZATION
[Authorize(Roles = "Administrator")]
[HttpGet("all")]
public async Task<IActionResult> GetAll()
{
return Ok();
}
// POLICY-BASED AUTHORIZATION
// CLAIM-BASE AUTHORIZATION (inherit from POLICY-BASED AUTHORIZATION)
[Authorize(Policy = "EmployeeOnly")]
[HttpGet("all")]
public async Task<IActionResult> GetAll()
{
return Ok();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment