Closed aminhajali closed 3 weeks ago
in the WeSerial.cpp: void WebSerialClass::begin(AsyncWebServer server, const char url) { _server = server; _ws = new AsyncWebSocket("/wserial");
if (_authenticate) { _ws->setAuthentication(_username, _password); //<-- must use _ws->setAuthentication(_username.c_str(), _password.c_str()); }
What is the reason ? Pointers should still be valid within setAuthentication
@mathieucarbou Anyhow, I still updated it. It's in dev
branch
AsyncWebHandler& setAuthentication(const char *username, const char *password){ _username = String(username);_password = String(password); return *this; };
Released in v2.0.2
@aminhajali , Ah that's why the confusion. We recently switched to @mathieucarbou 's fork of AsyncWebServer. It has a lot of fixes and support Strings for setAuthentication
function. Ref: https://github.com/mathieucarbou/ESPAsyncWebServer/blob/main/src/ESPAsyncWebServer.h#L366
Release Ref: https://github.com/ayushsharma82/WebSerial/releases/tag/v2.0.0
I've juste tested in my project, I have the same code base (in pro):
void WebSerialLiteClass::setAuthentication(const String& username, const String& password) {
_username = username;
_password = password;
_authenticate = !_username.isEmpty() && !_password.isEmpty();
if (_ws != nullptr) {
_ws->setAuthentication(_username.c_str(), _password.c_str());
}
}
void WebSerialLiteClass::begin(AsyncWebServer *server, const char* url) {
_server = server;
_ws = new AsyncWebSocket("/wserial");
[...]
if (_authenticate) {
_ws->setAuthentication(_username.c_str(), _password.c_str());
}
I tested:
WebSerialLite.begin(&webServer, "/console");
WebSerialLite.setAuthentication(YASOLR_ADMIN_USERNAME, config.get(KEY_ADMIN_PASSWORD).c_str());
and
WebSerialLite.setAuthentication(YASOLR_ADMIN_USERNAME, config.get(KEY_ADMIN_PASSWORD).c_str());
WebSerialLite.begin(&webServer, "/console");
Both work fine. There is no pointer issue or dereferencing because the implementation is saving the string in a String
.
AsyncWebHandler& setAuthentication(const char *username, const char *password){ _username = String(username);_password = String(password); return *this; };
@aminhajali You are using the wrong fork.
@ayushsharma82 : but he has a point that to be backward compatible with existing ESPAsyncWebServer project and forks, setAuthentication(char *, char*)
should be used. I didn't pay attention to that fats when doing my PR... Sorry.
I'll mark it as closed. Fixed as of v2.0.2
.
@aminhajali Thanks for bringing this to our attention.
in the WeSerial.cpp: void WebSerialClass::begin(AsyncWebServer server, const char url) { _server = server; _ws = new AsyncWebSocket("/wserial");
if (_authenticate) { _ws->setAuthentication(_username, _password); //<-- must use _ws->setAuthentication(_username.c_str(), _password.c_str()); }