1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Gewaer\Traits; |
||
6 | |||
7 | use Baka\Http\RouterCollection; |
||
8 | use Phalcon\Mvc\Router\Route; |
||
9 | |||
10 | /** |
||
11 | * Trait TokenTrait. |
||
12 | * |
||
13 | * @package Niden\Traits |
||
14 | */ |
||
15 | trait RequestJwtTrait |
||
16 | { |
||
17 | /** |
||
18 | * @return string |
||
19 | */ |
||
20 | 61 | public function getBearerTokenFromHeader(): string |
|
21 | { |
||
22 | 61 | return str_replace('Bearer ', '', $this->getHeader('Authorization')); |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
23 | } |
||
24 | |||
25 | /** |
||
26 | * @return bool |
||
27 | */ |
||
28 | 61 | public function isEmptyBearerToken(): bool |
|
29 | { |
||
30 | 61 | return empty($this->getBearerTokenFromHeader()); |
|
31 | } |
||
32 | |||
33 | /** |
||
34 | * Did we specify we dont need to validate JWT Token on this section? |
||
35 | * |
||
36 | * @return bool |
||
37 | */ |
||
38 | 69 | public function ignoreJwt(Route $route) : bool |
|
39 | { |
||
40 | //did we find the router? |
||
41 | 69 | if (is_array(RouterCollection::getJwtIgnoreRoutes()[$route->getHttpMethods()])) { |
|
42 | 69 | return isset(RouterCollection::getJwtIgnoreRoutes()[$route->getHttpMethods()][md5($route->getPattern())]); |
|
43 | } |
||
44 | |||
45 | //nop we dont have this route in ignore jwt |
||
46 | 22 | return false; |
|
47 | } |
||
48 | } |
||
49 |