Created
July 24, 2018 08:47
-
-
Save jinhduong/eef85ea9974808e80aefc8ffc99c8b38 to your computer and use it in GitHub Desktop.
aspnetcore authorization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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