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; }); }