From 1e560c09f59955a68c2c2dd3a00ed95d6974dbf5 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Sat, 25 Nov 2023 05:56:10 +0100 Subject: [PATCH] Fix deprecations on 6.4/7.0 --- .github/workflows/ci.yml | 2 +- Exception/ExpiredTokenException.php | 2 +- Exception/InvalidPayloadException.php | 2 +- Exception/InvalidTokenException.php | 2 +- Exception/MissingTokenException.php | 2 +- Exception/UserNotFoundException.php | 2 +- Security/Http/EntryPoint/JWTEntryPoint.php | 3 ++- Security/User/JWTUser.php | 2 +- Services/JWSProvider/DefaultJWSProvider.php | 1 + Tests/Functional/app/config/security_in_memory.yml | 1 - Tests/Functional/app/config/security_in_memory_legacy.yml | 1 - Tests/Functional/app/config/security_lexik_jwt.yml | 1 - Tests/Functional/app/config/security_lexik_jwt_legacy.yml | 1 - Tests/Stubs/User.php | 2 +- 14 files changed, 11 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab5702ab..fe9667fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,7 +79,7 @@ jobs: run: "composer remove --dev --no-update symfony/security-guard" - name: "Install api-platform/core" - if: "matrix.symfony == '6.1.*' || matrix.symfony == '6.2.*' || matrix.symfony == '6.3.*' || matrix.symfony == '6.4.*@dev' || matrix.symfony == '7.0.*@dev'" + if: "matrix.symfony == '6.1.*' || matrix.symfony == '6.2.*' || matrix.symfony == '6.3.*' || matrix.symfony == '6.4.*@dev'" run: "composer require --dev --no-update api-platform/core:^3.0" - name: "Install dependencies" diff --git a/Exception/ExpiredTokenException.php b/Exception/ExpiredTokenException.php index ec1441c9..55e60c8c 100644 --- a/Exception/ExpiredTokenException.php +++ b/Exception/ExpiredTokenException.php @@ -17,7 +17,7 @@ class ExpiredTokenException extends AuthenticationException * * @return string */ - public function getMessageKey() + public function getMessageKey(): string { return 'Expired JWT Token'; } diff --git a/Exception/InvalidPayloadException.php b/Exception/InvalidPayloadException.php index 3be61534..d7fdae81 100644 --- a/Exception/InvalidPayloadException.php +++ b/Exception/InvalidPayloadException.php @@ -26,7 +26,7 @@ public function __construct(string $invalidKey) * * @return string */ - public function getMessageKey() + public function getMessageKey(): string { return sprintf('Unable to find key "%s" in the token payload.', $this->invalidKey); } diff --git a/Exception/InvalidTokenException.php b/Exception/InvalidTokenException.php index 76e474c2..b09fe9df 100644 --- a/Exception/InvalidTokenException.php +++ b/Exception/InvalidTokenException.php @@ -16,7 +16,7 @@ class InvalidTokenException extends AuthenticationException * * @return string */ - public function getMessageKey() + public function getMessageKey(): string { return 'Invalid JWT Token'; } diff --git a/Exception/MissingTokenException.php b/Exception/MissingTokenException.php index e7cee1fc..366e185c 100644 --- a/Exception/MissingTokenException.php +++ b/Exception/MissingTokenException.php @@ -16,7 +16,7 @@ class MissingTokenException extends AuthenticationException * * @return string */ - public function getMessageKey() + public function getMessageKey(): string { return 'JWT Token not found'; } diff --git a/Exception/UserNotFoundException.php b/Exception/UserNotFoundException.php index 62aaed92..fc2e3d46 100644 --- a/Exception/UserNotFoundException.php +++ b/Exception/UserNotFoundException.php @@ -23,7 +23,7 @@ public function __construct(string $userIdentityField, string $identity) /** * {@inheritdoc} */ - public function getMessageKey() + public function getMessageKey(): string { return sprintf('Unable to load an user with property "%s" = "%s". If the user identity has changed, you must renew the token. Otherwise, verify that the "lexik_jwt_authentication.user_identity_field" config option is correctly set.', $this->userIdentityField, $this->identity); } diff --git a/Security/Http/EntryPoint/JWTEntryPoint.php b/Security/Http/EntryPoint/JWTEntryPoint.php index 6ef9a8fe..4be5fc59 100644 --- a/Security/Http/EntryPoint/JWTEntryPoint.php +++ b/Security/Http/EntryPoint/JWTEntryPoint.php @@ -5,6 +5,7 @@ use Lexik\Bundle\JWTAuthenticationBundle\Response\JWTAuthenticationFailureResponse; use Lexik\Bundle\JWTAuthenticationBundle\Security\Authenticator\JWTAuthenticator; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; @@ -26,7 +27,7 @@ public function __construct() /** * {@inheritdoc} */ - public function start(Request $request, AuthenticationException $authException = null) + public function start(Request $request, AuthenticationException $authException = null): Response { $response = new JWTAuthenticationFailureResponse(); diff --git a/Security/User/JWTUser.php b/Security/User/JWTUser.php index a7b8a7aa..223e760e 100644 --- a/Security/User/JWTUser.php +++ b/Security/User/JWTUser.php @@ -72,7 +72,7 @@ public function getSalt(): ?string /** * {@inheritdoc} */ - public function eraseCredentials() + public function eraseCredentials(): void { } } diff --git a/Services/JWSProvider/DefaultJWSProvider.php b/Services/JWSProvider/DefaultJWSProvider.php index c56ebbcb..9c50f5ae 100644 --- a/Services/JWSProvider/DefaultJWSProvider.php +++ b/Services/JWSProvider/DefaultJWSProvider.php @@ -83,6 +83,7 @@ public function __construct(KeyLoaderInterface $keyLoader, $cryptoEngine, $signa public function create(array $payload, array $header = []) { $header['alg'] = $this->signatureAlgorithm; + $jws = new JWS($header, $this->cryptoEngine); $claims = ['iat' => time()]; diff --git a/Tests/Functional/app/config/security_in_memory.yml b/Tests/Functional/app/config/security_in_memory.yml index eeff5932..a248da8a 100644 --- a/Tests/Functional/app/config/security_in_memory.yml +++ b/Tests/Functional/app/config/security_in_memory.yml @@ -12,7 +12,6 @@ security: provider: in_memory json_login: check_path: login_check - require_previous_session: false success_handler: lexik_jwt_authentication.handler.authentication_success failure_handler: lexik_jwt_authentication.handler.authentication_failure diff --git a/Tests/Functional/app/config/security_in_memory_legacy.yml b/Tests/Functional/app/config/security_in_memory_legacy.yml index 90ae1c0c..49db211d 100644 --- a/Tests/Functional/app/config/security_in_memory_legacy.yml +++ b/Tests/Functional/app/config/security_in_memory_legacy.yml @@ -13,7 +13,6 @@ security: provider: in_memory form_login: check_path: /login_check - require_previous_session: false success_handler: lexik_jwt_authentication.handler.authentication_success failure_handler: lexik_jwt_authentication.handler.authentication_failure diff --git a/Tests/Functional/app/config/security_lexik_jwt.yml b/Tests/Functional/app/config/security_lexik_jwt.yml index c683ee73..34cbd74a 100644 --- a/Tests/Functional/app/config/security_lexik_jwt.yml +++ b/Tests/Functional/app/config/security_lexik_jwt.yml @@ -12,7 +12,6 @@ security: provider: in_memory json_login: check_path: login_check - require_previous_session: false success_handler: lexik_jwt_authentication.handler.authentication_success failure_handler: lexik_jwt_authentication.handler.authentication_failure diff --git a/Tests/Functional/app/config/security_lexik_jwt_legacy.yml b/Tests/Functional/app/config/security_lexik_jwt_legacy.yml index fd63c50c..88c093fc 100644 --- a/Tests/Functional/app/config/security_lexik_jwt_legacy.yml +++ b/Tests/Functional/app/config/security_lexik_jwt_legacy.yml @@ -13,7 +13,6 @@ security: provider: in_memory form_login: check_path: /login_check - require_previous_session: false success_handler: lexik_jwt_authentication.handler.authentication_success failure_handler: lexik_jwt_authentication.handler.authentication_failure diff --git a/Tests/Stubs/User.php b/Tests/Stubs/User.php index 5441fad1..c85ab401 100644 --- a/Tests/Stubs/User.php +++ b/Tests/Stubs/User.php @@ -79,7 +79,7 @@ public function getUserIdentifier(): string /** * {@inheritdoc} */ - public function eraseCredentials() + public function eraseCredentials(): void { }