From a0f60be513d72dcc3f345ee5675e9f70bbbe442b Mon Sep 17 00:00:00 2001 From: Mati Kochen Date: Sun, 10 Mar 2024 19:04:03 +0100 Subject: [PATCH] feat: remove lcobucci/jwt deprecations --- phpunit.xml.dist | 3 -- psalm.xml.dist | 10 ---- src/Security/Jwt/Builder/Builder.php | 1 - .../Configuration/ConfigurationFactory.php | 16 +++--- .../Jwt/Decoder/AssociativeDecoder.php | 53 ------------------- 5 files changed, 6 insertions(+), 77 deletions(-) delete mode 100644 src/Security/Jwt/Decoder/AssociativeDecoder.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 40e15bf8..412ad809 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,9 +5,6 @@ src - - src/Security/Jwt/Decoder/AssociativeDecoder.php - diff --git a/psalm.xml.dist b/psalm.xml.dist index aa9b8cb1..2222bc17 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -51,16 +51,6 @@ - - - - - - - - - - diff --git a/src/Security/Jwt/Builder/Builder.php b/src/Security/Jwt/Builder/Builder.php index 140bcb90..39974608 100644 --- a/src/Security/Jwt/Builder/Builder.php +++ b/src/Security/Jwt/Builder/Builder.php @@ -78,7 +78,6 @@ public function build(array $headers, array $claims, KeyInterface $key): TokenIn MessagePayloadInterface::CLAIM_EXP => $now->addSeconds($this->messageTtl)->toDateTimeImmutable(), ] ); - foreach ($claims as $claimName => $claimValue) { switch ($claimName) { case MessagePayloadInterface::CLAIM_JTI: diff --git a/src/Security/Jwt/Configuration/ConfigurationFactory.php b/src/Security/Jwt/Configuration/ConfigurationFactory.php index 1e936cfb..4a8a6b68 100644 --- a/src/Security/Jwt/Configuration/ConfigurationFactory.php +++ b/src/Security/Jwt/Configuration/ConfigurationFactory.php @@ -24,12 +24,12 @@ use Lcobucci\Clock\SystemClock; use Lcobucci\JWT\Configuration; +use Lcobucci\JWT\Encoding\JoseEncoder; use Lcobucci\JWT\Signer\Key; use Lcobucci\JWT\Signer\Key\InMemory; +use Lcobucci\JWT\Validation\Constraint\LooseValidAt; use Lcobucci\JWT\Validation\Constraint\SignedWith; -use Lcobucci\JWT\Validation\Constraint\ValidAt; use OAT\Library\Lti1p3Core\Security\Jwt\Converter\KeyConverter; -use OAT\Library\Lti1p3Core\Security\Jwt\Decoder\AssociativeDecoder; use OAT\Library\Lti1p3Core\Security\Jwt\Signer\SignerFactory; use OAT\Library\Lti1p3Core\Security\Key\KeyInterface; @@ -51,18 +51,16 @@ public function create(?KeyInterface $signingKey = null, ?KeyInterface $verifica { $algorithm = $this->findAlgorithm($signingKey, $verificationKey); - $decoder = class_exists('Lcobucci\JWT\Parsing\Decoder') ? new AssociativeDecoder() : null; - $configuration = Configuration::forAsymmetricSigner( $this->factory->create($algorithm), $this->convertKey($signingKey), $this->convertKey($verificationKey), - null, - $decoder + new JoseEncoder(), + new JoseEncoder(), ); $configuration->setValidationConstraints( - new ValidAt(SystemClock::fromUTC()), + new LooseValidAt(SystemClock::fromUTC()), new SignedWith($configuration->signer(), $configuration->verificationKey()) ); @@ -85,9 +83,7 @@ private function findAlgorithm(?KeyInterface $signingKey = null, ?KeyInterface $ private function convertKey(?KeyInterface $key = null): Key { if (null === $key) { - return method_exists(InMemory::class, 'empty') - ? InMemory::empty() - : InMemory::plainText(''); + return InMemory::plainText('empty', 'empty'); } return $this->converter->convert($key); diff --git a/src/Security/Jwt/Decoder/AssociativeDecoder.php b/src/Security/Jwt/Decoder/AssociativeDecoder.php deleted file mode 100644 index 833105de..00000000 --- a/src/Security/Jwt/Decoder/AssociativeDecoder.php +++ /dev/null @@ -1,53 +0,0 @@ -