From d366e7c539320f1cda609e739c6db60a366d3ffd Mon Sep 17 00:00:00 2001 From: omersiar Date: Mon, 30 Oct 2017 11:43:31 +0300 Subject: [PATCH] =?UTF-8?q?This=20re-enables=20previously=20removed=20WebS?= =?UTF-8?q?ocket=20authentication=20which=20is=20=E2=80=A6=20(#272)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * This re-enables previously removed WebSocket authentication which is orginaly implemented PR #143 * Update README.md --- README.md | 4 ++-- src/AsyncWebSocket.cpp | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 49826b7..b58a902 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ To use this library you might need to have the latest git versions of [ESP32](ht - [VZero](https://github.com/andig/vzero) - the Wireless zero-config controller for volkszaehler.org - [ESPurna](https://bitbucket.org/xoseperez/espurna) - ESPurna ("spark" in Catalan) is a custom C firmware for ESP8266 based smart switches. It was originally developed with the ITead Sonoff in mind. - [fauxmoESP](https://bitbucket.org/xoseperez/fauxmoesp) - Belkin WeMo emulator library for ESP8266. -- [ESP-RFID] (https://github.com/omersiar/esp-rfid) - MFRC522 RFID Access Control Management project for ESP8266. +- [ESP-RFID](https://github.com/omersiar/esp-rfid) - MFRC522 RFID Access Control Management project for ESP8266. ## Request Variables @@ -1365,4 +1365,4 @@ webServer.onNotFound([](AsyncWebServerRequest *request) { request->send(404); } }); -``` \ No newline at end of file +``` diff --git a/src/AsyncWebSocket.cpp b/src/AsyncWebSocket.cpp index 1479efd..7eeadac 100644 --- a/src/AsyncWebSocket.cpp +++ b/src/AsyncWebSocket.cpp @@ -1098,6 +1098,9 @@ void AsyncWebSocket::handleRequest(AsyncWebServerRequest *request){ request->send(400); return; } + if((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str())){ + return request->requestAuthentication(); + } AsyncWebHeader* version = request->getHeader(WS_STR_VERSION); if(version->value().toInt() != 13){ AsyncWebServerResponse *response = request->beginResponse(400);