Skip to content

Commit 22c1023

Browse files
authored
Merge pull request #40 from TechnologyEnhancedLearning/RC
Merge Rc to CI
2 parents 029ee4c + e14c444 commit 22c1023

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

Auth/LearningHub.Nhs.Auth/Controllers/OpenAthensController.cs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@ public IActionResult Index()
125125
/// </exception>
126126
public async Task Login(string clientId, string origin, string returnUrl)
127127
{
128-
if (string.IsNullOrWhiteSpace(clientId) || string.IsNullOrWhiteSpace(origin))
129-
{
130-
throw new Exception("ClientId or origin are empty.");
131-
}
132-
133128
string oalhClient;
134129
try
135130
{
@@ -140,33 +135,26 @@ public async Task Login(string clientId, string origin, string returnUrl)
140135
oalhClient = string.Empty;
141136
}
142137

143-
if (string.IsNullOrWhiteSpace(oalhClient))
138+
if (!string.IsNullOrWhiteSpace(clientId) && !string.IsNullOrWhiteSpace(origin) && !string.IsNullOrWhiteSpace(oalhClient) && $"https://{oalhClient}".StartsWith(origin, StringComparison.InvariantCultureIgnoreCase))
144139
{
145-
throw new Exception("No OA LH client found.");
146-
}
147-
148-
if (!$"https://{oalhClient}".StartsWith(origin, StringComparison.InvariantCultureIgnoreCase))
149-
{
150-
throw new Exception("Invalid origin");
151-
}
152-
153-
if (!string.IsNullOrWhiteSpace(returnUrl))
154-
{
155-
this.Response.Cookies.Append(
156-
ClientReturnUrlKey,
157-
returnUrl,
158-
new CookieOptions
140+
if (!string.IsNullOrWhiteSpace(returnUrl))
159141
{
160-
Expires = DateTimeOffset.Now.AddMinutes(5),
161-
SameSite = SameSiteMode.None,
162-
HttpOnly = true,
163-
Secure = true,
164-
});
165-
}
142+
this.Response.Cookies.Append(
143+
ClientReturnUrlKey,
144+
returnUrl,
145+
new CookieOptions
146+
{
147+
Expires = DateTimeOffset.Now.AddMinutes(5),
148+
SameSite = SameSiteMode.None,
149+
HttpOnly = true,
150+
Secure = true,
151+
});
152+
}
166153

167-
var internalReturnUrl = $"/openathens/oacallback?clientId={clientId}";
168-
var authProps = new AuthenticationProperties { RedirectUri = internalReturnUrl };
169-
await this.HttpContext.ChallengeAsync("oidc_oa", authProps);
154+
var internalReturnUrl = $"/openathens/oacallback?clientId={clientId}";
155+
var authProps = new AuthenticationProperties { RedirectUri = internalReturnUrl };
156+
await this.HttpContext.ChallengeAsync("oidc_oa", authProps);
157+
}
170158

171159
// return Content("Route is working");
172160
}

Auth/LearningHub.Nhs.Auth/ServiceCollectionExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public static void ConfigureServices(this IServiceCollection services, IConfigur
145145
services.AddDistributedCache(opt =>
146146
{
147147
opt.RedisConnectionString = configuration.GetConnectionString("Redis");
148-
opt.KeyPrefix = $"{envPrefix}_WebUI";
148+
opt.KeyPrefix = $"{envPrefix}_Auth";
149149
opt.DefaultExpiryInMinutes = 60;
150150
});
151151
}

0 commit comments

Comments
 (0)