🪄 Formats AuthenticationService

This commit is contained in:
Rune Harlyk
2024-07-09 20:02:29 +02:00
committed by Rune Harlyk
parent 4952be1b47
commit 227610fcb9
2 changed files with 14 additions and 17 deletions
@@ -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<JsonObject>()) {
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);
}
@@ -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;
};