From 7ad4e3ec1c95702e980d7cd370e1cdf88f45641f Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 6 Jan 2026 10:15:48 -0500 Subject: [PATCH] feat(client): configure HttpClient with AuthRedirectHandler - Add using statement for JdeScoping.Client.Http namespace - Register AuthRedirectHandler as a scoped service - Replace simple HttpClient registration with handler pipeline - AuthRedirectHandler intercepts 401 responses and redirects to login - Keep all existing service registrations for backward compatibility --- NEW/src/JdeScoping.Client/Program.cs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/NEW/src/JdeScoping.Client/Program.cs b/NEW/src/JdeScoping.Client/Program.cs index bac90cd..41b4268 100644 --- a/NEW/src/JdeScoping.Client/Program.cs +++ b/NEW/src/JdeScoping.Client/Program.cs @@ -1,6 +1,9 @@ using JdeScoping.Client; using JdeScoping.Client.Auth; +using JdeScoping.Client.Http; using JdeScoping.Client.Services; +using JdeScoping.Core.ApiContracts; +using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; @@ -10,11 +13,20 @@ var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); -// Configure HttpClient with base address +// Configure HttpClient with AuthRedirectHandler for global 401 handling // In Blazor WebAssembly, the browser automatically handles cookies for same-origin requests -builder.Services.AddScoped(sp => new HttpClient +builder.Services.AddScoped(); +builder.Services.AddScoped(sp => { - BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) + var navigationManager = sp.GetRequiredService(); + var handler = new AuthRedirectHandler(navigationManager) + { + InnerHandler = new HttpClientHandler() + }; + return new HttpClient(handler) + { + BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) + }; }); // Radzen services @@ -40,4 +52,10 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +// New typed API clients (shared contracts) +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); + await builder.Build().RunAsync();