-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from marcominerva/develop
Add permisison-based authorization
- Loading branch information
Showing
31 changed files
with
536 additions
and
186 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
54 changes: 54 additions & 0 deletions
54
samples/Controllers/JwtBearerSample/Controllers/PeopleController.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System.Net.Mime; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using SimpleAuthentication.Permissions; | ||
using Swashbuckle.AspNetCore.Annotations; | ||
|
||
namespace JwtBearerSample.Controllers; | ||
|
||
[Authorize] | ||
[ApiController] | ||
[Route("api/[controller]")] | ||
[Produces(MediaTypeNames.Application.Json)] | ||
public class PeopleController : ControllerBase | ||
{ | ||
[Permissions(Permissions.PeopleRead, Permissions.PeopleAdmin)] | ||
[HttpGet] | ||
[SwaggerOperation(description: $"This endpoint requires the '{Permissions.PeopleRead}' or '{Permissions.PeopleAdmin}' permissions")] | ||
public IActionResult GetList() => NoContent(); | ||
|
||
[Permissions(Permissions.PeopleRead, Permissions.PeopleAdmin)] | ||
[HttpGet("{id:int}")] | ||
[ProducesResponseType(StatusCodes.Status204NoContent)] | ||
[ProducesDefaultResponseType] | ||
[SwaggerOperation(description: $"This endpoint requires the '{Permissions.PeopleRead}' or '{Permissions.PeopleAdmin}' permissions")] | ||
public IActionResult GetPerson(int id) => NoContent(); | ||
|
||
[Permissions(Permissions.PeopleWrite)] | ||
[HttpPost] | ||
[ProducesResponseType(StatusCodes.Status204NoContent)] | ||
[ProducesDefaultResponseType] | ||
[SwaggerOperation(description: $"This endpoint requires the '{Permissions.PeopleWrite}' permission")] | ||
public IActionResult Insert() => NoContent(); | ||
|
||
[Permissions(Permissions.PeopleWrite)] | ||
[HttpPut] | ||
[ProducesResponseType(StatusCodes.Status204NoContent)] | ||
[ProducesDefaultResponseType] | ||
[SwaggerOperation(description: $"This endpoint requires the '{Permissions.PeopleWrite}' permission")] | ||
public IActionResult Update() => NoContent(); | ||
|
||
[Permissions(Permissions.PeopleAdmin)] | ||
[HttpDelete("{id:int}")] | ||
[ProducesResponseType(StatusCodes.Status204NoContent)] | ||
[ProducesDefaultResponseType] | ||
[SwaggerOperation(description: $"This endpoint requires the '{Permissions.PeopleAdmin}' permission")] | ||
public IActionResult Delete(int id) => NoContent(); | ||
} | ||
|
||
public static class Permissions | ||
{ | ||
public const string PeopleRead = "people:read"; | ||
public const string PeopleWrite = "people:write"; | ||
public const string PeopleAdmin = "people:admin"; | ||
} |
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ public Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal) | |
|
||
return Task.FromResult(principal); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.