Skip to content

Commit e7fe434

Browse files
committed
authAll
1 parent 81b8137 commit e7fe434

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/AsyncFsWebServer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ void AsyncFsWebServer::sendOK(AsyncWebServerRequest *request) {
207207
}
208208

209209
void AsyncFsWebServer::notFound(AsyncWebServerRequest *request) {
210+
211+
// Check if authentication for all routes is turned on, and credentials are present:
212+
if (m_authAll && m_pageUser != nullptr) {
213+
if(!request->authenticate(m_pageUser, m_pagePswd))
214+
return request->requestAuthentication();
215+
}
216+
210217
String _url = request->url();
211218

212219
// Requested file not found, check if gzipped version exists

src/AsyncFsWebServer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class AsyncFsWebServer : public AsyncWebServer
9797
AsyncWebHandler *m_captive = nullptr;
9898
DNSServer* m_dnsServer = nullptr;
9999
bool m_isApMode = false;
100+
bool m_authAll = false;
100101

101102
void notFound(AsyncWebServerRequest *request);
102103
void handleFileName(AsyncWebServerRequest *request);
@@ -231,6 +232,12 @@ class AsyncFsWebServer : public AsyncWebServer
231232
Enable authenticate for /setup webpage
232233
*/
233234
void setAuthentication(const char* user, const char* pswd);
235+
/*
236+
Enable the flag which turns on basic authentication for all pages
237+
*/
238+
inline void requireAuthentication(bool require){
239+
m_authAll = require;
240+
}
234241

235242
/*
236243
List FS content

0 commit comments

Comments
 (0)