From 19180e4a2fce4b17ff539e2da94b115c7ff972e6 Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Thu, 29 Feb 2024 11:16:21 +0000 Subject: [PATCH] TD-3841 context null check --- .../Controllers/AccountController.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Auth/LearningHub.Nhs.Auth/Controllers/AccountController.cs b/Auth/LearningHub.Nhs.Auth/Controllers/AccountController.cs index 46d5cc2..235de2a 100644 --- a/Auth/LearningHub.Nhs.Auth/Controllers/AccountController.cs +++ b/Auth/LearningHub.Nhs.Auth/Controllers/AccountController.cs @@ -145,6 +145,12 @@ await this.interaction.GrantConsentAsync( } } + if (context == null) + { + this.ModelState.AddModelError(string.Empty, "Invalid request"); + goto showFormWithError; + } + if (this.ModelState.IsValid) { // validate username/password @@ -208,6 +214,8 @@ await this.UserService.AddLogonToUserHistory( this.ModelState.AddModelError(string.Empty, loginResult.ErrorMessage); } + showFormWithError: + // something went wrong, show form with error var vm = await this.BuildLoginViewModelAsync(model); if ((vm.ClientId == "learninghubwebclient") || (vm.ClientId == "learninghubadmin")) @@ -396,7 +404,7 @@ private async Task BuildLoginViewModelAsync(string returnUrl) Username = context?.LoginHint, ExternalProviders = providers.ToArray(), LoginClientTemplate = loginClientTemplate ?? new LoginClientTemplate(), - ClientId = context.Client.ClientId, + ClientId = context?.Client.ClientId, }; }