Skip to content

Commit

Permalink
Anonymous health endpopoint access (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmverma authored Oct 3, 2024
1 parent 3e580a3 commit 50b7dbd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@ public class AuthenticatedSessionAwareMiddleware(RequestDelegate next, ISession
{
public async Task Invoke(HttpContext context)
{
var endpoint = context.GetEndpoint();

if (endpoint != null)
if (context.Request.Path != "/health")
{
if (endpoint.Metadata.GetMetadata<AuthenticatedSessionNotRequiredAttribute>() is null)
var endpoint = context.GetEndpoint();

if (endpoint != null)
{
if (context.User.Identity?.IsAuthenticated == false)
if (endpoint.Metadata.GetMetadata<AuthenticatedSessionNotRequiredAttribute>() is null)
{
context.Response.Redirect("/");
return;
}
if (context.User.Identity?.IsAuthenticated == false)
{
context.Response.Redirect("/");
return;
}

var details = session.Get<UserDetails>(Session.UserDetailsKey);
var details = session.Get<UserDetails>(Session.UserDetailsKey);

if (details == null)
{
context.Response.Redirect("/");
return;
if (details == null)
{
context.Response.Redirect("/");
return;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Frontend/CO.CDP.OrganisationApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
app.UseHsts();
}

app.MapHealthChecks("/health");
app.MapHealthChecks("/health").AllowAnonymous();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
Expand Down

0 comments on commit 50b7dbd

Please sign in to comment.