Skip to content

Commit

Permalink
Remove support for lcobucci/jwt <3.4 & symfony/* <4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
chalasr committed Dec 20, 2020
1 parent 9c29534 commit f9e92d7
Show file tree
Hide file tree
Showing 36 changed files with 142 additions and 519 deletions.
44 changes: 5 additions & 39 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
push:

jobs:
php-56:
name: PHP 5.6 / Symfony 3.4
php-71:
name: PHP 7.1 / Symfony 4.4
runs-on: ubuntu-latest
steps:
- name: "Checkout"
Expand All @@ -17,48 +17,14 @@ jobs:
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "5.6"
php-version: "7.1"

- name: "Cache composer packages"
uses: "actions/cache@v2"
with:
path: "~/.composer/cache"
key: "php-5.6-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: "php-5.6-composer-locked-"

- name: "Install Symfony 3.4"
run: "composer require symfony/symfony:3.4.* --no-update"

- name: "Install Symfony PHPUnit Bridge 3.4"
run: "composer require symfony/phpunit-bridge:3.4.* --no-update"

- name: "Install dependencies with composer"
run: "composer update --no-interaction --prefer-dist --prefer-stable"

- name: "Run PHPUnit Tests"
env:
SYMFONY_PHPUNIT_VERSION: 5.7
run: "composer test"
php-72:
name: PHP 7.2 / Symfony 4.4
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
with:
fetch-depth: 2

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "7.2"

- name: "Cache composer packages"
uses: "actions/cache@v2"
with:
path: "~/.composer/cache"
key: "php-7.2-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: "php-7.2-composer-locked-"
key: "php-7.1-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: "php-7.1-composer-locked-"

- name: "Install Symfony 4.4"
run: "composer require symfony/symfony:4.4.* --no-update"
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('lexik_jwt_authentication');
$rootNode = \method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('lexik_jwt_authentication');

$rootNode
$treeBuilder
->getRootNode()
->addDefaultsIfNotSet()
->children()
->scalarNode('private_key_path')
Expand Down
1 change: 1 addition & 0 deletions Event/AuthenticationFailureEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Contracts\EventDispatcher\Event;

/**
* AuthenticationFailureEvent.
Expand Down
1 change: 1 addition & 0 deletions Event/AuthenticationSuccessEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Contracts\EventDispatcher\Event;

/**
* AuthenticationSuccessEvent.
Expand Down
18 changes: 0 additions & 18 deletions Event/Event.php

This file was deleted.

1 change: 1 addition & 0 deletions Event/JWTAuthenticatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;

use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Contracts\EventDispatcher\Event;

/**
* JWTAuthenticatedEvent.
Expand Down
1 change: 1 addition & 0 deletions Event/JWTCreatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;

use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Contracts\EventDispatcher\Event;

/**
* JWTCreatedEvent.
Expand Down
4 changes: 3 additions & 1 deletion Event/JWTDecodedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Lexik\Bundle\JWTAuthenticationBundle\Event;

use Symfony\Contracts\EventDispatcher\Event;

/**
* JWTDecodedEvent.
*
Expand Down Expand Up @@ -54,7 +56,7 @@ public function markAsInvalid()
}

/**
* @return boolean
* @return bool
*/
public function isValid()
{
Expand Down
16 changes: 3 additions & 13 deletions Event/JWTEncodedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,17 @@

namespace Lexik\Bundle\JWTAuthenticationBundle\Event;

/**
* JWTEncodedEvent.
*/
use Symfony\Contracts\EventDispatcher\Event;

class JWTEncodedEvent extends Event
{
/**
* @var string
*/
private $jwtString;

/**
* @param string $jwtString
*/
public function __construct($jwtString)
public function __construct(string $jwtString)
{
$this->jwtString = $jwtString;
}

/**
* @return string
*/
public function getJWTString()
{
return $this->jwtString;
Expand Down
5 changes: 1 addition & 4 deletions Exception/InvalidPayloadException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
*/
class InvalidPayloadException extends AuthenticationException
{
/**
* @var string
*/
private $invalidKey;

/**
* @param string $invalidKey The key that cannot be found in the payload
*/
public function __construct($invalidKey)
public function __construct(string $invalidKey)
{
$this->invalidKey = $invalidKey;
}
Expand Down
20 changes: 1 addition & 19 deletions Exception/JWTFailureException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,22 @@
*/
class JWTFailureException extends \Exception
{
/**
* @var string
*/
private $reason;

/**
* @var array|null
*/
private $payload;

/**
* @param string $reason
* @param string $message
* @param \Exception|null $previous
*/
public function __construct($reason, $message, \Exception $previous = null, array $payload = null)
public function __construct(string $reason, string $message, \Throwable $previous = null, array $payload = null)
{
$this->reason = $reason;
$this->payload = $payload;

parent::__construct($message, 0, $previous);
}

/**
* @return string
*/
public function getReason()
{
return $this->reason;
}

/**
* @return array|null
*/
public function getPayload()
{
return $this->payload;
Expand Down
13 changes: 1 addition & 12 deletions Exception/UserNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,10 @@
*/
class UserNotFoundException extends AuthenticationException
{
/**
* @var string
*/
private $userIdentityField;

/**
* @var string
*/
private $identity;

/**
* @param string $userIdentityField
* @param string $identity
*/
public function __construct($userIdentityField, $identity)
public function __construct(string $userIdentityField, string $identity)
{
$this->userIdentityField = $userIdentityField;
$this->identity = $identity;
Expand Down
13 changes: 6 additions & 7 deletions Helper/JWTSplitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* JWTSplitter.
*
* @author Adam Lukacovic <adam@adamlukacovic.sk>
*
* @final
*/
class JWTSplitter
{
Expand All @@ -24,12 +26,9 @@ class JWTSplitter
*/
private $signature;

/**
* @param string $jwt
*/
public function __construct($jwt)
public function __construct(string $jwt)
{
list($this->header, $this->payload, $this->signature) = explode('.', $jwt);
[$this->header, $this->payload, $this->signature] = explode('.', $jwt);
}

/**
Expand All @@ -38,8 +37,8 @@ public function __construct($jwt)
*/
public function getParts($parts = [])
{
if (empty($parts)) {
return implode('.', get_object_vars($this));
if (!$parts) {
return "$this->header.$this->payload.$this->signature";
}

return implode('.', array_intersect_key(get_object_vars($this), array_flip($parts)));
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LexikJWTAuthenticationBundle

This bundle provides JWT (Json Web Token) authentication for your Symfony API.

It is compatible and tested with PHP 5.6, 7.3, 7.4, 8.0 on Symfony 3.4, 4.x and 5.x.
It is compatible and tested with PHP 7.1+ on Symfony 3.4, 4.x and 5.x.

Documentation
-------------
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/console.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="lexik_jwt_authentication.check_config_command" class="Lexik\Bundle\JWTAuthenticationBundle\Command\CheckConfigCommand" public="true">
<service id="lexik_jwt_authentication.check_config_command" class="Lexik\Bundle\JWTAuthenticationBundle\Command\CheckConfigCommand">
<argument type="service" id="lexik_jwt_authentication.key_loader" />
<argument type="string">%lexik_jwt_authentication.encoder.signature_algorithm%</argument> <!-- signature algorithm -->
<tag name="console.command" command="lexik:jwt:check-config" />
Expand Down
12 changes: 1 addition & 11 deletions Response/JWTAuthenticationFailureResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@
*/
final class JWTAuthenticationFailureResponse extends JsonResponse
{
/**
* The response message.
*
* @var string
*/
private $message;

/**
* @param string $message A failure message passed in the response body
*/
public function __construct($message = 'Bad credentials', $statusCode = JsonResponse::HTTP_UNAUTHORIZED)
public function __construct(string $message = 'Bad credentials', string $statusCode = JsonResponse::HTTP_UNAUTHORIZED)
{
$this->message = $message;

Expand Down
9 changes: 2 additions & 7 deletions Security/Authentication/Provider/JWTProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
use Lexik\Bundle\JWTAuthenticationBundle\Security\Authentication\Token\JWTUserToken;
use Lexik\Bundle\JWTAuthenticationBundle\Security\Guard\JWTTokenAuthenticator;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTManagerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
Expand Down Expand Up @@ -91,11 +90,7 @@ public function authenticate(TokenInterface $token)
$authToken->setRawToken($token->getCredentials());

$event = new JWTAuthenticatedEvent($payload, $authToken);
if ($this->dispatcher instanceof ContractsEventDispatcherInterface) {
$this->dispatcher->dispatch($event, Events::JWT_AUTHENTICATED);
} else {
$this->dispatcher->dispatch(Events::JWT_AUTHENTICATED, $event);
}
$this->dispatcher->dispatch($event, Events::JWT_AUTHENTICATED);

return $authToken;
}
Expand Down
17 changes: 3 additions & 14 deletions Security/Firewall/JWTListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
use Lexik\Bundle\JWTAuthenticationBundle\Security\Authentication\Token\JWTUserToken;
use Lexik\Bundle\JWTAuthenticationBundle\Security\Guard\JWTTokenAuthenticator;
use Lexik\Bundle\JWTAuthenticationBundle\TokenExtractor\TokenExtractorInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
Expand Down Expand Up @@ -82,12 +81,7 @@ public function __invoke($event)

if (null === $requestToken) {
$jwtNotFoundEvent = new JWTNotFoundEvent();
if ($this->dispatcher instanceof ContractsEventDispatcherInterface) {
$this->dispatcher->dispatch($jwtNotFoundEvent, Events::JWT_NOT_FOUND);
} else {
$this->dispatcher->dispatch(Events::JWT_NOT_FOUND, $jwtNotFoundEvent);
}

$this->dispatcher->dispatch($jwtNotFoundEvent, Events::JWT_NOT_FOUND);

if ($response = $jwtNotFoundEvent->getResponse()) {
$event->setResponse($response);
Expand All @@ -112,12 +106,7 @@ public function __invoke($event)
$response = new JWTAuthenticationFailureResponse($failed->getMessage());

$jwtInvalidEvent = new JWTInvalidEvent($failed, $response);
if ($this->dispatcher instanceof ContractsEventDispatcherInterface) {
$this->dispatcher->dispatch($jwtInvalidEvent, Events::JWT_INVALID);
} else {
$this->dispatcher->dispatch(Events::JWT_INVALID, $jwtInvalidEvent);
}

$this->dispatcher->dispatch($jwtInvalidEvent, Events::JWT_INVALID);

$event->setResponse($jwtInvalidEvent->getResponse());
}
Expand Down
Loading

0 comments on commit f9e92d7

Please sign in to comment.