-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
359 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,26 @@ | ||
parameters: | ||
paths: | ||
- src | ||
excludePaths: | ||
analyse: | ||
- src/Plugin/JWT/* | ||
|
||
ignoreErrors: | ||
- | ||
- # Too variants of parameters signature between PHP versions | ||
message: '#Parameter \#3 \$options of function setcookie expects .+#' | ||
reportUnmatched: false | ||
path: src/Enabler.php | ||
count: 2 | ||
|
||
- # Weird bug by PhpStan - the `path` fiealt is still nullable | ||
message: '#Offset ''path'' on array.+ on left side of \?\? always exists and is not nullable\.#' | ||
path: src/Plugin/SignedUrl.php | ||
count: 1 | ||
|
||
- | ||
message: '#.+ has unknown class (OpenSSLAsymmetricKey|OpenSSLCertificate) as its type.#' # PHP 7 compatibility | ||
reportUnmatched: false | ||
|
||
- | ||
message: '#.+ has invalid type (OpenSSLAsymmetricKey|OpenSSLCertificate).#' # PHP 7 compatibility | ||
reportUnmatched: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/** | ||
* The MIT License (MIT) | ||
* Copyright (c) 2023 Redbit s.r.o., Jakub Bouček | ||
* | ||
* @noinspection PhpUndefinedClassInspection OpenSSL only optional dependency | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Redbitcz\DebugMode\Plugin\JWT; | ||
|
||
use Firebase\JWT\JWT; | ||
use ReflectionMethod; | ||
use stdClass; | ||
|
||
class JWTFirebaseV5 implements JWTImpl | ||
{ | ||
/** @var OpenSSLAsymmetricKey|OpenSSLCertificate|resource|string */ | ||
protected $key; | ||
protected string $algorithm; | ||
|
||
/** | ||
* @param OpenSSLAsymmetricKey|OpenSSLCertificate|resource|string $key | ||
* @param string $algorithm | ||
*/ | ||
public function __construct($key, string $algorithm = 'HS256') | ||
{ | ||
$this->key = $key; | ||
$this->algorithm = $algorithm; | ||
} | ||
|
||
public static function isAvailable(): bool | ||
{ | ||
if (class_exists(JWT::class) === false) { | ||
return false; | ||
} | ||
|
||
$params = (new ReflectionMethod(JWT::class, 'decode'))->getParameters(); | ||
|
||
// JWT v5 has second parameter named `$key` | ||
if ($params[1]->getName() === 'key') { | ||
return true; | ||
} | ||
|
||
// JWT v5.5.0 already second parameter named `$keyOrKeyArray`, detect by third param (future compatibility) | ||
return $params[1]->getName() === 'keyOrKeyArray' | ||
&& isset($params[2]) | ||
&& $params[2]->getName() === 'allowed_algs'; | ||
} | ||
|
||
public function decode(string $jwt): stdClass | ||
{ | ||
return JWT::decode($jwt, $this->key, [$this->algorithm]); | ||
} | ||
|
||
public function encode(array $payload): string | ||
{ | ||
return JWT::encode($payload, $this->key, $this->algorithm); | ||
} | ||
|
||
public function setTimestamp(?int $timestamp): void | ||
{ | ||
JWT::$timestamp = $timestamp; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* The MIT License (MIT) | ||
* Copyright (c) 2023 Redbit s.r.o., Jakub Bouček | ||
* | ||
* @noinspection PhpUndefinedClassInspection Library support JWT 5.0 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Redbitcz\DebugMode\Plugin\JWT; | ||
|
||
use Firebase\JWT\JWT; | ||
use Firebase\JWT\Key; | ||
use ReflectionMethod; | ||
use stdClass; | ||
|
||
class JWTFirebaseV6 extends JWTFirebaseV5 | ||
{ | ||
public static function isAvailable(): bool | ||
{ | ||
if (class_exists(JWT::class) === false) { | ||
return false; | ||
} | ||
|
||
$params = (new ReflectionMethod(JWT::class, 'decode'))->getParameters(); | ||
|
||
// JWT v6 has always second parameter named `$keyOrKeyArray` | ||
if ($params[1]->getName() !== 'keyOrKeyArray') { | ||
return false; | ||
} | ||
|
||
// JWT v5.5.0 already second parameter named `$keyOrKeyArray`, detect by third param (future compatibility) | ||
return isset($params[2]) === false || $params[2]->getName() !== 'allowed_algs'; | ||
} | ||
|
||
public function decode(string $jwt): stdClass | ||
{ | ||
return JWT::decode($jwt, new Key($this->key, $this->algorithm)); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
/** | ||
* The MIT License (MIT) | ||
* Copyright (c) 2023 Redbit s.r.o., Jakub Bouček | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Redbitcz\DebugMode\Plugin\JWT; | ||
|
||
use stdClass; | ||
|
||
interface JWTImpl | ||
{ | ||
public static function isAvailable(): bool; | ||
|
||
public function decode(string $jwt): stdClass; | ||
|
||
public function encode(array $payload): string; | ||
|
||
public function setTimestamp(?int $timestamp): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.