Skip to content

Instantly share code, notes, and snippets.

@wellingtonjhn
Created May 29, 2018 22:06
Show Gist options
  • Save wellingtonjhn/23be96bf91632833090e7dac2f519bbd to your computer and use it in GitHub Desktop.
Save wellingtonjhn/23be96bf91632833090e7dac2f519bbd to your computer and use it in GitHub Desktop.
Authorize Attribute with Policy
[Route("api/[controller]"), Authorize(Roles = "Administrator")]
public class AdministrationController : Controller
{
// ... restante do código omitido
[HttpDelete, Route("accounts/{accountId}"), Authorize(Policy = "DeleteUserPolicy")]
public async Task<IActionResult> DeleteAccount(Guid accountId)
{
var command = new RemoveAccount(accountId);
var response = await _mediator.Send(command);
if (response.HasMessages)
{
return BadRequest(response.Messages);
}
return Ok();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment