Last active
May 10, 2020 02:08
-
-
Save mattbajorek/bc293fcf0b37a6e6eaaa1b55b4733e4f to your computer and use it in GitHub Desktop.
Policy Based Authorization
This file contains 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
... | |
using Microsoft.AspNetCore.Authorization; | |
... | |
[Authorize] | |
[Route("api/[controller]")] | |
[ApiController] | |
public class ClapsController : ControllerBase | |
{ | |
... | |
// This policy will only apply to this specific route | |
[Authorize(Policy = "Admin")] | |
// GET api/claps/9000 | |
[HttpGet("{id}")] | |
public ActionResult<int> GetClaps(int id) | |
{ | |
// This will only return 9000 (ITS OVER 9000) if authenticated and is an Admin | |
// Otherwise it will return a status code 401 | |
return id; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment