Refactors Tesla OIDC configuration retrieval
All checks were successful
Build, Push and Run Container / build (push) Successful in 23s

Replaces the default document retriever with a custom implementation.

This change simplifies the configuration by embedding the HTTP document retriever directly within the custom retriever, and centralizes the URL replacement logic for Tesla's OIDC configuration. This avoids injecting the HttpDocumentRetriever into the TeslaDocumentRetriever constructor and makes the code more maintainable.
This commit is contained in:
2025-08-17 00:35:34 +02:00
parent 8442fb8f05
commit 06514e2929

View File

@@ -15,7 +15,7 @@ public sealed class TeslaOIDCConfigurationManager : IConfigurationManager<OpenId
public TeslaOIDCConfigurationManager(string metadataAddress)
{
_inner = new ConfigurationManager<OpenIdConnectConfiguration>(metadataAddress, new OpenIdConnectConfigurationRetriever(), new HttpDocumentRetriever());
_inner = new ConfigurationManager<OpenIdConnectConfiguration>(metadataAddress, new OpenIdConnectConfigurationRetriever(), new TeslaDocumentRetriever());
}
public async Task<OpenIdConnectConfiguration> GetConfigurationAsync(CancellationToken cancel)
@@ -37,16 +37,10 @@ public sealed class TeslaOIDCConfigurationManager : IConfigurationManager<OpenId
public class TeslaDocumentRetriever : IDocumentRetriever
{
private readonly HttpDocumentRetriever httpDocumentRetriever;
public TeslaDocumentRetriever(HttpDocumentRetriever httpDocumentRetriever)
{
this.httpDocumentRetriever = httpDocumentRetriever;
}
private readonly HttpDocumentRetriever httpDocumentRetriever = new HttpDocumentRetriever();
public async Task<string> GetDocumentAsync(string address, CancellationToken cancel)
{
address = address.Replace("https://fleet-auth.tesla.com/oauth2/v3", "https://fleet-auth.prd.vn.cloud.tesla.com/oauth2/v3");
string document = await this.httpDocumentRetriever.GetDocumentAsync(address, cancel);
return document.Replace("https://fleet-auth.tesla.com/oauth2/v3", "https://fleet-auth.prd.vn.cloud.tesla.com/oauth2/v3");
}