Fix 1813
This commit is contained in:
		| @@ -21,7 +21,7 @@ public class CurlElectoralApiService : IElectoralApiService | |||||||
|   { |   { | ||||||
|     _logger = logger; |     _logger = logger; | ||||||
|     _configuration = configuration; |     _configuration = configuration; | ||||||
|         _baseUrl = _configuration["ElectoralApi:BaseUrl"] ?? ""; |     _baseUrl = _configuration["ElectoralApi__BaseUrl"] ?? ""; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   private async Task<(int, string)> ExecuteCurlCommand(string arguments) |   private async Task<(int, string)> ExecuteCurlCommand(string arguments) | ||||||
| @@ -57,16 +57,28 @@ public class CurlElectoralApiService : IElectoralApiService | |||||||
|  |  | ||||||
|   public async Task<string?> GetAuthTokenAsync() |   public async Task<string?> GetAuthTokenAsync() | ||||||
|   { |   { | ||||||
|         var username = _configuration["ElectoralApi:Username"]; |     var username = _configuration["ElectoralApi__Username"]; | ||||||
|         var password = _configuration["ElectoralApi:Password"]; |     var password = _configuration["ElectoralApi__Password"]; // OJO: Verifica el nombre exacto de la variable en tu .env | ||||||
|     var arguments = $"-s -H \"username: {username}\" -H \"password: {password}\" \"{_baseUrl}/api/createtoken\""; |     var arguments = $"-s -H \"username: {username}\" -H \"password: {password}\" \"{_baseUrl}/api/createtoken\""; | ||||||
|  |  | ||||||
|     var (status, output) = await ExecuteCurlCommand(arguments); |     var (status, output) = await ExecuteCurlCommand(arguments); | ||||||
|         if (status != 200) return null; |     if (status != 200) | ||||||
|  |     { | ||||||
|  |       _logger.LogError("Curl recibió un código de estado no exitoso. Respuesta: {Output}", output); | ||||||
|  |       return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     try | ||||||
|  |     { | ||||||
|       var tokenResponse = JsonSerializer.Deserialize<TokenResponse>(output); |       var tokenResponse = JsonSerializer.Deserialize<TokenResponse>(output); | ||||||
|       return tokenResponse?.Data?.AccessToken; |       return tokenResponse?.Data?.AccessToken; | ||||||
|     } |     } | ||||||
|  |     catch (JsonException ex) | ||||||
|  |     { | ||||||
|  |       _logger.LogError(ex, "Falló la deserialización del JSON. La respuesta del servidor NO era un JSON válido. Respuesta recibida: {Output}", output); | ||||||
|  |       return null; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|   // Implementa los demás métodos de la interfaz usando el mismo patrón |   // Implementa los demás métodos de la interfaz usando el mismo patrón | ||||||
|   // ... |   // ... | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user