#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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user