Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed authenticate middleware #83

Merged
merged 1 commit into from
Jun 12, 2024
Merged
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
38 changes: 22 additions & 16 deletions src/Server/src/AspNet/Security/EnsureAuthenticatedMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,38 @@ public async Task InvokeAsync(HttpContext context)

return;
}
else

if (context.Request.Path.StartsWithSegments("/api")
|| context.Request.Path.StartsWithSegments("/graphql")
|| context.Request.Path.StartsWithSegments("/signalR")
|| context.Request.Path.StartsWithSegments("/error"))
{
if (context.Request.Path.StartsWithSegments("/api")
|| context.Request.Path.StartsWithSegments("/graphql")
|| context.Request.Path.StartsWithSegments("/signalR")
|| context.Request.Path.StartsWithSegments("/error"))
if (HasIdOpsRole(context))
{
if (HasIdOpsRole(context))
{
await _next(context);
}
else
{
context.Response.StatusCode = 403;
await context.Response.WriteAsync("Access denied!");
}
await _next(context);
}
else if (!context.User.Identity.IsAuthenticated)
else
{
context.Response.StatusCode = 403;
await context.Response.WriteAsync("Access denied!");
}
}
else if (!context.User.Identity.IsAuthenticated)
{
if (context.Request.Path == "/")
{
await context.ChallengeAsync();
}
else
{
await _next(context);
context.Response.StatusCode = 403;
await context.Response.WriteAsync("Access denied!");
}
}
else
{
await _next(context);
}
}

private bool HasIdOpsRole(HttpContext context)
Expand Down
Loading