From 9d0eca30049e61b270302ecb51432d96e6a8f6e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Tue, 26 Mar 2024 18:38:48 +0100 Subject: [PATCH] Bump OpenIddict to 5.4.0 --- Directory.Packages.props | 28 +++++++++--------- .../Controllers/AuthorizationController.cs | 29 +++++++++---------- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 13c268a1..58628bd5 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -44,11 +44,11 @@ - - - - - + + + + + @@ -85,15 +85,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/samples/Matty/Matty.Server/Controllers/AuthorizationController.cs b/samples/Matty/Matty.Server/Controllers/AuthorizationController.cs index 88f7c205..ed411ea2 100644 --- a/samples/Matty/Matty.Server/Controllers/AuthorizationController.cs +++ b/samples/Matty/Matty.Server/Controllers/AuthorizationController.cs @@ -48,16 +48,6 @@ public AuthorizationController( [Authorize, HttpGet("~/connect/verify"), IgnoreAntiforgeryToken] public async Task Verify() { - var request = HttpContext.GetOpenIddictServerRequest() ?? - throw new InvalidOperationException("The OpenID Connect request cannot be retrieved."); - - // If the user code was not specified in the query string (e.g as part of the verification_uri_complete), - // render a form to ask the user to enter the user code manually (non-digit chars are automatically ignored). - if (string.IsNullOrEmpty(request.UserCode)) - { - return View(new VerifyViewModel()); - } - // Retrieve the claims principal associated with the user code. var result = await HttpContext.AuthenticateAsync(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme); if (result.Succeeded && !string.IsNullOrEmpty(result.Principal.GetClaim(Claims.ClientId))) @@ -71,16 +61,23 @@ public async Task Verify() { ApplicationName = await _applicationManager.GetLocalizedDisplayNameAsync(application), Scope = string.Join(" ", result.Principal.GetScopes()), - UserCode = request.UserCode + UserCode = result.Properties.GetTokenValue(OpenIddictServerAspNetCoreConstants.Tokens.UserCode) }); } - // Redisplay the form when the user code is not valid. - return View(new VerifyViewModel + // If a user code was specified (e.g as part of the verification_uri_complete) + // but is not valid, render a form asking the user to enter the user code manually. + else if (!string.IsNullOrEmpty(result.Properties.GetTokenValue(OpenIddictServerAspNetCoreConstants.Tokens.UserCode))) { - Error = Errors.InvalidToken, - ErrorDescription = "The specified user code is not valid. Please make sure you typed it correctly." - }); + return View(new VerifyViewModel + { + Error = Errors.InvalidToken, + ErrorDescription = "The specified user code is not valid. Please make sure you typed it correctly." + }); + } + + // Otherwise, render a form asking the user to enter the user code manually. + return View(new VerifyViewModel()); } [Authorize, FormValueRequired("submit.Accept")]