Skip to content

Commit

Permalink
Fix ability to set extra standard claims in the input payload (bis)
Browse files Browse the repository at this point in the history
  • Loading branch information
chalasr committed Nov 30, 2020
1 parent 682f441 commit 61a22d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Services/JWSProvider/LcobucciJWSProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand Down
15 changes: 15 additions & 0 deletions Tests/Functional/SubscribedTokenAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 61a22d8

Please sign in to comment.