From 0ac37d198c6704a983747331e6a075c85cf4aac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szak=C3=A1ts=20Alp=C3=A1r=20Zsolt?= Date: Sun, 17 Aug 2025 12:17:01 +0200 Subject: [PATCH] Configures insecure HTTP client for proxy Adds named HTTP client configuration with insecure settings to communicate with the tesla_command_proxy, which uses a self-signed certificate. Changes the base address to use HTTPS. --- Source/ProofOfConcept/Program.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Source/ProofOfConcept/Program.cs b/Source/ProofOfConcept/Program.cs index 2d25776..7428967 100644 --- a/Source/ProofOfConcept/Program.cs +++ b/Source/ProofOfConcept/Program.cs @@ -26,11 +26,16 @@ builder.Services.AddOpenApi(); builder.Services.AddMediator(); builder.Services.AddMemoryCache(); builder.Services.AddHybridCache(); -builder.Services.AddHttpClient(); builder.Services.AddRazorPages(); builder.Services.AddHealthChecks() .AddAsyncCheck("", cancellationToken => Task.FromResult(HealthCheckResult.Healthy()), ["ready"]); //TODO: Check tag builder.Services.AddHttpContextAccessor(); +builder.Services.AddHttpClient().AddHttpClient("InsecureClient") + .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler + { + ServerCertificateCustomValidationCallback = + HttpClientHandler.DangerousAcceptAnyServerCertificateValidator + }); builder.Services .AddAuthentication(o => @@ -239,9 +244,9 @@ if (app.Environment.IsDevelopment()) if (String.IsNullOrEmpty(access_token)) return Results.LocalRedirect("/Authorize"); - - HttpClient client = httpClientFactory.CreateClient(); - client.BaseAddress = new Uri("tesla_command_proxy"); + + HttpClient client = httpClientFactory.CreateClient("InsecureClient"); + client.BaseAddress = new Uri("https://tesla_command_proxy"); client.DefaultRequestHeaders.Add("Authorization", $"Bearer {access_token}"); client.DefaultRequestHeaders.Add("Content-Type", "application/json");