-
-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Invalidate a JWT token - Adding the jti claim by the JWTManager class…
… instead of doing it via a listener
- Loading branch information
Showing
16 changed files
with
226 additions
and
29 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
DependencyInjection/Compiler/CollectPayloadEnrichmentsPass.php
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,22 @@ | ||
<?php | ||
|
||
namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class CollectPayloadEnrichmentsPass implements CompilerPassInterface | ||
{ | ||
use PriorityTaggedServiceTrait; | ||
|
||
public function process(ContainerBuilder $container): void | ||
{ | ||
if (!$container->hasDefinition('lexik_jwt_authentication.payload_enrichment')) { | ||
return; | ||
} | ||
|
||
$container->getDefinition('lexik_jwt_authentication.payload_enrichment') | ||
->replaceArgument(0, $this->findAndSortTaggedServices('lexik_jwt_authentication.payload_enrichment', $container)); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Lexik\Bundle\JWTAuthenticationBundle\Services\PayloadEnrichment; | ||
|
||
use Lexik\Bundle\JWTAuthenticationBundle\Services\PayloadEnrichmentInterface; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
class ChainEnrichment implements PayloadEnrichmentInterface | ||
{ | ||
private $enrichments; | ||
|
||
/** | ||
* @param PayloadEnrichmentInterface[] $enrichments | ||
*/ | ||
public function __construct(array $enrichments) | ||
{ | ||
$this->enrichments = $enrichments; | ||
} | ||
|
||
public function enrich(UserInterface $user, array &$payload): void | ||
{ | ||
foreach ($this->enrichments as $enrichment) { | ||
$enrichment->enrich($user, $payload); | ||
} | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Lexik\Bundle\JWTAuthenticationBundle\Services\PayloadEnrichment; | ||
|
||
use Lexik\Bundle\JWTAuthenticationBundle\Services\PayloadEnrichmentInterface; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
class NullEnrichment implements PayloadEnrichmentInterface | ||
{ | ||
public function enrich(UserInterface $user, array &$payload): 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Lexik\Bundle\JWTAuthenticationBundle\Services\PayloadEnrichment; | ||
|
||
use Lexik\Bundle\JWTAuthenticationBundle\Services\PayloadEnrichmentInterface; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
class RandomJtiEnrichment implements PayloadEnrichmentInterface | ||
{ | ||
public function enrich(UserInterface $user, array &$payload): void | ||
{ | ||
$payload['jti'] = bin2hex(random_bytes(16)); | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Lexik\Bundle\JWTAuthenticationBundle\Services; | ||
|
||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
interface PayloadEnrichmentInterface | ||
{ | ||
public function enrich(UserInterface $user, array &$payload): 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Lexik\Bundle\JWTAuthenticationBundle\Services\PayloadEnrichment; | ||
|
||
use Lexik\Bundle\JWTAuthenticationBundle\Services\PayloadEnrichmentInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
class ChainEnrichmentTest extends TestCase | ||
{ | ||
public function testEnrich(): void | ||
{ | ||
$payload = ['foo' => 'bar']; | ||
|
||
$enrichmentFoo = new class() implements PayloadEnrichmentInterface { | ||
public function enrich(UserInterface $user, array &$payload): void | ||
{ | ||
$payload['foo'] = 'baz'; | ||
} | ||
}; | ||
|
||
$enrichmentBar = new class() implements PayloadEnrichmentInterface { | ||
public function enrich(UserInterface $user, array &$payload): void | ||
{ | ||
$payload['bar'] = 'qux'; | ||
} | ||
}; | ||
|
||
$chainEnrichment = new ChainEnrichment([$enrichmentFoo, $enrichmentBar]); | ||
$chainEnrichment->enrich($this->createMock(UserInterface::class), $payload); | ||
|
||
$this->assertEquals(['foo' => 'baz', 'bar' => 'qux'], $payload); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Lexik\Bundle\JWTAuthenticationBundle\Services\PayloadEnrichment; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
class NullEnrichmentTest extends TestCase | ||
{ | ||
public function testEnrich(): void | ||
{ | ||
$payload = ['foo' => 'bar']; | ||
$enrichment = new NullEnrichment(); | ||
$enrichment->enrich($this->createMock(UserInterface::class), $payload); | ||
|
||
$this->assertEquals(['foo' => 'bar'], $payload); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace Lexik\Bundle\JWTAuthenticationBundle\Services\PayloadEnrichment; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
class RandomJtiEnrichmentTest extends TestCase | ||
{ | ||
public function testEnrich(): void | ||
{ | ||
$payload = ['foo' => 'bar']; | ||
$enrichment = new RandomJtiEnrichment(); | ||
$enrichment->enrich($this->createMock(UserInterface::class), $payload); | ||
|
||
$this->assertArrayHasKey('jti', $payload); | ||
$this->assertIsString($payload['jti']); | ||
$this->assertArrayHasKey('foo', $payload); | ||
} | ||
} |
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