Skip to content

Commit 66af300

Browse files
committed
More cleanup
1 parent bbea924 commit 66af300

15 files changed

+26
-99
lines changed

DependencyInjection/Security/Factory/JWTUserFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
final class JWTUserFactory implements UserProviderFactoryInterface
2020
{
21-
public function create(ContainerBuilder $container, $id, $config): void
21+
public function create(ContainerBuilder $container, string $id, array $config): void
2222
{
2323
$container->setDefinition($id, new ChildDefinition('lexik_jwt_authentication.security.jwt_user_provider'))
2424
->replaceArgument(0, $config['class']);
@@ -37,7 +37,7 @@ public function addConfiguration(NodeDefinition $node): void
3737
->cannotBeEmpty()
3838
->defaultValue(JWTUser::class)
3939
->validate()
40-
->ifTrue(fn ($class) => !(new \ReflectionClass($class))->implementsInterface(JWTUserInterface::class))
40+
->ifTrue(fn ($class) => !is_subclass_of($class, JWTUserInterface::class))
4141
->thenInvalid('The %s class must implement ' . JWTUserInterface::class . ' for using the "lexik_jwt" user provider.')
4242
->end()
4343
->end()

Event/AuthenticationFailureEvent.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
class AuthenticationFailureEvent extends Event
1717
{
1818
protected AuthenticationException $exception;
19-
2019
protected ?Response $response;
21-
2220
protected ?Request $request;
2321

2422
public function __construct(?AuthenticationException $exception, ?Response $response, ?Request $request = null)

Event/BeforeJWEComputationEvent.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,17 @@
1010
*/
1111
class BeforeJWEComputationEvent
1212
{
13-
/**
14-
* @var array<string, mixed>
15-
*/
1613
private $header;
1714

15+
/**
16+
* @param array<string, mixed> $header
17+
*/
1818
public function __construct(array $header)
1919
{
2020
$this->header = $header;
2121
}
2222

23-
/**
24-
* @param mixed $value
25-
*/
26-
public function setHeader(string $key, $value): self
23+
public function setHeader(string $key, mixed $value): self
2724
{
2825
$this->header[$key] = $value;
2926

Event/JWTDecodedEvent.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
class JWTDecodedEvent extends Event
1313
{
1414
protected array $payload;
15-
1615
protected bool $isValid;
1716

1817
public function __construct(array $payload)

EventListener/RejectBlockedTokenListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public function __construct(BlockedTokenManagerInterface $blockedTokenManager)
1717
}
1818

1919
/**
20-
* @throws InvalidTokenException if the JWT is blocked
20+
* @throws InvalidTokenException If the JWT is blocked
2121
*/
2222
public function __invoke(JWTAuthenticatedEvent $event): void
2323
{
2424
try {
2525
if ($this->blockedTokenManager->has($event->getPayload())) {
2626
throw new InvalidTokenException('JWT blocked');
2727
}
28-
} catch (MissingClaimException $e) {
28+
} catch (MissingClaimException) {
2929
// Do nothing if the required claims do not exist on the payload (older JWTs won't have the "jti" claim the manager requires)
3030
}
3131
}

Helper/JWTSplitter.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
class JWTSplitter
1313
{
1414
private string $header;
15-
1615
private string $payload;
17-
1816
private string $signature;
1917

2018
/**

OpenApi/OpenApiFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
class OpenApiFactory implements OpenApiFactoryInterface
2121
{
2222
private OpenApiFactoryInterface $decorated;
23-
2423
private string $checkPath;
2524
private string $usernamePath;
2625
private string $passwordPath;

Response/JWTAuthenticationFailureResponse.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Lexik\Bundle\JWTAuthenticationBundle\Response;
44

5+
use Symfony\Component\HttpFoundation\JsonResponse;
56
use Symfony\Component\HttpFoundation\Response;
67

78
/**
@@ -11,7 +12,7 @@
1112
*
1213
* @author Robin Chalas <[email protected]>
1314
*/
14-
final class JWTAuthenticationFailureResponse extends JWTCompatAuthenticationFailureResponse
15+
final class JWTAuthenticationFailureResponse extends JsonResponse
1516
{
1617
private string $message;
1718

@@ -22,6 +23,14 @@ public function __construct(string $message = 'Bad credentials', int $statusCode
2223
parent::__construct(null, $statusCode, ['WWW-Authenticate' => 'Bearer']);
2324
}
2425

26+
/**
27+
* Sets the response data with the statusCode & message included.
28+
*/
29+
public function setData(mixed $data = []): static
30+
{
31+
return parent::setData((array)$data + ["code" => $this->statusCode, "message" => $this->getMessage()]);
32+
}
33+
2534
/**
2635
* Sets the failure message.
2736
*/

Response/JWTCompatAuthenticationFailureResponse.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

Services/JWSProvider/JWSProviderInterface.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,11 @@ interface JWSProviderInterface
1414
{
1515
/**
1616
* Creates a new JWS signature from a given payload.
17-
*
18-
* @return CreatedJWS
1917
*/
20-
public function create(array $payload, array $header = []);
18+
public function create(array $payload, array $header = []): CreatedJWS;
2119

2220
/**
2321
* Loads an existing JWS signature from a given JWT token.
24-
*
25-
* @param string $token
26-
*
27-
* @return LoadedJWS
2822
*/
29-
public function load($token);
23+
public function load(string $token): LoadedJWS;
3024
}

0 commit comments

Comments
 (0)