From f80593a86c89f57965af37790edff579f63163fc Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Tue, 21 May 2024 15:19:44 +0100 Subject: [PATCH 1/2] TD-4111: Log table flooded with error has been handled --- .../Controllers/OpenAthensController.cs | 46 +++++++------------ .../ServiceCollectionExtension.cs | 2 +- Auth/LearningHub.Nhs.Auth/appsettings.json | 4 +- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/Auth/LearningHub.Nhs.Auth/Controllers/OpenAthensController.cs b/Auth/LearningHub.Nhs.Auth/Controllers/OpenAthensController.cs index e9db992..0bd8e3f 100644 --- a/Auth/LearningHub.Nhs.Auth/Controllers/OpenAthensController.cs +++ b/Auth/LearningHub.Nhs.Auth/Controllers/OpenAthensController.cs @@ -125,11 +125,6 @@ public IActionResult Index() /// public async Task Login(string clientId, string origin, string returnUrl) { - if (string.IsNullOrWhiteSpace(clientId) || string.IsNullOrWhiteSpace(origin)) - { - throw new Exception("ClientId or origin are empty."); - } - string oalhClient; try { @@ -140,33 +135,26 @@ public async Task Login(string clientId, string origin, string returnUrl) oalhClient = string.Empty; } - if (string.IsNullOrWhiteSpace(oalhClient)) + if (!string.IsNullOrWhiteSpace(clientId) && !string.IsNullOrWhiteSpace(origin) && !string.IsNullOrWhiteSpace(oalhClient) && $"https://{oalhClient}".StartsWith(origin, StringComparison.InvariantCultureIgnoreCase)) { - throw new Exception("No OA LH client found."); - } - - if (!$"https://{oalhClient}".StartsWith(origin, StringComparison.InvariantCultureIgnoreCase)) - { - throw new Exception("Invalid origin"); - } - - if (!string.IsNullOrWhiteSpace(returnUrl)) - { - this.Response.Cookies.Append( - ClientReturnUrlKey, - returnUrl, - new CookieOptions + if (!string.IsNullOrWhiteSpace(returnUrl)) { - Expires = DateTimeOffset.Now.AddMinutes(5), - SameSite = SameSiteMode.None, - HttpOnly = true, - Secure = true, - }); - } + this.Response.Cookies.Append( + ClientReturnUrlKey, + returnUrl, + new CookieOptions + { + Expires = DateTimeOffset.Now.AddMinutes(5), + SameSite = SameSiteMode.None, + HttpOnly = true, + Secure = true, + }); + } - var internalReturnUrl = $"/openathens/oacallback?clientId={clientId}"; - var authProps = new AuthenticationProperties { RedirectUri = internalReturnUrl }; - await this.HttpContext.ChallengeAsync("oidc_oa", authProps); + var internalReturnUrl = $"/openathens/oacallback?clientId={clientId}"; + var authProps = new AuthenticationProperties { RedirectUri = internalReturnUrl }; + await this.HttpContext.ChallengeAsync("oidc_oa", authProps); + } // return Content("Route is working"); } diff --git a/Auth/LearningHub.Nhs.Auth/ServiceCollectionExtension.cs b/Auth/LearningHub.Nhs.Auth/ServiceCollectionExtension.cs index 8cc986b..6aaf2f5 100644 --- a/Auth/LearningHub.Nhs.Auth/ServiceCollectionExtension.cs +++ b/Auth/LearningHub.Nhs.Auth/ServiceCollectionExtension.cs @@ -145,7 +145,7 @@ public static void ConfigureServices(this IServiceCollection services, IConfigur services.AddDistributedCache(opt => { opt.RedisConnectionString = configuration.GetConnectionString("Redis"); - opt.KeyPrefix = $"{envPrefix}_WebUI"; + opt.KeyPrefix = $"{envPrefix}_Auth"; opt.DefaultExpiryInMinutes = 60; }); } diff --git a/Auth/LearningHub.Nhs.Auth/appsettings.json b/Auth/LearningHub.Nhs.Auth/appsettings.json index b37f7c6..82077b3 100644 --- a/Auth/LearningHub.Nhs.Auth/appsettings.json +++ b/Auth/LearningHub.Nhs.Auth/appsettings.json @@ -19,8 +19,8 @@ }, "Logging": { "LogLevel": { - "Default": "Trace", - "Microsoft": "Trace" + "Default": "Critical", + "Microsoft": "Critical" } }, "ConnectionStrings": { From 385081db8acb14bffc8ede33c1e16bf7ec96795d Mon Sep 17 00:00:00 2001 From: Sarathlal Sarangadharan Date: Tue, 21 May 2024 16:33:20 +0100 Subject: [PATCH 2/2] TD-4111: appsettings changes reverted since this will be updated in prod directly --- Auth/LearningHub.Nhs.Auth/appsettings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Auth/LearningHub.Nhs.Auth/appsettings.json b/Auth/LearningHub.Nhs.Auth/appsettings.json index 82077b3..b37f7c6 100644 --- a/Auth/LearningHub.Nhs.Auth/appsettings.json +++ b/Auth/LearningHub.Nhs.Auth/appsettings.json @@ -19,8 +19,8 @@ }, "Logging": { "LogLevel": { - "Default": "Critical", - "Microsoft": "Critical" + "Default": "Trace", + "Microsoft": "Trace" } }, "ConnectionStrings": {