1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-08 14:22:21 +01:00

Basic Auth for web_server component (#674)

* Basic auth

* Test

* Linter fix

* Make username/password strict strings

Reason: passwords only consisting of digits (012345) will be silently converted (to "12345")


Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
Nikolay Vasilchuk
2019-10-13 15:27:44 +03:00
committed by Otto Winter
parent 1a763ae974
commit b2388b6fe7
5 changed files with 30 additions and 1 deletions

View File

@@ -119,6 +119,9 @@ void WebServer::setup() {
void WebServer::dump_config() {
ESP_LOGCONFIG(TAG, "Web Server:");
ESP_LOGCONFIG(TAG, " Address: %s:%u", network_get_address().c_str(), this->base_->get_port());
if (this->using_auth()) {
ESP_LOGCONFIG(TAG, " Basic authentication enabled");
}
}
float WebServer::get_setup_priority() const { return setup_priority::WIFI - 1.0f; }
@@ -490,6 +493,10 @@ bool WebServer::canHandle(AsyncWebServerRequest *request) {
return false;
}
void WebServer::handleRequest(AsyncWebServerRequest *request) {
if (this->using_auth() && !request->authenticate(this->username_, this->password_)) {
return request->requestAuthentication();
}
if (request->url() == "/") {
this->handle_index_request(request);
return;