Hello,
I'm creating a restapi using jwt authentication.
I'm decoding Jwt hashes in my auth filter like that:
PHP Code:
public function before(RequestInterface $request, $arguments = null)
{
$header = $_SERVER['HTTP_AUTHORIZATION'];
$token = null;
$response = Services::response();
$response->setJSON(['success' => false]);
$response->setStatusCode(401);
if (empty($header)) {
return $response;
}
preg_match('/Bearer\s(\S+)/', $header, $matches);
$token = $matches[1];
if (is_null($token) || empty($token)) {
return $response;
}
$key = getenv('JWT_SECRET');
try {
$user_id = JWT::decode($token, new Key($key, 'HS256'));
} catch (\Exception $ex) {
return $response;
}
}
And the goal is to pass $
user_id variable from the filter to the controller
What is the best way to do it?