From ef325aa1e44222685dc33a0d4ddc322eab4634fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Sun, 1 Sep 2024 10:47:01 +0200 Subject: [PATCH] Do not limit the error controller to a specific HTTP method --- .../Controllers/ErrorController.cs | 22 +++++++++---------- .../Controllers/ErrorController.cs | 22 +++++++++---------- .../Controllers/ErrorController.cs | 19 ++++++++-------- .../Controllers/ErrorController.cs | 20 ++++++++--------- 4 files changed, 38 insertions(+), 45 deletions(-) diff --git a/samples/Dantooine/Dantooine.Server/Controllers/ErrorController.cs b/samples/Dantooine/Dantooine.Server/Controllers/ErrorController.cs index 94e00f076..86e4b0289 100644 --- a/samples/Dantooine/Dantooine.Server/Controllers/ErrorController.cs +++ b/samples/Dantooine/Dantooine.Server/Controllers/ErrorController.cs @@ -4,30 +4,28 @@ * the license and the contributors participating to this project. */ +using Dantooine.Server.ViewModels.Shared; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Mvc; -using Dantooine.Server.ViewModels.Shared; namespace Dantooine.Server.Controllers; public class ErrorController : Controller { - [Route("error")] - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true), Route("~/error")] public IActionResult Error() { - // If the error was not caused by an invalid - // OIDC request, display a generic error page. + // If the error originated from the OpenIddict server, render the error details. var response = HttpContext.GetOpenIddictServerResponse(); - if (response == null) + if (response is not null) { - return View(new ErrorViewModel()); + return View(new ErrorViewModel + { + Error = response.Error, + ErrorDescription = response.ErrorDescription + }); } - return View(new ErrorViewModel - { - Error = response.Error, - ErrorDescription = response.ErrorDescription - }); + return View(new ErrorViewModel()); } } diff --git a/samples/Matty/Matty.Server/Controllers/ErrorController.cs b/samples/Matty/Matty.Server/Controllers/ErrorController.cs index 0d5bbdb12..656930a49 100644 --- a/samples/Matty/Matty.Server/Controllers/ErrorController.cs +++ b/samples/Matty/Matty.Server/Controllers/ErrorController.cs @@ -4,30 +4,28 @@ * the license and the contributors participating to this project. */ +using Matty.Server.ViewModels.Shared; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Mvc; -using Matty.Server.ViewModels.Shared; namespace Matty.Server.Controllers; public class ErrorController : Controller { - [Route("error")] - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true), Route("~/error")] public IActionResult Error() { - // If the error was not caused by an invalid - // OIDC request, display a generic error page. + // If the error originated from the OpenIddict server, render the error details. var response = HttpContext.GetOpenIddictServerResponse(); - if (response == null) + if (response is not null) { - return View(new ErrorViewModel()); + return View(new ErrorViewModel + { + Error = response.Error, + ErrorDescription = response.ErrorDescription + }); } - return View(new ErrorViewModel - { - Error = response.Error, - ErrorDescription = response.ErrorDescription - }); + return View(new ErrorViewModel()); } } diff --git a/samples/Velusia/Velusia.Client/Controllers/ErrorController.cs b/samples/Velusia/Velusia.Client/Controllers/ErrorController.cs index 862b3d83a..194919821 100644 --- a/samples/Velusia/Velusia.Client/Controllers/ErrorController.cs +++ b/samples/Velusia/Velusia.Client/Controllers/ErrorController.cs @@ -6,21 +6,20 @@ namespace Velusia.Client; public class ErrorController : Controller { - [HttpGet, HttpPost, Route("~/error")] + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true), Route("~/error")] public IActionResult Error() { - // If the error was not caused by an invalid - // OIDC request, display a generic error page. + // If the error originated from the OpenIddict client, render the error details. var response = HttpContext.GetOpenIddictClientResponse(); - if (response is null) + if (response is not null) { - return View(new ErrorViewModel()); + return View(new ErrorViewModel + { + Error = response.Error, + ErrorDescription = response.ErrorDescription + }); } - return View(new ErrorViewModel - { - Error = response.Error, - ErrorDescription = response.ErrorDescription - }); + return View(new ErrorViewModel()); } } diff --git a/samples/Velusia/Velusia.Server/Controllers/ErrorController.cs b/samples/Velusia/Velusia.Server/Controllers/ErrorController.cs index 95f4c6e9c..dca855d40 100644 --- a/samples/Velusia/Velusia.Server/Controllers/ErrorController.cs +++ b/samples/Velusia/Velusia.Server/Controllers/ErrorController.cs @@ -12,22 +12,20 @@ namespace Velusia.Server.Controllers; public class ErrorController : Controller { - [Route("error")] - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true), Route("~/error")] public IActionResult Error() { - // If the error was not caused by an invalid - // OIDC request, display a generic error page. + // If the error originated from the OpenIddict server, render the error details. var response = HttpContext.GetOpenIddictServerResponse(); - if (response == null) + if (response is not null) { - return View(new ErrorViewModel()); + return View(new ErrorViewModel + { + Error = response.Error, + ErrorDescription = response.ErrorDescription + }); } - return View(new ErrorViewModel - { - Error = response.Error, - ErrorDescription = response.ErrorDescription - }); + return View(new ErrorViewModel()); } }