From e392cb4cbf17f1961d372d672c792e2af7d80dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Sun, 1 Sep 2024 10:46:26 +0200 Subject: [PATCH] Do not limit the error controller to a specific HTTP method --- .../Controllers/ErrorController.cs | 19 +++++++++---------- .../Controllers/ErrorController.cs | 19 +++++++++---------- .../OpenIddictHelpers.cs | 2 +- .../Primitives/OpenIddictExtensions.cs | 4 ++-- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/sandbox/OpenIddict.Sandbox.AspNetCore.Client/Controllers/ErrorController.cs b/sandbox/OpenIddict.Sandbox.AspNetCore.Client/Controllers/ErrorController.cs index d71cbcee1..570eae15b 100644 --- a/sandbox/OpenIddict.Sandbox.AspNetCore.Client/Controllers/ErrorController.cs +++ b/sandbox/OpenIddict.Sandbox.AspNetCore.Client/Controllers/ErrorController.cs @@ -12,21 +12,20 @@ namespace OpenIddict.Sandbox.AspNetCore.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/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Controllers/ErrorController.cs b/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Controllers/ErrorController.cs index da8248529..4bb5f3309 100644 --- a/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Controllers/ErrorController.cs +++ b/sandbox/OpenIddict.Sandbox.AspNetCore.Server/Controllers/ErrorController.cs @@ -12,21 +12,20 @@ namespace OpenIddict.Sandbox.AspNetCore.Server; 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 server, render the error details. var response = HttpContext.GetOpenIddictServerResponse(); - 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/shared/OpenIddict.Extensions/OpenIddictHelpers.cs b/shared/OpenIddict.Extensions/OpenIddictHelpers.cs index 87fe62d44..736bd643c 100644 --- a/shared/OpenIddict.Extensions/OpenIddictHelpers.cs +++ b/shared/OpenIddict.Extensions/OpenIddictHelpers.cs @@ -1387,7 +1387,7 @@ public Dictionary GetResults() { foreach (var entry in _expandingAccumulator) { - _accumulator[entry.Key] = new StringValues(entry.Value.ToArray()); + _accumulator[entry.Key] = new StringValues([.. entry.Value]); } } diff --git a/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs b/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs index cc42c2797..856bcf854 100644 --- a/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs +++ b/src/OpenIddict.Abstractions/Primitives/OpenIddictExtensions.cs @@ -660,7 +660,7 @@ public static ImmutableDictionary GetDestinations(this ClaimsI } } - builder.Add(group.Key, destinations.ToArray()); + builder.Add(group.Key, [.. destinations]); } } @@ -697,7 +697,7 @@ public static ImmutableDictionary GetDestinations(this ClaimsP } } - builder.Add(group.Key, destinations.ToArray()); + builder.Add(group.Key, [.. destinations]); } }