Skip to content

Commit 4ccd4ae

Browse files
authored
Merge pull request #22 from TechnologyEnhancedLearning/RC
Merge RC Changes to CI
2 parents ad660da + 47f038b commit 4ccd4ae

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class AccountController : IdentityServerController
4545
private readonly IAuthenticationSchemeProvider schemeProvider;
4646
private readonly LearningHubAuthConfig authConfig;
4747
private readonly WebSettings webSettings;
48+
private readonly ILogger logger;
4849

4950
/// <summary>
5051
/// Initializes a new instance of the <see cref="AccountController"/> class.
@@ -55,6 +56,7 @@ public class AccountController : IdentityServerController
5556
/// <param name="events">events parameter.</param>
5657
/// <param name="userService">userService parameter.</param>
5758
/// <param name="webSettings">webSettings parameter.</param>
59+
/// <param name="logger">ILogger instance.</param>
5860
/// <param name="authConfig">Auth service config.</param>
5961
/// <param name="cacheService">Cacje service config.</param>
6062
public AccountController(
@@ -64,6 +66,7 @@ public AccountController(
6466
IEventService events,
6567
IUserService userService,
6668
WebSettings webSettings,
69+
ILogger<AccountController> logger,
6770
IOptions<LearningHubAuthConfig> authConfig,
6871
ICacheService cacheService)
6972
: base(userService, events, clientStore, webSettings, cacheService)
@@ -72,6 +75,7 @@ public AccountController(
7275
this.schemeProvider = schemeProvider;
7376
this.authConfig = authConfig?.Value;
7477
this.webSettings = webSettings;
78+
this.logger = logger;
7579
}
7680

7781
/// <summary>
@@ -336,7 +340,7 @@ private async Task<LoginViewModel> BuildLoginViewModelAsync(string returnUrl)
336340
{
337341
var context = await this.interaction.GetAuthorizationContextAsync(returnUrl);
338342
LoginClientTemplate loginClientTemplate = null;
339-
if (context?.Client.ClientId != null && this.authConfig.IdsClients.ContainsKey(context.Client.ClientId))
343+
if (context?.Client?.ClientId != null && this.authConfig.IdsClients.ContainsKey(context.Client.ClientId))
340344
{
341345
loginClientTemplate = this.authConfig.IdsClients[context.Client.ClientId];
342346

@@ -383,7 +387,7 @@ private async Task<LoginViewModel> BuildLoginViewModelAsync(string returnUrl)
383387

384388
var allowLocal = true;
385389

386-
if (context?.Client.ClientId != null)
390+
if (context?.Client?.ClientId != null)
387391
{
388392
var client = await this.ClientStore.FindEnabledClientByIdAsync(context.Client.ClientId);
389393
if (client != null)
@@ -396,6 +400,12 @@ private async Task<LoginViewModel> BuildLoginViewModelAsync(string returnUrl)
396400
}
397401
}
398402

403+
if (context == null || loginClientTemplate == null)
404+
{
405+
string message = context == null ? "context" : loginClientTemplate == null ? "clientTemplate" : string.Empty;
406+
this.logger.LogWarning($"return url has no {message} : {returnUrl}");
407+
}
408+
399409
return new LoginViewModel
400410
{
401411
AllowRememberLogin = loginClientTemplate?.AllowRememberLogin ?? AccountOptions.AllowRememberLogin,
@@ -404,7 +414,7 @@ private async Task<LoginViewModel> BuildLoginViewModelAsync(string returnUrl)
404414
Username = context?.LoginHint,
405415
ExternalProviders = providers.ToArray(),
406416
LoginClientTemplate = loginClientTemplate ?? new LoginClientTemplate(),
407-
ClientId = context?.Client.ClientId,
417+
ClientId = context?.Client?.ClientId,
408418
};
409419
}
410420

0 commit comments

Comments
 (0)