Last active
November 25, 2019 14:23
-
-
Save mattbajorek/06a614286568758dabf96ac3334d74c3 to your computer and use it in GitHub Desktop.
Authorization Decorator
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; | |
... | |
// This authorize attribute will be applied to all routes in this controller | |
[Authorize] | |
[Route("api/[controller]")] | |
[ApiController] | |
public class ClapsController : ControllerBase | |
{ | |
// GET api/claps | |
[HttpGet] | |
public ActionResult<int> GetClaps() | |
{ | |
// This will only return 50 if authenticated | |
// Otherwise it will return a status code 401 | |
return 50; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment