From 088e64f28f26dc876dd65f0229e1237bf8758089 Mon Sep 17 00:00:00 2001 From: Khwezi Mngoma Date: Sat, 13 Jun 2026 22:51:07 +0200 Subject: [PATCH] Fixed the redirect URI on logout so its passed by the caller --- LiteCharms.Features/Extensions/Api.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/LiteCharms.Features/Extensions/Api.cs b/LiteCharms.Features/Extensions/Api.cs index ae57c25..d89b998 100644 --- a/LiteCharms.Features/Extensions/Api.cs +++ b/LiteCharms.Features/Extensions/Api.cs @@ -18,7 +18,7 @@ public static class Api return services; } - + public static IServiceCollection AddSecurityApiSdk(this IServiceCollection services, IConfiguration configuration) { var configSection = configuration.GetSection(nameof(LiteCharmsClientSettings)); @@ -143,13 +143,19 @@ public static class Api }); }); - app.MapGet("/logout", async (HttpContext context) => + app.MapGet("/logout", async (HttpContext context, string? redirectUri = null) => { var idToken = await context.GetTokenAsync("id_token"); - var authProperties = new AuthenticationProperties { RedirectUri = "/", }; + if (string.IsNullOrWhiteSpace(redirectUri)) + { + var host = context.Request.Host.ToUriComponent(); + redirectUri = $"https://{host}/"; + } - if (!string.IsNullOrEmpty(idToken)) + var authProperties = new AuthenticationProperties { RedirectUri = redirectUri, }; + + if (!string.IsNullOrEmpty(idToken)) authProperties.Parameters.Add("id_token_hint", idToken); await context.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, authProperties);