Failed Conditions
Pull Request — master (#10)
by Maximo
03:08
created

library/Middleware/TokenValidationMiddleware.php (1 issue)

1
<?php
0 ignored issues
show
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
2
3
declare(strict_types=1);
4
5
namespace Gewaer\Middleware;
6
7
use Gewaer\Exception\ModelException;
8
use Phalcon\Mvc\Micro;
9
use Phalcon\Mvc\Micro\MiddlewareInterface;
10
use Phalcon\Http\Request;
11
use Exception;
12
13
/**
14
 * Class TokenValidationMiddleware
15
 *
16
 * @package Gewaer\Middleware
17
 */
18
class TokenValidationMiddleware implements MiddlewareInterface
19
{
20
    /**
21
     * @param Micro $api
22
     *
23
     * @return bool
24
     * @throws ModelException
25
     */
26 2
    public function call(Micro $api)
27
    {
28 2
        $config = $api->getService('config');
29
30 2
        $auth = $api->getService('auth');
31
        // to get the payload
32 2
        $data = $auth->data();
33
34 2
        if (!empty($data) && $data['iat'] <= strtotime('-10 seconds')) {
35
            // return false to invalidate the authentication
36
            //throw new Exception("Old Request");
37
        }
38
39 2
        return true;
40
    }
41
}
42