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 | 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 | public function call(Micro $api) |
||
| 27 | {
|
||
| 28 | $config = $api->getService('config');
|
||
| 29 | |||
| 30 | $auth = $api->getService('auth');
|
||
| 31 | // to get the payload |
||
| 32 | $data = $auth->data(); |
||
| 33 | |||
| 34 | if (!empty($data) && $data['iat'] <= strtotime('-10 seconds')) {
|
||
| 35 | // return false to invalidate the authentication |
||
| 36 | //throw new Exception("Old Request");
|
||
| 37 | } |
||
| 38 | |||
| 39 | return true; |
||
| 40 | } |
||
| 41 | } |
||
| 42 |