| @@ 194-208 (lines=15) @@ | ||
| 191 | * @throws Exception If the key is not set in config or not a string. |
|
| 192 | * @return string |
|
| 193 | */ |
|
| 194 | private function loadPrivateKey(JWTConfig $config) |
|
| 195 | { |
|
| 196 | if (!isset($config['privateKey'])) { |
|
| 197 | throw new Exception( |
|
| 198 | 'JWT authentication configuration requires a private key.' |
|
| 199 | ); |
|
| 200 | } |
|
| 201 | $keyFile = $config['privateKey']; |
|
| 202 | if (!file_exists($keyFile)) { |
|
| 203 | throw new Exception( |
|
| 204 | sprintf('JWT private key file "%s" does not exist.', $keyFile) |
|
| 205 | ); |
|
| 206 | } |
|
| 207 | return file_get_contents($keyFile); |
|
| 208 | } |
|
| 209 | ||
| 210 | /** |
|
| 211 | * @param JWTConfig $config The JWT / auth configuration. |
|
| @@ 215-230 (lines=16) @@ | ||
| 212 | * @throws Exception If the key is not set in config or not a string. |
|
| 213 | * @return string |
|
| 214 | */ |
|
| 215 | private function loadPublicKey(JWTConfig $config) |
|
| 216 | { |
|
| 217 | if (!isset($config['publicKey'])) { |
|
| 218 | throw new Exception( |
|
| 219 | 'JWT authentication configuration requires a public key.' |
|
| 220 | ); |
|
| 221 | } |
|
| 222 | ||
| 223 | $keyFile = $config['publicKey']; |
|
| 224 | if (!file_exists($keyFile)) { |
|
| 225 | throw new Exception( |
|
| 226 | sprintf('JWT public key file "%s" does not exist.', $keyFile) |
|
| 227 | ); |
|
| 228 | } |
|
| 229 | return file_get_contents($keyFile); |
|
| 230 | } |
|
| 231 | } |
|
| 232 | ||