From cc6e4cbf78f3715527a2cfa8c505f46806f88008 Mon Sep 17 00:00:00 2001 From: Baybars HAZAR Date: Mon, 28 Oct 2019 01:21:58 +0300 Subject: [PATCH 1/2] Update WebSocketClient.h Added basic auth lines. --- src/WebSocketClient.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/WebSocketClient.h b/src/WebSocketClient.h index 4b009e6..704c4d4 100644 --- a/src/WebSocketClient.h +++ b/src/WebSocketClient.h @@ -28,6 +28,8 @@ class WebSocketClient : public HttpClient */ int begin(const char* aPath = "/"); int begin(const String& aPath); + int begin(const char* username, const char* password); + int begin(const String& aPath, const char* username, const char* password); /** Begin to send a message of type (TYPE_TEXT or TYPE_BINARY) Use the write or Stream API's to set message content, followed by endMessage @@ -84,6 +86,9 @@ class WebSocketClient : public HttpClient void flushRx(); private: + bool hasAuth = false; + const char* _username; + const char* _password; bool iTxStarted; uint8_t iTxMessageType; uint8_t iTxBuffer[128]; From 37d1443d0e4b5dc64957d8fdbdd774e16ea00cf9 Mon Sep 17 00:00:00 2001 From: Baybars HAZAR Date: Mon, 28 Oct 2019 01:22:46 +0300 Subject: [PATCH 2/2] Basic auth added while connecting --- src/WebSocketClient.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/WebSocketClient.cpp b/src/WebSocketClient.cpp index ab41b0a..d96937a 100644 --- a/src/WebSocketClient.cpp +++ b/src/WebSocketClient.cpp @@ -51,6 +51,10 @@ int WebSocketClient::begin(const char* aPath) sendHeader("Connection", "Upgrade"); sendHeader("Sec-WebSocket-Key", base64RandomKey); sendHeader("Sec-WebSocket-Version", "13"); + + if(hasAuth) { + sendBasicAuth(_username, _password); + } endRequest(); status = responseStatusCode(); @@ -72,6 +76,23 @@ int WebSocketClient::begin(const String& aPath) return begin(aPath.c_str()); } +int WebSocketClient::begin(const char* username, const char* password) +{ + hasAuth = true; + _username = username; + _password = password; + return begin("/"); +} + +int WebSocketClient::begin(const String& aPath, const char* username, const char* password) +{ + hasAuth = true; + _username = username; + _password = password; + return begin(aPath.c_str()); +} + + int WebSocketClient::beginMessage(int aType) { if (iTxStarted)