#1 : Test de Keycloak.
This commit is contained in:
49
Webzine.WebApplication/Controllers/AccountController.cs
Normal file
49
Webzine.WebApplication/Controllers/AccountController.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
namespace Webzine.WebApplication.Controllers
|
||||
{
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
public class AccountController : Controller
|
||||
{
|
||||
[HttpGet("/account/login")]
|
||||
public IActionResult Login(string? returnUrl = "/")
|
||||
{
|
||||
return this.Challenge(
|
||||
new AuthenticationProperties
|
||||
{
|
||||
RedirectUri = string.IsNullOrWhiteSpace(returnUrl) ? "/" : returnUrl,
|
||||
},
|
||||
OpenIdConnectDefaults.AuthenticationScheme);
|
||||
}
|
||||
|
||||
[HttpGet("/account/logout")]
|
||||
public IActionResult Logout()
|
||||
{
|
||||
return this.SignOut(
|
||||
new AuthenticationProperties
|
||||
{
|
||||
RedirectUri = "/",
|
||||
},
|
||||
CookieAuthenticationDefaults.AuthenticationScheme,
|
||||
OpenIdConnectDefaults.AuthenticationScheme);
|
||||
}
|
||||
|
||||
[HttpGet("/account/access-denied")]
|
||||
public IActionResult AccessDenied()
|
||||
{
|
||||
return this.View();
|
||||
}
|
||||
|
||||
[HttpGet("/account/auth-error")]
|
||||
public IActionResult AuthError(string? message = null)
|
||||
{
|
||||
this.ViewData["Message"] = string.IsNullOrWhiteSpace(message)
|
||||
? "Une erreur est survenue pendant la connexion."
|
||||
: message;
|
||||
|
||||
return this.View();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
namespace Webzine.WebApplication.Controllers
|
||||
{
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Webzine.Repository.Contracts;
|
||||
@@ -38,6 +39,7 @@
|
||||
/// </summary>
|
||||
/// <param name="page">Le numéro de page pour la pagination des titres (par défaut à 0).</param>
|
||||
/// <returns>La vue Index avec le ViewModel contenant les listes de titres à afficher.</returns>
|
||||
[Authorize(Roles = "ADMIN")]
|
||||
public IActionResult Index(int page = 0)
|
||||
{
|
||||
this.logger.LogInformation("Arrivée sur la page d'accueil");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
namespace Webzine.WebApplication.Controllers
|
||||
{
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Webzine.Repository.Contracts;
|
||||
@@ -33,6 +34,7 @@
|
||||
/// </summary>
|
||||
/// <param name="nom">Le nom de l'artiste à rechercher, formaté en kebab-case (ex: "fatal-bazooka").</param>
|
||||
/// <returns>La vue de l'artiste avec son ViewModel, ou une redirection vers l'accueil si le nom est vide, ou une erreur 404 si l'artiste n'est pas trouvé.</returns>
|
||||
[Authorize(Roles = "ADMIN")]
|
||||
public IActionResult Index(string nom)
|
||||
{
|
||||
this.logger.LogInformation("Tentative d'accès à l'artiste avec le nom : {NomArtiste}", nom);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
namespace Webzine.WebApplication.Controllers
|
||||
{
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
/// <summary>
|
||||
@@ -25,6 +26,7 @@
|
||||
/// Affiche la page de contact du webzine.
|
||||
/// </summary>
|
||||
/// <returns>La vue Index de la page de contact.</returns>
|
||||
[Authorize(Roles = "ADMIN")]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return this.View();
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
namespace Webzine.WebApplication.Controllers
|
||||
{
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Webzine.Repository.Contracts;
|
||||
@@ -39,6 +40,7 @@ namespace Webzine.WebApplication.Controllers
|
||||
/// </summary>
|
||||
/// <param name="mot">Nom d'artiste ou de titre.</param>
|
||||
/// <returns>Page de recherche avec les r<>sultats.</returns>
|
||||
[Authorize(Roles = "ADMIN")]
|
||||
public IActionResult Index(string mot)
|
||||
{
|
||||
// Logger la recherche.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
namespace Webzine.WebApplication.Controllers
|
||||
{
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Webzine.Entity;
|
||||
@@ -47,6 +48,7 @@ namespace Webzine.WebApplication.Controllers
|
||||
/// <param name="id">Identifiant du titre.</param>
|
||||
/// <param name="model">Model de donnée pour un commentaire.</param>
|
||||
/// <returns>Vue des details ou 404 si introuvable.</returns>
|
||||
[Authorize(Roles = "ADMIN")]
|
||||
public IActionResult Index(int id)
|
||||
{
|
||||
this.logger.LogInformation("Demande d'affichage du detail pour le titre ID {Id}.", id);
|
||||
|
||||
Reference in New Issue
Block a user