Add KeyPairing to /Tesla endpoint
All checks were successful
Build, Push and Run Container / build (push) Successful in 24s
All checks were successful
Build, Push and Run Container / build (push) Successful in 24s
This commit is contained in:
@@ -172,8 +172,7 @@ if (app.Environment.IsDevelopment())
|
||||
app.MapGet("/CheckRegisteredApplication", ([FromServices] ITeslaAuthenticatorService service) => service.CheckApplicationRegistrationAsync());
|
||||
app.MapGet("/RegisterApplication", ([FromServices] ITeslaAuthenticatorService service) => service.RegisterApplicationAsync());
|
||||
app.MapGet("/Authorize", async (IHttpContextAccessor contextAccessor) => await (contextAccessor.HttpContext!).ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/Tesla" }));
|
||||
app.MapGet("/KeyPairing", () => Results.Redirect("https://tesla.com/_ak/tesla-connector.automatic-parking.app"));
|
||||
app.MapGet("/KeyPairing2", () => Results.Redirect("https://tesla.com/_ak/automatic-parking.app"));
|
||||
app.MapGet("/KeyPairing", () => Results.Redirect("https://tesla.com/_ak/automatic-parking.app"));
|
||||
app.MapGet("/Tokens", async (IHttpContextAccessor httpContextAccessor) =>
|
||||
{
|
||||
var ctx = httpContextAccessor.HttpContext;
|
||||
@@ -252,9 +251,22 @@ if (app.Environment.IsDevelopment())
|
||||
|
||||
//Get cars
|
||||
VehiclesEnvelope? vehiclesEnvelope = await client.GetFromJsonAsync<VehiclesEnvelope>("/api/1/vehicles");
|
||||
string[] vins = vehiclesEnvelope?.Response.Select(x => x.Vin ?? "").Where(v => !String.IsNullOrWhiteSpace(v)).ToArray() ?? Array.Empty<string>();
|
||||
logger.LogCritical("User has access to {count} cars: {vins}", vins.Length, String.Join(", ", vins));
|
||||
string[] vinNumbers = vehiclesEnvelope?.Response.Select(x => x.Vin ?? "").Where(v => !String.IsNullOrWhiteSpace(v)).ToArray() ?? Array.Empty<string>();
|
||||
logger.LogCritical("User has access to {count} cars: {vins}", vinNumbers.Length, String.Join(", ", vinNumbers));
|
||||
|
||||
if (vinNumbers.Length == 0)
|
||||
return Results.Ok("No cars found");
|
||||
|
||||
//Check if key pairing is required
|
||||
var requestObject = new { vins = vinNumbers };
|
||||
HttpResponseMessage statusResponse = await client.PostAsJsonAsync("/api/1/vehicles/fleet_status", requestObject);
|
||||
string statusResponseContent = await statusResponse.Content.ReadAsStringAsync();
|
||||
logger.LogTrace("Status response: {statusResponseContent}", statusResponseContent);
|
||||
|
||||
FleetResponse? fleetResponse = JsonSerializer.Deserialize<FleetResponse>(statusResponseContent);
|
||||
|
||||
if (!fleetResponse?.KeyPairedVins.Any() ?? false)
|
||||
return Results.Redirect("/KeyPairing");
|
||||
|
||||
//Get CA from validate server file
|
||||
string fileContent = await File.ReadAllTextAsync("Resources/validate_server.json");
|
||||
@@ -262,7 +274,7 @@ if (app.Environment.IsDevelopment())
|
||||
|
||||
TelemetryConfigRequest configRequest = new TelemetryConfigRequest()
|
||||
{
|
||||
Vins = new List<string>(vins),
|
||||
Vins = new List<string>(vinNumbers),
|
||||
Config = new TelemetryConfig()
|
||||
{
|
||||
Hostname = "tesla-connector.automatic-parking.app",
|
||||
@@ -280,9 +292,6 @@ if (app.Environment.IsDevelopment())
|
||||
};
|
||||
logger.LogInformation("Config request: {configRequest}", JsonSerializer.Serialize(configRequest, new JsonSerializerOptions() { WriteIndented = true }));
|
||||
|
||||
if (vins.Length == 0)
|
||||
return Results.Ok("No cars found");
|
||||
|
||||
HttpResponseMessage response = await client.PostAsJsonAsync("/api/1/vehicles/fleet_telemetry_config", configRequest);
|
||||
return Results.Ok(response.Content.ReadAsStringAsync());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user