Skip to content

Instantly share code, notes, and snippets.

@mattbajorek
Last active November 25, 2019 14:23
Show Gist options
  • Save mattbajorek/06a614286568758dabf96ac3334d74c3 to your computer and use it in GitHub Desktop.
Save mattbajorek/06a614286568758dabf96ac3334d74c3 to your computer and use it in GitHub Desktop.
Authorization Decorator
...
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