fix: KOSync authentication with Calibre-Web-Automated (#1951)

## Summary

* **What is the goal of this PR?** Fix regression of
Calibre-Web-Automated authentication
* **What changes are included?** Trivial fix using ESP HTTP Client
primitives

## Additional Context

Calibre-Web-Automated KOSync stopped working after refactoring HTTP
client to use `ESP HTTP Client`, resulting in a _Server error (try again
later)_ error.

---

### AI Usage

Did you use AI tools to help write this code? _**NO**_

---------

Co-authored-by: drbourbon <fabio@MacBook-Air-di-Fabio.local>
This commit is contained in:
Fabio Barbon
2026-05-13 08:32:18 -05:00
committed by GitHub
co-authored by drbourbon
parent 30b14f2ecf
commit 71518b3336
+5 -11
View File
@@ -2,7 +2,6 @@
#include <ArduinoJson.h>
#include <Logging.h>
#include <base64.h>
#include <esp_crt_bundle.h>
#include <esp_http_client.h>
@@ -75,6 +74,11 @@ esp_http_client_handle_t createClient(const char* url, ResponseBuffer* buf,
config.buffer_size_tx = HTTP_BUF_SIZE;
config.crt_bundle_attach = esp_crt_bundle_attach;
// HTTP Basic Auth for Calibre-Web-Automated compatibility
config.username = KOREADER_STORE.getUsername().c_str();
config.password = KOREADER_STORE.getPassword().c_str();
config.auth_type = HTTP_AUTH_TYPE_BASIC;
esp_http_client_handle_t client = esp_http_client_init(&config);
if (!client) return nullptr;
@@ -87,16 +91,6 @@ esp_http_client_handle_t createClient(const char* url, ResponseBuffer* buf,
return nullptr;
}
// HTTP Basic Auth for Calibre-Web-Automated compatibility
std::string credentials = KOREADER_STORE.getUsername() + ":" + KOREADER_STORE.getPassword();
String encoded = base64::encode(reinterpret_cast<const uint8_t*>(credentials.data()), credentials.size());
std::string authHeader = "Basic " + std::string(encoded.c_str());
if (esp_http_client_set_header(client, "Authorization", authHeader.c_str()) != ESP_OK) {
LOG_ERR("KOSync", "Failed to set Authorization header");
esp_http_client_cleanup(client);
return nullptr;
}
return client;
}
} // namespace