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
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
using JdeScoping.Client;
|
using JdeScoping.Client;
|
||||||
using JdeScoping.Client.Auth;
|
using JdeScoping.Client.Auth;
|
||||||
|
using JdeScoping.Client.Http;
|
||||||
using JdeScoping.Client.Services;
|
using JdeScoping.Client.Services;
|
||||||
|
using JdeScoping.Core.ApiContracts;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components.Authorization;
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
using Microsoft.AspNetCore.Components.Web;
|
using Microsoft.AspNetCore.Components.Web;
|
||||||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
|
||||||
@@ -10,11 +13,20 @@ var builder = WebAssemblyHostBuilder.CreateDefault(args);
|
|||||||
builder.RootComponents.Add<App>("#app");
|
builder.RootComponents.Add<App>("#app");
|
||||||
builder.RootComponents.Add<HeadOutlet>("head::after");
|
builder.RootComponents.Add<HeadOutlet>("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
|
// In Blazor WebAssembly, the browser automatically handles cookies for same-origin requests
|
||||||
builder.Services.AddScoped(sp => new HttpClient
|
builder.Services.AddScoped<AuthRedirectHandler>();
|
||||||
|
builder.Services.AddScoped(sp =>
|
||||||
{
|
{
|
||||||
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
|
var navigationManager = sp.GetRequiredService<NavigationManager>();
|
||||||
|
var handler = new AuthRedirectHandler(navigationManager)
|
||||||
|
{
|
||||||
|
InnerHandler = new HttpClientHandler()
|
||||||
|
};
|
||||||
|
return new HttpClient(handler)
|
||||||
|
{
|
||||||
|
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Radzen services
|
// Radzen services
|
||||||
@@ -40,4 +52,10 @@ builder.Services.AddScoped<ILookupService, LookupService>();
|
|||||||
builder.Services.AddScoped<IFileService, FileService>();
|
builder.Services.AddScoped<IFileService, FileService>();
|
||||||
builder.Services.AddScoped<IRefreshStatusService, RefreshStatusService>();
|
builder.Services.AddScoped<IRefreshStatusService, RefreshStatusService>();
|
||||||
|
|
||||||
|
// New typed API clients (shared contracts)
|
||||||
|
builder.Services.AddScoped<ISearchApiClient, SearchApiClient>();
|
||||||
|
builder.Services.AddScoped<ILookupApiClient, LookupApiClient>();
|
||||||
|
builder.Services.AddScoped<IAuthApiClient, AuthApiClient>();
|
||||||
|
builder.Services.AddScoped<IFileApiClient, FileApiClient>();
|
||||||
|
|
||||||
await builder.Build().RunAsync();
|
await builder.Build().RunAsync();
|
||||||
|
|||||||
Reference in New Issue
Block a user