feat(maui): resolve 401 load error by registering MobileAuthenticationHeaderHandler with configuration-based API host
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NexusReader.Application.Abstractions.Services;
|
||||
using NexusReader.Infrastructure.Mobile.Services;
|
||||
using NexusReader.UI.Shared.Services;
|
||||
using NexusReader.Application;
|
||||
using MediatR;
|
||||
using NexusReader.Maui.Infrastructure.Logging;
|
||||
using NexusReader.Maui.Infrastructure.Identity;
|
||||
|
||||
namespace NexusReader.Maui;
|
||||
|
||||
@@ -50,8 +52,15 @@ public static class MauiProgram
|
||||
sp.GetRequiredService<NexusAuthenticationStateProvider>());
|
||||
builder.Services.AddAuthorizationCore();
|
||||
|
||||
// Basic Network
|
||||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://10.0.2.2:5000") });
|
||||
// Basic Network with Secure Token Handler
|
||||
builder.Services.AddTransient<MobileAuthenticationHeaderHandler>();
|
||||
builder.Services.AddHttpClient("NexusAPI", client =>
|
||||
{
|
||||
var apiBaseUrl = builder.Configuration["ApiSettings:BaseUrl"] ?? "http://localhost:5000";
|
||||
client.BaseAddress = new Uri(apiBaseUrl);
|
||||
}).AddHttpMessageHandler<MobileAuthenticationHeaderHandler>();
|
||||
|
||||
builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("NexusAPI"));
|
||||
|
||||
// UI State
|
||||
builder.Services.AddScoped<IThemeService, ThemeService>();
|
||||
|
||||
Reference in New Issue
Block a user