From 227610fcb95a88af1b8f35fc8506d0d1200d4a17 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Tue, 9 Jul 2024 20:02:29 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=84=20Formats=20AuthenticationService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ESP32-sveltekit/AuthenticationService.cpp | 24 +++++++++---------- .../ESP32-sveltekit/AuthenticationService.h | 7 +++--- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/esp32/lib/ESP32-sveltekit/AuthenticationService.cpp b/esp32/lib/ESP32-sveltekit/AuthenticationService.cpp index 9350f52..c7c654d 100644 --- a/esp32/lib/ESP32-sveltekit/AuthenticationService.cpp +++ b/esp32/lib/ESP32-sveltekit/AuthenticationService.cpp @@ -16,16 +16,13 @@ #if FT_ENABLED(FT_SECURITY) -AuthenticationService::AuthenticationService(PsychicHttpServer *server, SecurityManager *securityManager) : _server(server), - _securityManager(securityManager) -{ -} +AuthenticationService::AuthenticationService(PsychicHttpServer *server, SecurityManager *securityManager) + : _server(server), _securityManager(securityManager) {} -void AuthenticationService::begin() -{ - // Signs in a user if the username and password match. Provides a JWT to be used in the Authorization header in subsequent requests - _server->on(SIGN_IN_PATH, HTTP_POST, [this](PsychicRequest *request, JsonVariant &json) - { +void AuthenticationService::begin() { + // Signs in a user if the username and password match. Provides a JWT to be used in the Authorization header in + // subsequent requests + _server->on(SIGN_IN_PATH, HTTP_POST, [this](PsychicRequest *request, JsonVariant &json) { if (json.is()) { String username = json["username"]; String password = json["password"]; @@ -37,15 +34,16 @@ void AuthenticationService::begin() return response.send(); } } - return request->reply(401); }); + return request->reply(401); + }); ESP_LOGV("AuthenticationService", "Registered POST endpoint: %s", SIGN_IN_PATH); // Verifies that the request supplied a valid JWT - _server->on(VERIFY_AUTHORIZATION_PATH, HTTP_GET, [this](PsychicRequest *request) - { + _server->on(VERIFY_AUTHORIZATION_PATH, HTTP_GET, [this](PsychicRequest *request) { Authentication authentication = _securityManager->authenticateRequest(request); - return request->reply(authentication.authenticated ? 200 : 401); }); + return request->reply(authentication.authenticated ? 200 : 401); + }); ESP_LOGV("AuthenticationService", "Registered GET endpoint: %s", VERIFY_AUTHORIZATION_PATH); } diff --git a/esp32/lib/ESP32-sveltekit/AuthenticationService.h b/esp32/lib/ESP32-sveltekit/AuthenticationService.h index eb9fe9a..2f932fc 100644 --- a/esp32/lib/ESP32-sveltekit/AuthenticationService.h +++ b/esp32/lib/ESP32-sveltekit/AuthenticationService.h @@ -24,14 +24,13 @@ #if FT_ENABLED(FT_SECURITY) -class AuthenticationService -{ -public: +class AuthenticationService { + public: AuthenticationService(PsychicHttpServer *server, SecurityManager *securityManager); void begin(); -private: + private: SecurityManager *_securityManager; PsychicHttpServer *_server; };