Skip to content

Commit 2b4eb35

Browse files
Merge pull request #132 from TechnologyEnhancedLearning/Develop/Fixes/Td-3731-Password-Change-Does-Not-Invalidate-Current-Session
TD-3731: Password Change Does Not Invalidate Current Session
2 parents 1d8c1d7 + 11526c1 commit 2b4eb35

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

Auth/LearningHub.Nhs.Auth/Configuration/WebSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,10 @@ public class WebSettings
5656
/// Gets or sets the SupportFeedbackForm.
5757
/// </summary>
5858
public string SupportFeedbackForm { get; set; }
59+
60+
/// <summary>
61+
/// Gets or sets a value indicating whether IsPasswordUpdate.
62+
/// </summary>
63+
public bool IsPasswordUpdate { get; set; }
5964
}
6065
}

Auth/LearningHub.Nhs.Auth/Controllers/AccountController.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@
2020
using LearningHub.Nhs.Auth.Models.Account;
2121
using LearningHub.Nhs.Caching;
2222
using LearningHub.Nhs.Models.Common;
23-
using LearningHub.Nhs.Models.Entities.Reporting;
2423
using Microsoft.AspNetCore.Authentication;
2524
using Microsoft.AspNetCore.Authorization;
26-
using Microsoft.AspNetCore.Http;
2725
using Microsoft.AspNetCore.Mvc;
28-
using Microsoft.Extensions.Configuration;
2926
using Microsoft.Extensions.Logging;
3027
using Microsoft.Extensions.Options;
31-
using NHSUKViewComponents.Web.ViewModels;
3228

3329
/// <summary>
3430
/// Account Controller operations.
@@ -72,7 +68,7 @@ public AccountController(
7268
this.authConfig = authConfig?.Value;
7369
this.webSettings = webSettings;
7470
this.logger = logger;
75-
}
71+
}
7672

7773
/// <summary>
7874
/// Shows the Login page.
@@ -214,9 +210,9 @@ await this.UserService.AddLogonToUserHistory(
214210
this.ModelState.AddModelError(string.Empty, loginResult.ErrorMessage);
215211
}
216212

217-
showFormWithError:
213+
showFormWithError:
218214

219-
// something went wrong, show form with error
215+
// something went wrong, show form with error
220216
var vm = await this.BuildLoginViewModelAsync(model);
221217
if ((vm.ClientId == "learninghubwebclient") || (vm.ClientId == "learninghubadmin"))
222218
{
@@ -268,6 +264,9 @@ public async Task<IActionResult> Logout(LogoutInputModel model)
268264
// delete local authentication cookie
269265
await this.HttpContext.SignOutAsync();
270266

267+
// Delete the authentication cookie to ensure it is invalidated
268+
this.HttpContext.Response.Cookies.Delete(".AspNetCore.Identity.Application");
269+
271270
// raise the logout event
272271
await this.Events.RaiseAsync(new UserLogoutSuccessEvent(this.User.GetSubjectId(), this.User.GetDisplayName()));
273272

@@ -296,7 +295,15 @@ public async Task<IActionResult> Logout(LogoutInputModel model)
296295
return this.SignOut(new AuthenticationProperties { RedirectUri = url }, vm.ExternalAuthenticationScheme);
297296
}
298297

299-
return this.View("LoggedOut", vm);
298+
if (this.webSettings.IsPasswordUpdate)
299+
{
300+
var redirectUri = $"{this.webSettings.LearningHubWebClient}Home/ChangePasswordAcknowledgement";
301+
return this.Redirect(redirectUri);
302+
}
303+
else
304+
{
305+
return this.View("LoggedOut", vm);
306+
}
300307
}
301308

302309
/// <summary>

Auth/LearningHub.Nhs.Auth/Controllers/HomeController.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,27 @@ public async Task<IActionResult> Error()
8080
return this.View("Error");
8181
}
8282

83+
/// <summary>
84+
/// IsPasswordUpdateMethod.
85+
/// </summary>
86+
/// <param name="isLogout">The Logout.</param>
87+
/// <returns>The <see cref="ActionResult"/>.</returns>
88+
[HttpGet]
89+
public IActionResult SetIsPasswordUpdate(bool isLogout)
90+
{
91+
if (isLogout)
92+
{
93+
this.webSettings.IsPasswordUpdate = false;
94+
}
95+
else
96+
{
97+
this.webSettings.IsPasswordUpdate = true;
98+
}
99+
100+
var redirectUri = $"{this.webSettings.LearningHubWebClient}Home/UserLogout";
101+
return this.Redirect(redirectUri);
102+
}
103+
83104
/// <summary>
84105
/// Shows the HealthCheck response.
85106
/// </summary>

Auth/LearningHub.Nhs.Auth/appsettings.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@
3939
"ElfhHub": "",
4040
"Rcr": "",
4141
"SupportForm": "https://support.learninghub.nhs.uk/support/tickets/new",
42-
"SupportFeedbackForm": "https://forms.office.com/e/C8tteweEhG"
43-
44-
42+
"SupportFeedbackForm": "https://forms.office.com/e/C8tteweEhG",
43+
"IsPasswordUpdate": "false"
4544
},
4645
"AllowOpenAthensDebug": false,
4746
"OaLhClients": {

0 commit comments

Comments
 (0)