feat(TFARegController): Logout-Methode hinzugefügt

This commit is contained in:
Developer 02 2025-02-11 16:13:24 +01:00
parent b79bc2e418
commit 3d5053d177

View File

@ -9,11 +9,13 @@ using DigitalData.Core.DTO;
using EnvelopeGenerator.Application.Extensions; using EnvelopeGenerator.Application.Extensions;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using static EnvelopeGenerator.Common.Constants;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication;
namespace EnvelopeGenerator.Web.Controllers; namespace EnvelopeGenerator.Web.Controllers;
//TODO: Add authorization as well as limiting the link duration (intermediate token with different role) or sign it //TODO: Add authorization as well as limiting the link duration (intermediate token with different role) or sign it
[Route("tfa")]
public class TFARegController : ViewControllerBase public class TFARegController : ViewControllerBase
{ {
private readonly IEnvelopeReceiverService _envRcvService; private readonly IEnvelopeReceiverService _envRcvService;
@ -29,8 +31,9 @@ public class TFARegController : ViewControllerBase
_params = tfaRegParamsOptions.Value; _params = tfaRegParamsOptions.Value;
} }
//TODO: move under auth route
[Authorize] [Authorize]
[HttpGet("{envelopeReceiverId}")] [HttpGet("tfa/{envelopeReceiverId}")]
public async Task<IActionResult> Reg(string envelopeReceiverId) public async Task<IActionResult> Reg(string envelopeReceiverId)
{ {
try try
@ -84,4 +87,20 @@ public class TFARegController : ViewControllerBase
return this.ViewInnerServiceError(); return this.ViewInnerServiceError();
} }
} }
[Authorize(Roles = ReceiverRole.FullyAuth)]
[HttpPost("auth/logout")]
public async Task<IActionResult> LogOut()
{
try
{
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return Ok();
}
catch(Exception ex)
{
_logger.LogError(ex, "{message}", ex.Message);
return this.ViewInnerServiceError();
}
}
} }