Skip to content

Commit

Permalink
bug #804 Fix ability to set extra standard claims in the input payloa…
Browse files Browse the repository at this point in the history
…d (bis) (chalasr)

This PR was merged into the 2.x-dev branch.

Discussion
----------

Fix ability to set extra standard claims in the input payload (bis)

Fixes #803

Commits
-------

61a22d8 Fix ability to set extra standard claims in the input payload (bis)
  • Loading branch information
chalasr committed Nov 30, 2020
2 parents 97e0c05 + 61a22d8 commit 395b361
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 395b361

Please sign in to comment.