🪄 Formats AuthenticationService
This commit is contained in:
@@ -16,16 +16,13 @@
|
|||||||
|
|
||||||
#if FT_ENABLED(FT_SECURITY)
|
#if FT_ENABLED(FT_SECURITY)
|
||||||
|
|
||||||
AuthenticationService::AuthenticationService(PsychicHttpServer *server, SecurityManager *securityManager) : _server(server),
|
AuthenticationService::AuthenticationService(PsychicHttpServer *server, SecurityManager *securityManager)
|
||||||
_securityManager(securityManager)
|
: _server(server), _securityManager(securityManager) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void AuthenticationService::begin()
|
void AuthenticationService::begin() {
|
||||||
{
|
// Signs in a user if the username and password match. Provides a JWT to be used in the Authorization header in
|
||||||
// Signs in a user if the username and password match. Provides a JWT to be used in the Authorization header in subsequent requests
|
// subsequent requests
|
||||||
_server->on(SIGN_IN_PATH, HTTP_POST, [this](PsychicRequest *request, JsonVariant &json)
|
_server->on(SIGN_IN_PATH, HTTP_POST, [this](PsychicRequest *request, JsonVariant &json) {
|
||||||
{
|
|
||||||
if (json.is<JsonObject>()) {
|
if (json.is<JsonObject>()) {
|
||||||
String username = json["username"];
|
String username = json["username"];
|
||||||
String password = json["password"];
|
String password = json["password"];
|
||||||
@@ -37,15 +34,16 @@ void AuthenticationService::begin()
|
|||||||
return response.send();
|
return response.send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return request->reply(401); });
|
return request->reply(401);
|
||||||
|
});
|
||||||
|
|
||||||
ESP_LOGV("AuthenticationService", "Registered POST endpoint: %s", SIGN_IN_PATH);
|
ESP_LOGV("AuthenticationService", "Registered POST endpoint: %s", SIGN_IN_PATH);
|
||||||
|
|
||||||
// Verifies that the request supplied a valid JWT
|
// 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);
|
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);
|
ESP_LOGV("AuthenticationService", "Registered GET endpoint: %s", VERIFY_AUTHORIZATION_PATH);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,14 +24,13 @@
|
|||||||
|
|
||||||
#if FT_ENABLED(FT_SECURITY)
|
#if FT_ENABLED(FT_SECURITY)
|
||||||
|
|
||||||
class AuthenticationService
|
class AuthenticationService {
|
||||||
{
|
public:
|
||||||
public:
|
|
||||||
AuthenticationService(PsychicHttpServer *server, SecurityManager *securityManager);
|
AuthenticationService(PsychicHttpServer *server, SecurityManager *securityManager);
|
||||||
|
|
||||||
void begin();
|
void begin();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SecurityManager *_securityManager;
|
SecurityManager *_securityManager;
|
||||||
PsychicHttpServer *_server;
|
PsychicHttpServer *_server;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user