|
5 | 5 | using System.Linq; |
6 | 6 | using System.Net; |
7 | 7 | using System.Threading.Tasks; |
8 | | - using Azure.Core; |
9 | 8 | using elfhHub.Nhs.Models.Common; |
10 | 9 | using elfhHub.Nhs.Models.Enums; |
11 | 10 | using IdentityModel; |
|
23 | 22 | using LearningHub.Nhs.Models.Common; |
24 | 23 | using Microsoft.AspNetCore.Authentication; |
25 | 24 | using Microsoft.AspNetCore.Authorization; |
26 | | - using Microsoft.AspNetCore.Http; |
27 | 25 | using Microsoft.AspNetCore.Mvc; |
28 | 26 | using Microsoft.Extensions.Logging; |
29 | 27 | using Microsoft.Extensions.Options; |
30 | | - using UAParser; |
31 | 28 |
|
32 | 29 | /// <summary> |
33 | 30 | /// Account Controller operations. |
@@ -166,44 +163,34 @@ await this.interaction.GrantConsentAsync( |
166 | 163 |
|
167 | 164 | if (loginResult.IsAuthenticated) |
168 | 165 | { |
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"]); |
175 | 167 |
|
176 | | - if (context != null) |
| 168 | + if (context != null) |
| 169 | + { |
| 170 | + if (await this.ClientStore.IsPkceClientAsync(context.Client.ClientId)) |
177 | 171 | { |
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 }); |
187 | 175 | } |
188 | 176 |
|
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("~/"); |
203 | 189 | } |
204 | 190 | else |
205 | 191 | { |
206 | | - return this.View("AlreadyActiveSession"); |
| 192 | + // user might have clicked on a malicious link - should be logged |
| 193 | + throw new Exception("invalid return URL"); |
207 | 194 | } |
208 | 195 | } |
209 | 196 | else if (userId > 0) |
|
0 commit comments