Skip to content

Commit ebbe8a6

Browse files
authored
Merge pull request #154 from TechnologyEnhancedLearning/RC
Merge English Ivy release to master
2 parents 7cf3cae + d0c1290 commit ebbe8a6

File tree

12 files changed

+233
-51
lines changed

12 files changed

+233
-51
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>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
namespace LearningHub.Nhs.Auth.Helpers
2+
{
3+
using System;
4+
using System.Collections.Concurrent;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using Microsoft.AspNetCore.Authentication;
8+
using Microsoft.AspNetCore.Authentication.Cookies;
9+
10+
/// <summary>
11+
/// Defines the <see cref="InMemoryTicketStore" />.
12+
/// </summary>
13+
public class InMemoryTicketStore : ITicketStore
14+
{
15+
private readonly ConcurrentDictionary<string, AuthenticationTicket> cache;
16+
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="InMemoryTicketStore"/> class.
19+
/// The InMemoryTicketStore.
20+
/// </summary>
21+
/// <param name="cache">the cache.</param>
22+
public InMemoryTicketStore(ConcurrentDictionary<string, AuthenticationTicket> cache)
23+
{
24+
this.cache = cache;
25+
}
26+
27+
/// <summary>
28+
/// The StoreAsync.
29+
/// </summary>
30+
/// <param name="ticket">The ticket.</param>
31+
/// <returns>The key.</returns>
32+
public async Task<string> StoreAsync(AuthenticationTicket ticket)
33+
{
34+
var ticketUserId = ticket.Principal.Claims.Where(c => c.Type == "sub")
35+
.FirstOrDefault()
36+
.Value;
37+
var matchingAuthTicket = this.cache.Values.FirstOrDefault(
38+
t => t.Principal.Claims.FirstOrDefault(
39+
c => c.Type == "sub"
40+
&& c.Value == ticketUserId) != null);
41+
if (matchingAuthTicket != null)
42+
{
43+
var cacheKey = this.cache.Where(
44+
entry => entry.Value == matchingAuthTicket)
45+
.Select(entry => entry.Key)
46+
.FirstOrDefault();
47+
this.cache.TryRemove(
48+
cacheKey,
49+
out _);
50+
}
51+
52+
var key = Guid
53+
.NewGuid()
54+
.ToString();
55+
await this.RenewAsync(
56+
key,
57+
ticket);
58+
return key;
59+
}
60+
61+
/// <summary>
62+
/// The RenewAsync.
63+
/// </summary>
64+
/// <param name="key">The key.</param>
65+
/// <param name="ticket">The ticket.</param>
66+
/// <returns>The Task.</returns>
67+
public Task RenewAsync(
68+
string key,
69+
AuthenticationTicket ticket)
70+
{
71+
this.cache.AddOrUpdate(
72+
key,
73+
ticket,
74+
(_, _) => ticket);
75+
return Task.CompletedTask;
76+
}
77+
78+
/// <summary>
79+
/// The RetrieveAsync.
80+
/// </summary>
81+
/// <param name="key">The Key.</param>
82+
/// <returns>The Task.</returns>
83+
public Task<AuthenticationTicket> RetrieveAsync(string key)
84+
{
85+
this.cache.TryGetValue(
86+
key,
87+
out var ticket);
88+
return Task.FromResult(ticket);
89+
}
90+
91+
/// <summary>
92+
/// The RemoveAsync.
93+
/// </summary>
94+
/// <param name="key">The key.</param>
95+
/// <returns>The Task.</returns>
96+
public Task RemoveAsync(string key)
97+
{
98+
this.cache.TryRemove(
99+
key,
100+
out _);
101+
return Task.CompletedTask;
102+
}
103+
}
104+
}

Auth/LearningHub.Nhs.Auth/ServiceCollectionExtension.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
namespace LearningHub.Nhs.Auth
22
{
33
using System;
4+
using System.Collections.Concurrent;
45
using System.Security.Cryptography.X509Certificates;
56
using Azure.Identity;
67
using IdentityServer4;
78
using LearningHub.Nhs.Auth.Configuration;
9+
using LearningHub.Nhs.Auth.Helpers;
810
using LearningHub.Nhs.Auth.Middleware;
911
using LearningHub.Nhs.Caching;
1012
using LearningHub.Nhs.Models.Enums;
@@ -70,7 +72,9 @@ public static void ConfigureServices(this IServiceCollection services, IConfigur
7072
{
7173
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
7274
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
73-
}).AddCookie().AddOpenIdConnect(
75+
})
76+
.AddCookie()
77+
.AddOpenIdConnect(
7478
"oidc_oa",
7579
options =>
7680
{

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": {

Auth/LearningHub.Nhs.Auth/package-lock.json

Lines changed: 35 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)