Skip to content

Commit c661f83

Browse files
authored
Merge pull request #183 from TechnologyEnhancedLearning/RC
Merge RC to master
2 parents a4a2a8c + 2f2a73d commit c661f83

File tree

11 files changed

+512
-512
lines changed

11 files changed

+512
-512
lines changed

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

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Linq;
66
using System.Net;
77
using System.Threading.Tasks;
8-
using Azure.Core;
98
using elfhHub.Nhs.Models.Common;
109
using elfhHub.Nhs.Models.Enums;
1110
using IdentityModel;
@@ -23,11 +22,9 @@
2322
using LearningHub.Nhs.Models.Common;
2423
using Microsoft.AspNetCore.Authentication;
2524
using Microsoft.AspNetCore.Authorization;
26-
using Microsoft.AspNetCore.Http;
2725
using Microsoft.AspNetCore.Mvc;
2826
using Microsoft.Extensions.Logging;
2927
using Microsoft.Extensions.Options;
30-
using UAParser;
3128

3229
/// <summary>
3330
/// Account Controller operations.
@@ -166,44 +163,34 @@ await this.interaction.GrantConsentAsync(
166163

167164
if (loginResult.IsAuthenticated)
168165
{
169-
var uaParser = Parser.GetDefault();
170-
var clientInfo = uaParser.Parse(this.Request.Headers["User-Agent"]);
171-
var result = await this.UserService.CheckUserHasAnActiveSessionAsync(userId);
172-
if (result.Items.Count == 0 || result.Items[0].BrowserName == clientInfo.UA.Family)
173-
{
174-
await this.SignInUser(userId, model.Username.Trim(), model.RememberLogin, context.Parameters["ext_referer"]);
166+
await this.SignInUser(userId, model.Username.Trim(), model.RememberLogin, context.Parameters["ext_referer"]);
175167

176-
if (context != null)
168+
if (context != null)
169+
{
170+
if (await this.ClientStore.IsPkceClientAsync(context.Client.ClientId))
177171
{
178-
if (await this.ClientStore.IsPkceClientAsync(context.Client.ClientId))
179-
{
180-
// if the client is PKCE then we assume it's native, so this change in how to
181-
// return the response is for better UX for the end user.
182-
return this.View("Redirect", new RedirectViewModel { RedirectUrl = model.ReturnUrl });
183-
}
184-
185-
// we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null
186-
return this.Redirect(model.ReturnUrl);
172+
// if the client is PKCE then we assume it's native, so this change in how to
173+
// return the response is for better UX for the end user.
174+
return this.View("Redirect", new RedirectViewModel { RedirectUrl = model.ReturnUrl });
187175
}
188176

189-
// request for a local page
190-
if (this.Url.IsLocalUrl(model.ReturnUrl))
191-
{
192-
return this.Redirect(model.ReturnUrl);
193-
}
194-
else if (string.IsNullOrEmpty(model.ReturnUrl))
195-
{
196-
return this.Redirect("~/");
197-
}
198-
else
199-
{
200-
// user might have clicked on a malicious link - should be logged
201-
throw new Exception("invalid return URL");
202-
}
177+
// we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null
178+
return this.Redirect(model.ReturnUrl);
179+
}
180+
181+
// request for a local page
182+
if (this.Url.IsLocalUrl(model.ReturnUrl))
183+
{
184+
return this.Redirect(model.ReturnUrl);
185+
}
186+
else if (string.IsNullOrEmpty(model.ReturnUrl))
187+
{
188+
return this.Redirect("~/");
203189
}
204190
else
205191
{
206-
return this.View("AlreadyActiveSession");
192+
// user might have clicked on a malicious link - should be logged
193+
throw new Exception("invalid return URL");
207194
}
208195
}
209196
else if (userId > 0)

Auth/LearningHub.Nhs.Auth/Interfaces/IUserService.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,6 @@ public interface IUserService
114114
/// </returns>
115115
Task StoreUserHistoryAsync(UserHistoryViewModel userHistory);
116116

117-
/// <summary>
118-
/// check user has an laredy active session.
119-
/// </summary>
120-
/// <param name="userId">The userId.</param>
121-
/// <returns>The <see cref="Task"/>.</returns>
122-
Task<PagedResultSet<UserHistoryViewModel>> CheckUserHasAnActiveSessionAsync(int userId);
123-
124117
/// <summary>
125118
/// The store user history async.
126119
/// </summary>

Auth/LearningHub.Nhs.Auth/Services/UserService.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -243,29 +243,5 @@ public async Task StoreUserHistoryAsync(UserHistoryViewModel userHistory)
243243
}
244244
}
245245
}
246-
247-
/// <inheritdoc/>
248-
public async Task<PagedResultSet<UserHistoryViewModel>> CheckUserHasAnActiveSessionAsync(int userId)
249-
{
250-
PagedResultSet<UserHistoryViewModel> userHistoryViewModel = new PagedResultSet<UserHistoryViewModel>();
251-
252-
var client = this.UserApiHttpClient.GetClient();
253-
var request = $"UserHistory/CheckUserHasActiveSession/{userId}";
254-
var response = await client.GetAsync(request).ConfigureAwait(false);
255-
256-
if (response.IsSuccessStatusCode)
257-
{
258-
var result = await response.Content.ReadAsStringAsync();
259-
userHistoryViewModel = JsonConvert.DeserializeObject<PagedResultSet<UserHistoryViewModel>>(result);
260-
}
261-
else if (response.StatusCode == HttpStatusCode.Unauthorized
262-
||
263-
response.StatusCode == HttpStatusCode.Forbidden)
264-
{
265-
throw new Exception("AccessDenied");
266-
}
267-
268-
return userHistoryViewModel;
269-
}
270246
}
271247
}

Auth/LearningHub.Nhs.Auth/Views/Account/AlreadyActiveSession.cshtml

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)