From 4576b5aa2b6c6034247d3cd136fe15c82d27a6f4 Mon Sep 17 00:00:00 2001 From: Khwezi Mngoma Date: Fri, 5 Jun 2026 08:15:13 +0200 Subject: [PATCH] Refactored logout endpoint --- LiteCharms.Features/Extensions/Api.cs | 28 ++++++--------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/LiteCharms.Features/Extensions/Api.cs b/LiteCharms.Features/Extensions/Api.cs index d675013..608f84c 100644 --- a/LiteCharms.Features/Extensions/Api.cs +++ b/LiteCharms.Features/Extensions/Api.cs @@ -112,30 +112,14 @@ public static class Api app.MapGet("/logout", async (HttpContext context, IHttpClientFactory httpClientFactory, IOptions settings) => { - var authOptions = settings.Value; - var accessToken = await context.GetTokenAsync("access_token"); - - if (!string.IsNullOrEmpty(accessToken)) - { - try - { - var client = httpClientFactory.CreateClient(); - - var requestContent = new FormUrlEncodedContent(new Dictionary(StringComparer.Ordinal) - { - { "token", accessToken }, - { "client_id", authOptions.ClientId! }, - { "client_secret", authOptions.ClientSecret! }, - }); - - await client.PostAsync(authOptions.RevokationEndpoint, requestContent, context.RequestAborted); - } - catch { } - } - await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); - return Results.Redirect($"{authOptions.Authority}end-session/"); + string currentBaseUrl = $"https://{context.Request.Host}{context.Request.PathBase}/"; + + await context.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties + { + RedirectUri = currentBaseUrl + }); }); return app;