Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 17 additions & 29 deletions Auth/LearningHub.Nhs.Auth/Controllers/OpenAthensController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ public IActionResult Index()
/// </exception>
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
{
Expand All @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion Auth/LearningHub.Nhs.Auth/ServiceCollectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down