Simplifies authentication logic and adds VIN.
All checks were successful
Build, Push and Run Container / build (push) Successful in 35s
All checks were successful
Build, Push and Run Container / build (push) Successful in 35s
Removes temporary test endpoints and refactors the authorize endpoint. Adds support for VIN notifications for a new vehicle by adding it to the dictionary.
This commit is contained in:
@@ -174,7 +174,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 ([FromQuery] string redirect, [FromServices] IHttpContextAccessor contextAccessor) => await (contextAccessor.HttpContext!).ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties { RedirectUri = redirect }));
|
||||
app.MapGet("/Authorize", async ([FromQuery] string redirect, [FromServices] IHttpContextAccessor contextAccessor) => await (contextAccessor.HttpContext!).ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties() { RedirectUri = redirect }));
|
||||
app.MapGet("/KeyPairing", () => Results.Redirect("https://tesla.com/_ak/automatic-parking.app"));
|
||||
app.MapGet("/Tokens", async (IHttpContextAccessor httpContextAccessor) =>
|
||||
{
|
||||
@@ -339,108 +339,6 @@ if (app.Environment.IsDevelopment())
|
||||
});
|
||||
}
|
||||
|
||||
app.MapGet("/RePair", async ([FromServices] ILogger<Configurator> logger, [FromServices] IHttpClientFactory httpClientFactory) =>
|
||||
{
|
||||
string access_token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InFEc3NoM2FTV0cyT05YTTdLMzFWV0VVRW5BNCJ9.eyJpc3MiOiJodHRwczovL2ZsZWV0LWF1dGgudGVzbGEuY29tL29hdXRoMi92My9udHMiLCJhenAiOiJiMjI0MGVlNC0zMzJhLTQyNTItOTFhYS1iYmNjMjRmNzhmZGIiLCJzdWIiOiJkZDg3Mzc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YWasfFhQZQisSfSusCgpGvHRVsyuLbOtd2fQ";
|
||||
|
||||
HttpClient client = httpClientFactory.CreateClient("InsecureClient");
|
||||
client.BaseAddress = new Uri("https://tesla_command_proxy");
|
||||
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {access_token}");
|
||||
|
||||
//Get fleet_status endpoint
|
||||
string vin = "5YJ3E7EB7KF291652";
|
||||
|
||||
var resp = await client.DeleteAsync($"/api/1/vehicles/{vin}/fleet_telemetry_config");
|
||||
logger.LogInformation("Fleet telemetry remove response ({ResponseStatusCode}): {ResponseContent}): ", resp.StatusCode, await resp.Content.ReadAsStringAsync());;
|
||||
|
||||
//Get CA from validate server file
|
||||
string fileContent = await File.ReadAllTextAsync("Resources/validate_server.json");
|
||||
ValidationModel? vm = JsonSerializer.Deserialize<ValidationModel>(fileContent);
|
||||
|
||||
TelemetryConfigRequest configRequest = new TelemetryConfigRequest()
|
||||
{
|
||||
Vins = new List<string>() { vin },
|
||||
Config = new TelemetryConfig()
|
||||
{
|
||||
Hostname = "tesla-telemetry.automatic-parking.app",
|
||||
Port = 443,
|
||||
CertificateAuthority = vm?.CA ?? "EMPTY",
|
||||
Fields = new Dictionary<string, TelemetryFieldConfig>()
|
||||
{
|
||||
{ "Gear", new TelemetryFieldConfig() { IntervalSeconds = 60 } },
|
||||
{ "Locked", new TelemetryFieldConfig() { IntervalSeconds = 60 } },
|
||||
{ "DriverSeatOccupied", new TelemetryFieldConfig() { IntervalSeconds = 60 } },
|
||||
{ "GpsState", new TelemetryFieldConfig() { IntervalSeconds = 60 } },
|
||||
{ "Location", new TelemetryFieldConfig() { IntervalSeconds = 60 } },
|
||||
}
|
||||
}
|
||||
};
|
||||
logger.LogInformation("Config request: {configRequest}", JsonSerializer.Serialize(configRequest, new JsonSerializerOptions() { WriteIndented = true }));
|
||||
|
||||
HttpResponseMessage response = await client.PostAsJsonAsync("/api/1/vehicles/fleet_telemetry_config", configRequest);
|
||||
|
||||
return Results.Ok(response.Content.ReadAsStringAsync());
|
||||
});
|
||||
|
||||
app.MapGet("/Status", async ([FromServices] ILogger<Configurator> logger, [FromServices] IHttpClientFactory httpClientFactory) =>
|
||||
{
|
||||
string access_token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InFEc3NoM2FTV0cyT05YTTdLMzFWV0VVRW5BNCJ9.eyJpc3MiOiJodHRwczovL2ZsZWV0LWF1dGgudGVzbGEuY29tL29hdXRoMi92My9udHMiLCJhenAiOiJiMjI0MGVlNC0zMzJhLTQyNTItOTFhYS1iYmNjMjRmNzhmZGIiLCJzdWIiOiJkZDg3Mzc4OC00ZjliLTQyY2UtYmRkNi00YzdmMjQxOGMwN2UiLCJhdWQiOlsiaHR0cHM6Ly9mbGVldC1hcGkucHJkLm5hLnZuLmNsb3VkLnRlc2xhLmNvbSIsImh0dHBzOi8vZmxlZXQtYXBpLnByZC5ldS52bi5jbG91ZC50ZXNsYS5jb20iLCJodHRwczovL2ZsZWV0LWF1dGgudGVzbGEuY29tL29hdXRoMi92My91c2VyaW5mbyJdLCJzY3AiOlsib3BlbmlkIiwib2ZmbGluZV9hY2Nlc3MiLCJ2ZWhpY2xlX2RldmljZV9kYXRhIiwidmVoaWNsZV9sb2NhdGlvbiJdLCJhbXIiOlsicHdkIl0sImV4cCI6MTc1NTgwODkzNSwiaWF0IjoxNzU1NzgwMTM1LCJvdV9jb2RlIjoiRVUiLCJsb2NhbGUiOiJodS1IVSIsImFjY291bnRfdHlwZSI6InBlcnNvbiIsIm9wZW5fc291cmNlIjpmYWxzZSwiYWNjb3VudF9pZCI6IjE5YTBhZjRmLTY1ZDgtNDc2MC1hYjVmLTZjMzk3ZTViMTI4ZiIsImF1dGhfdGltZSI6MTc1NTc4MDEzNCwibm9uY2UiOiI2Mzg5MTM3NjkyNDEzMDI0MjMuTmpBNE0yWmpOalV0Wmpkak9DMDBabVF6TFdFeVlqa3RaR05rWVRKa01HSTRZMll6TnpKa09HSTNPV0V0Wmprd055MDBPREZpTFdGbE1UQXRNbVV4WlRnME1UZG1PV00xIn0.IAfZApY-P3HkRp4U2oO_T2DUFplbGfwuOfnXihcnlmiGKxKSSSuJ5aI76pcaDg9saxrhIhg17KjmEC4gL90ByDk6P7KUMp_xot0FN1Vtwy3C8_NDltebhZdM2emR5N7QHXdP4OYAQNvHwanRwBUeQthQ8pFUk9-fDzsZhwkTjrGYtvpQKZK-pn5GCLIKLib4AemsidCtfOlObjgqTd6wf_Tdb2dkbt-ACNIueTcmfXt-eFUZVRySwrvOb5pOWAUkjTUCpW074ySJjj_TDYheQHA9aTZsDJWCUNHC-51qnawiUvh-LwYWasfFhQZQisSfSusCgpGvHRVsyuLbOtd2fQ";
|
||||
|
||||
HttpClient client = httpClientFactory.CreateClient("InsecureClient");
|
||||
client.BaseAddress = new Uri("https://tesla_command_proxy");
|
||||
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {access_token}");
|
||||
|
||||
//Get fleet_status endpoint
|
||||
string vin = "5YJ3E7EB7KF291652";
|
||||
|
||||
var requestObject = new { vins = new string[] { vin } };
|
||||
HttpResponseMessage statusResponse = await client.PostAsJsonAsync("/api/1/vehicles/fleet_status", requestObject);
|
||||
string statusResponseContent = await statusResponse.Content.ReadAsStringAsync();
|
||||
logger.LogTrace("Fleet status response: {statusResponseContent}", statusResponseContent);
|
||||
|
||||
HttpResponseMessage rspmsg = await client.GetAsync($"/api/1/vehicles/{vin}/fleet_telemetry_config");
|
||||
string rsp = await rspmsg.Content.ReadAsStringAsync();
|
||||
logger.LogInformation("Telemetry config: {response}", rsp);
|
||||
|
||||
HttpResponseMessage responseMessage = await client.GetAsync($"/api/1/vehicles/{vin}/fleet_telemetry_errors");
|
||||
string response = await responseMessage.Content.ReadAsStringAsync();
|
||||
logger.LogInformation("Telemetry errors: {response}", response);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("Fleet status:");
|
||||
sb.AppendLine(statusResponseContent);
|
||||
sb.AppendLine();
|
||||
sb.AppendLine("Telemetry config:");
|
||||
sb.AppendLine(rsp);
|
||||
sb.AppendLine();
|
||||
sb.AppendLine("Telemetry errors:");
|
||||
sb.AppendLine(response);
|
||||
|
||||
return Results.Ok(sb.ToString());
|
||||
});
|
||||
|
||||
app.MapGet("/TestStartParking", async ([FromQuery] double latitude, [FromQuery] double longitude, [FromServices] ILogger<Configurator> logger, [FromServices] MessageProcessor messageProcessor) =>
|
||||
{
|
||||
logger.LogTrace("Test Start Parking...");
|
||||
|
||||
await messageProcessor.ProcessMessage("5YJ3E7EB7KF291652", "location", $"{{\"latitude\":{latitude},\"longitude\":{longitude}}}");
|
||||
await messageProcessor.ProcessMessage("5YJ3E7EB7KF291652", "gear", "P");
|
||||
await messageProcessor.ProcessMessage("5YJ3E7EB7KF291652", "locked", "true");
|
||||
await messageProcessor.ProcessMessage("5YJ3E7EB7KF291652", "driverseatoccupied", "false");
|
||||
|
||||
logger.LogInformation("All messages sent");
|
||||
});
|
||||
|
||||
app.MapGet("/TestStopParking", async ([FromServices] ILogger<Configurator> logger, [FromServices] MessageProcessor messageProcessor) =>
|
||||
{
|
||||
logger.LogTrace("Test Stop Parking...");
|
||||
|
||||
await messageProcessor.ProcessMessage("5YJ3E7EB7KF291652", "locked", "false");
|
||||
await messageProcessor.ProcessMessage("5YJ3E7EB7KF291652", "gear", "D");
|
||||
|
||||
logger.LogInformation("All messages sent");
|
||||
});
|
||||
|
||||
app.MapGet("/Zone", async ([FromQuery] double latitude, [FromQuery] double longitude, [FromServices] ILogger<Configurator> logger, [FromServices] ZoneDeterminatorService zoneDeterminator) =>
|
||||
{
|
||||
logger.LogTrace("Getting zone for: {latitude}, {longitude}...", latitude, longitude);
|
||||
|
||||
Reference in New Issue
Block a user