| Conditions | 6 |
| Paths | 5 |
| Total Lines | 30 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 29 | public static function decode(string $jwt, string $serverKey): Payload |
||
| 30 | { |
||
| 31 | try { |
||
| 32 | $payload = JWT::decode( |
||
| 33 | $jwt, // jwt The JWT |
||
| 34 | new Key( |
||
| 35 | $serverKey, |
||
| 36 | self::ALGORITHM_HS256, |
||
| 37 | ), |
||
| 38 | ); |
||
| 39 | } catch (\Throwable $e) { |
||
| 40 | throw new JwtException($e->getMessage(), $e->getCode(), $e); |
||
| 41 | } |
||
| 42 | |||
| 43 | if (!\property_exists($payload, 'sub') || !\property_exists($payload, 'clientKey')) { |
||
| 44 | throw new JwtException('Token is missing required data.'); |
||
| 45 | } |
||
| 46 | |||
| 47 | $sub = (string) $payload->sub; |
||
| 48 | $clientKey = (string) $payload->clientKey; |
||
| 49 | |||
| 50 | if (!$sub) { |
||
| 51 | throw new JwtException('Invalid token part: "sub".'); |
||
| 52 | } |
||
| 53 | |||
| 54 | if (!$clientKey) { |
||
| 55 | throw new JwtException('Invalid token part: "clientKey".'); |
||
| 56 | } |
||
| 57 | |||
| 58 | return new Payload($sub, $clientKey); |
||
| 59 | } |
||
| 61 |