Hello.
I was wondering how you guys have implementet JWT in your application. The way i have done it, is by adding a beforeDispatch, that runs this code:
if (!isset($headers["Authorization"]) || empty($headers["Authorization"])) {
//devolvemos un 403, Forbidden
$response->setStatusCode(403, "Forbidden");
$response->send();
die();
}
$token = explode(" ", $headers["Authorization"]);
$token = trim($token[1], '"');
try {
JWT::$leeway = 60; // 60 seconds
$user = JWT::decode($token, $this->jwt_key, array('HS256'));
} catch (\Firebase\JWT\ExpiredException $e) {
$response->setStatusCode(405, $e->getMessage());
$response->send();
die();
}
This code is implemented in my module, as an event.
My question is, what is the best way to setup JWT for phalcon, maybe you have done this in a much smarter way?