diff --git a/Services/JWSProvider/LcobucciJWSProvider.php b/Services/JWSProvider/LcobucciJWSProvider.php index 3e050666..cb9d1b25 100644 --- a/Services/JWSProvider/LcobucciJWSProvider.php +++ b/Services/JWSProvider/LcobucciJWSProvider.php @@ -126,7 +126,7 @@ public function create(array $payload, array $header = []) unset($payload['sub']); } - if (class_exists(RegisteredClaims::class)) { + if (interface_exists(RegisteredClaims::class)) { $this->addStandardClaims($jws, $payload); } @@ -272,7 +272,7 @@ private function addStandardClaims(Builder $builder, array &$payload) ]; foreach ($payload as $claim => $value) { - if (!\in_array($claim, $mutatorMap, true)) { + if (!isset($mutatorMap[$claim])) { continue; } diff --git a/Tests/Functional/SubscribedTokenAuthenticationTest.php b/Tests/Functional/SubscribedTokenAuthenticationTest.php index 1b147b3f..d5a3a50c 100644 --- a/Tests/Functional/SubscribedTokenAuthenticationTest.php +++ b/Tests/Functional/SubscribedTokenAuthenticationTest.php @@ -2,6 +2,7 @@ namespace Lexik\Bundle\JWTAuthenticationBundle\Tests\Functional; +use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent; use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTDecodedEvent; use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTExpiredEvent; use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTInvalidEvent; @@ -73,6 +74,20 @@ public function testAccessSecuredRouteWithInvalidJWTDecodedEvent() self::$subscriber->unsetListener(Events::JWT_DECODED); } + public function testAccessSecuredRouteWithExtraStandardClaim() + { + self::$subscriber->setListener(Events::JWT_CREATED, function (JWTCreatedEvent $e) { + $e->setData(['jti' => 'some-unique-id'] + $e->getData()); + }); + + static::$client = static::createAuthenticatedClient(); + static::accessSecuredRoute(); + + $this->assertSuccessful(static::$client->getResponse()); + + self::$subscriber->unsetListener(Events::JWT_CREATED); + } + /** * @group time-sensitive */