| @@ 109-126 (lines=18) @@ | ||
| 106 | * |
|
| 107 | * @return array |
|
| 108 | */ |
|
| 109 | public static function header($token) |
|
| 110 | { |
|
| 111 | if (null === $token || trim($token) === '') { |
|
| 112 | throw new JoseJwtException('Incoming token expected to be in compact serialization form, but is empty'); |
|
| 113 | } |
|
| 114 | ||
| 115 | $parts = explode('.', $token); |
|
| 116 | if (count($parts) != 3 && count($parts) != 5) { |
|
| 117 | throw new JoseJwtException('Invalid JWT'); |
|
| 118 | } |
|
| 119 | ||
| 120 | $header = json_decode(UrlSafeB64Encoder::decode($parts[0]), true); |
|
| 121 | if (null == $header) { |
|
| 122 | throw new JoseJwtException('Invalid header'); |
|
| 123 | } |
|
| 124 | ||
| 125 | return $header; |
|
| 126 | } |
|
| 127 | ||
| 128 | /** |
|
| 129 | * @param $token |
|
| @@ 133-150 (lines=18) @@ | ||
| 130 | * |
|
| 131 | * @return array |
|
| 132 | */ |
|
| 133 | public static function payload($token) |
|
| 134 | { |
|
| 135 | if (null === $token || trim($token) === '') { |
|
| 136 | throw new JoseJwtException('Incoming token expected to be in compact serialization form, but is empty'); |
|
| 137 | } |
|
| 138 | ||
| 139 | $parts = explode('.', $token); |
|
| 140 | if (count($parts) != 3) { |
|
| 141 | throw new JoseJwtException('Invalid JWT'); |
|
| 142 | } |
|
| 143 | ||
| 144 | $payload = json_decode(UrlSafeB64Encoder::decode($parts[1]), true); |
|
| 145 | if (null == $payload) { |
|
| 146 | throw new JoseJwtException('Invalid payload'); |
|
| 147 | } |
|
| 148 | ||
| 149 | return $payload; |
|
| 150 | } |
|
| 151 | } |
|
| 152 | ||