bakaphp /
phalcon-api
| 1 | <?php |
||
| 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\Http\Request; |
||
| 10 | use Gewaer\Models\Users; |
||
| 11 | use Gewaer\Exception\PermissionException; |
||
| 12 | use Baka\Http\RouterCollection; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Class TokenValidationMiddleware. |
||
| 16 | * |
||
| 17 | * @package Gewaer\Middleware |
||
| 18 | */ |
||
| 19 | class TokenValidationMiddleware extends TokenBase |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @param Micro $api |
||
| 23 | * |
||
| 24 | * @return bool |
||
| 25 | * @throws ModelException |
||
| 26 | */ |
||
| 27 | 69 | public function call(Micro $api) |
|
| 28 | { |
||
| 29 | /** @var Request $request */ |
||
| 30 | 69 | $request = $api->getService('request'); |
|
| 31 | |||
| 32 | 69 | if ($this->isValidCheck($request, $api)) { |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 33 | /** |
||
| 34 | * This is where we will validate the token that was sent to us |
||
| 35 | * using Bearer Authentication. |
||
| 36 | * |
||
| 37 | * Find the user attached to this token |
||
| 38 | */ |
||
| 39 | 61 | $token = $this->getToken($request->getBearerTokenFromHeader()); |
|
| 40 | |||
| 41 | 61 | if (!$token->validate(Users::getValidationData($token->getHeader('jti')))) { |
|
| 42 | throw new PermissionException('Invalid Token'); |
||
| 43 | //return false; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | 69 | return true; |
|
| 48 | } |
||
| 49 | } |
||
| 50 |