Removed the previous Login method from AuthController, including its XML documentation and Swagger/OpenAPI annotations. This prepares the controller for a revised authentication implementation.
59 lines
2.2 KiB
C#
59 lines
2.2 KiB
C#
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using EnvelopeGenerator.API.Models;
|
|
|
|
namespace EnvelopeGenerator.API.Controllers;
|
|
|
|
/// <summary>
|
|
/// Controller verantwortlich für die Benutzer-Authentifizierung, einschließlich Anmelden, Abmelden und Überprüfung des Authentifizierungsstatus.
|
|
/// </summary>
|
|
/// <param name="logger"></param>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public partial class AuthController(ILogger<AuthController> logger) : ControllerBase
|
|
{
|
|
|
|
/// <summary>
|
|
/// Entfernt das Authentifizierungs-Cookie des Benutzers (AuthCookie)
|
|
/// </summary>
|
|
/// <returns>
|
|
/// Gibt eine HTTP 200 oder 401.
|
|
/// </returns>
|
|
/// <remarks>
|
|
/// Sample request:
|
|
///
|
|
/// POST /api/auth/logout
|
|
///
|
|
/// </remarks>
|
|
/// <response code="200">Erfolgreich gelöscht, wenn der Benutzer ein berechtigtes Cookie hat.</response>
|
|
/// <response code="401">Wenn es kein zugelassenes Cookie gibt, wird „nicht zugelassen“ zurückgegeben.</response>
|
|
[ProducesResponseType(typeof(string), StatusCodes.Status200OK, "text/javascript")]
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
[Authorize]
|
|
[HttpPost("logout")]
|
|
public async Task<IActionResult> Logout()
|
|
{
|
|
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
|
|
return Ok();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Prüft, ob der Benutzer ein autorisiertes Token hat.
|
|
/// </summary>
|
|
/// <returns>Wenn ein autorisiertes Token vorhanden ist HTTP 200 asynchron 401</returns>
|
|
/// <remarks>
|
|
/// Sample request:
|
|
///
|
|
/// GET /api/auth
|
|
///
|
|
/// </remarks>
|
|
/// <response code="200">Wenn es einen autorisierten Cookie gibt.</response>
|
|
/// <response code="401">Wenn kein Cookie vorhanden ist oder nicht autorisierte.</response>
|
|
[ProducesResponseType(typeof(string), StatusCodes.Status200OK, "text/javascript")]
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
[Authorize]
|
|
[HttpGet]
|
|
public IActionResult IsAuthenticated() => Ok();
|
|
} |