1 | <?php |
||
10 | class JWTService implements JWTServiceInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var AppOptions |
||
14 | */ |
||
15 | private $appOptions; |
||
16 | |||
17 | /** |
||
18 | * JWTService constructor. |
||
19 | * @param AppOptions $appOptions |
||
20 | * |
||
21 | * @Inject({AppOptions::class}) |
||
22 | */ |
||
23 | 6 | public function __construct(AppOptions $appOptions) |
|
27 | |||
28 | /** |
||
29 | * Creates a new JSON web token por provided API key |
||
30 | * |
||
31 | * @param ApiKey $apiKey |
||
32 | * @param int $lifetime |
||
33 | * @return string |
||
34 | */ |
||
35 | 1 | public function create(ApiKey $apiKey, $lifetime = self::DEFAULT_LIFETIME) |
|
47 | |||
48 | /** |
||
49 | * Refreshes a token and returns it with the new expiration |
||
50 | * |
||
51 | * @param string $jwt |
||
52 | * @param int $lifetime |
||
53 | * @return string |
||
54 | * @throws AuthenticationException If the token has expired |
||
55 | */ |
||
56 | 1 | public function refresh($jwt, $lifetime = self::DEFAULT_LIFETIME) |
|
62 | |||
63 | /** |
||
64 | * Verifies that certain JWT is valid |
||
65 | * |
||
66 | * @param string $jwt |
||
67 | * @return bool |
||
68 | */ |
||
69 | 2 | public function verify($jwt) |
|
79 | |||
80 | /** |
||
81 | * Decodes certain token and returns the payload |
||
82 | * |
||
83 | * @param string $jwt |
||
84 | * @return array |
||
85 | * @throws AuthenticationException If the token has expired |
||
86 | */ |
||
87 | 3 | public function getPayload($jwt) |
|
95 | |||
96 | /** |
||
97 | * @param array $data |
||
98 | * @return string |
||
99 | */ |
||
100 | 2 | protected function encode(array $data) |
|
104 | |||
105 | /** |
||
106 | * @param $jwt |
||
107 | * @return array |
||
108 | */ |
||
109 | 5 | protected function decode($jwt) |
|
113 | } |
||
114 |