bakaphp /
phalcon-api
| 1 | <?php |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
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 |