reeplace cerberos by thalos

This commit is contained in:
Sergio Matias Urquin
2025-05-18 19:31:25 -06:00
parent 2519e1b4fb
commit bb87b0e148
59 changed files with 194 additions and 194 deletions

View File

@@ -0,0 +1,67 @@
using Core.Thalos.Adapters.Contracts;
using Core.Thalos.Adapters.Handlers;
using Core.Thalos.Adapters.TokenProvider;
using Core.Thalos.External.GatewayConfigurations;
using LSA.Dashboard.External.Clients.Dashboard;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Refit;
namespace Core.Thalos.External.ClientConfiguration
{
public static class RegisterClientConfiguration
{
public static IServiceCollection RegisterExternalLayer(this IServiceCollection services, IConfiguration configuration)
{
var gatewayConfiguration = new GatewayConfiguration();
var gatewaySettingsConfiguration = new GatewaySettingsConfigurations(configuration);
// Register GatewayConfiguration as a singleton
services.AddSingleton(gatewayConfiguration);
// Register IHttpContextAccessor
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
// Register ITokenProvider
services.AddSingleton<ITokenProvider, HttpContextTokenProvider>();
// Register the custom AuthenticatedHttpClientHandler
services.AddTransient(provider =>
{
var tokenProvider = provider.GetRequiredService<ITokenProvider>();
var trackingIdHandler = new TrackingMechanismExtension(provider.GetRequiredService<IHttpContextAccessor>());
var handler = new AuthenticatedHttpClientHandler(tokenProvider)
{
InnerHandler = new HttpClientHandler() // Setting the InnerHandler manually
};
// Attach the TrackingIdHandler as the outermost handler
trackingIdHandler.InnerHandler = handler;
return handler;
});
var thalosServiceApiUrl = GatewaySettingsConfigurations.GetThalosServiceAPIEndpoint().Endpoint.Url;
// Register IDashBoardServiceClient with the manually created HttpClient
services.AddScoped(provider =>
{
var handler = provider.GetRequiredService<AuthenticatedHttpClientHandler>();
var handlerTrackingId = new TrackingMechanismExtension(provider.GetRequiredService<IHttpContextAccessor>()); // Using the TrackingIdHandler here
// Chain the handlers
handlerTrackingId.InnerHandler = handler; //chaining
var httpClient = new HttpClient(handlerTrackingId)
{
BaseAddress = new Uri(thalosServiceApiUrl),
Timeout = TimeSpan.FromMinutes(1)
};
return RestService.For<IThalosServiceClient>(httpClient);
});
return services;
}
}
}