Configured security, stable run
continuous-integration/drone/pr Build is passing

This commit is contained in:
Khwezi Mngoma
2026-05-17 08:29:12 +02:00
parent 3bdf897ac8
commit 5f5f83a85a
7 changed files with 151 additions and 53 deletions
+27 -2
View File
@@ -65,6 +65,21 @@ builder.Services.AddAuthentication(options =>
NameClaimType = "name",
RoleClaimType = "groups"
};
options.Events = new OpenIdConnectEvents
{
OnRedirectToIdentityProviderForSignOut = async callbackContext =>
{
var request = callbackContext.Request;
string currentBaseUrl = $"{request.Scheme}://{request.Host}{request.PathBase}/";
callbackContext.ProtocolMessage.PostLogoutRedirectUri = currentBaseUrl;
var idToken = await callbackContext.HttpContext.GetTokenAsync("id_token");
if (!string.IsNullOrEmpty(idToken)) callbackContext.ProtocolMessage.IdTokenHint = idToken;
}
};
});
var app = builder.Build();
@@ -97,8 +112,18 @@ app.UseAuthorization();
app.MapStaticAssets();
app.MapGet("/auth/login", (string redirectUri = "/") =>
Results.Challenge(new AuthenticationProperties { RedirectUri = redirectUri },[OpenIdConnectDefaults.AuthenticationScheme]));
app.MapGet("/auth/logout", () => Results.SignOut(new AuthenticationProperties { RedirectUri = "/" }, [CookieAuthenticationDefaults.AuthenticationScheme, OpenIdConnectDefaults.AuthenticationScheme]));
Results.Challenge(new AuthenticationProperties { RedirectUri = redirectUri }, [OpenIdConnectDefaults.AuthenticationScheme]));
app.MapGet("/auth/logout", async (HttpContext context) =>
{
await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
string currentBaseUrl = $"{context.Request.Scheme}://{context.Request.Host}{context.Request.PathBase}/";
await context.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties
{
RedirectUri = currentBaseUrl
});
});
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();