Configure authentication in program.cs and endpoints

This commit is contained in:
Oscar Morales
2025-07-15 17:21:08 -06:00
parent 3511043209
commit a14cec8fb1
8 changed files with 100 additions and 68 deletions

View File

@@ -24,6 +24,7 @@ namespace LSA.Core.Thalos.API.Controllers
[Produces(MimeTypes.ApplicationJson)]
[Consumes(MimeTypes.ApplicationJson)]
[ApiController]
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
public class RoleController(IRoleProvider service) : ControllerBase
{
/// <summary>
@@ -35,8 +36,7 @@ namespace LSA.Core.Thalos.API.Controllers
/// <response code="500">The service internal error.</response>
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<RoleAdapter>), StatusCodes.Status200OK)]
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
//[Permission("RoleManagement.Read")]
[Permission("RoleManagement.Read")]
public async Task<IActionResult> GetAllRolesAsync(CancellationToken cancellationToken)
{
var result = await service.GetAllRoles(cancellationToken).ConfigureAwait(false);
@@ -54,8 +54,7 @@ namespace LSA.Core.Thalos.API.Controllers
[HttpGet]
[Route(Routes.Id)]
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
//[Permission("RoleManagement.Read")]
[Permission("RoleManagement.Read")]
public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string id, CancellationToken cancellationToken)
{
var result = await service.GetRoleById(id, cancellationToken).ConfigureAwait(false);
@@ -78,8 +77,7 @@ namespace LSA.Core.Thalos.API.Controllers
/// <response code="500">The service internal error.</response>
[HttpPost]
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status201Created)]
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
//[Permission("RoleManagement.Write")]
[Permission("RoleManagement.Write")]
public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole, CancellationToken cancellationToken)
{
var result = await service.CreateRole(newRole, cancellationToken).ConfigureAwait(false);
@@ -99,8 +97,7 @@ namespace LSA.Core.Thalos.API.Controllers
[HttpPut]
[Route(Routes.Id)]
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
//[Permission("RoleManagement.Write")]
[Permission("RoleManagement.Write")]
public async Task<IActionResult> UpdateRoleAsync([FromRoute] string id, [FromBody] RoleAdapter entity, CancellationToken cancellationToken)
{
if (id != entity.Id?.ToString())
@@ -126,8 +123,7 @@ namespace LSA.Core.Thalos.API.Controllers
[HttpPatch]
[Route(Routes.ChangeStatus)]
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
//[Permission("RoleManagement.Write")]
[Permission("RoleManagement.Write")]
public async Task<IActionResult> ChangeRoleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
{
var result = await service.ChangeRoleStatus(id, newStatus, cancellationToken).ConfigureAwait(false);
@@ -146,8 +142,7 @@ namespace LSA.Core.Thalos.API.Controllers
/// <response code="500">The service internal error.</response>
[HttpPost(Routes.AddApplication)]
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
//[Permission("RoleManagement.Write")]
[Permission("RoleManagement.Write")]
public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken)
{
var result = await service.AddApplicationToRole(roleId, application, cancellationToken).ConfigureAwait(false);
@@ -166,8 +161,7 @@ namespace LSA.Core.Thalos.API.Controllers
/// <response code="500">The service internal error.</response>
[HttpDelete(Routes.RemoveApplication)]
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
//[Permission("RoleManagement.Write")]
[Permission("RoleManagement.Write")]
public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken)
{
var result = await service.RemoveApplicationFromRole(roleId, application, cancellationToken).ConfigureAwait(false);