Test Failed
Push — master ( cb9afd...2b9e35 )
by Maximo
02:09
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
11
/**
12
 * Class TokenValidationMiddleware
13
 *
14
 * @package Gewaer\Middleware
15
 */
16
class TokenValidationMiddleware implements MiddlewareInterface
17
{
18
    /**
19
     * @param Micro $api
20
     *
21
     * @return bool
22
     * @throws ModelException
23
     */
24
    public function call(Micro $api)
25
    {
26
        $config = $api->getService('config');
27
28
        $auth = $api->getService('auth');
29
        // to get the payload
30
        $data = $auth->data();
31
32
        if (!empty($data) && $data['iat'] <= strtotime('-10 seconds')) {
33
            // return false to invalidate the authentication
34
            //throw new Exception("Old Request");
35
        }
36
37
        return true;
38
    }
39
}
40