File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,13 @@ void AsyncFsWebServer::sendOK(AsyncWebServerRequest *request) {
207207}
208208
209209void 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments