Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop PHP <7.1 and Symfony <5.3 support #1056

Merged
merged 1 commit into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
matrix:
include:
# Lowest Deps
- php: 7.1
symfony: 4.4.*
- php: 7.2
symfony: 5.4.*
composer-flags: '--prefer-stable --prefer-lowest'
can-fail: false
# LTS with latest stable PHP
Expand All @@ -24,17 +24,12 @@ jobs:
can-fail: false
# Stable Symfony branches
- php: 7.4
symfony: 4.4.*
composer-flags: '--prefer-stable'
can-fail: false
- php: 8.0
symfony: 6.0.*
symfony: 5.4.*
composer-flags: '--prefer-stable'
can-fail: false
# Development Symfony branches
- php: 8.1
symfony: 6.1.*@dev
composer-flags: ''
symfony: 6.1.*
composer-flags: '--prefer-stable'
can-fail: false

name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"
Expand Down
109 changes: 66 additions & 43 deletions DependencyInjection/Security/Factory/JWTAuthenticatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,74 @@
namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory;

use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;

if (interface_exists(SecurityFactoryInterface::class) && !interface_exists(AuthenticatorFactoryInterface::class)) {
eval('
namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory;

use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;

/**
* Wires the "jwt" authenticator from user configuration.
*
* @author Robin Chalas <[email protected]>
*/
class JWTAuthenticatorFactory implements SecurityFactoryInterface
{
use JWTAuthenticatorFactoryTrait;
}
');
} elseif (!method_exists(SecurityExtension::class, 'addAuthenticatorFactory')) {
eval('
namespace Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory;

use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;

/**
* Wires the "jwt" authenticator from user configuration.
*
* @author Robin Chalas <[email protected]>
*/
class JWTAuthenticatorFactory implements AuthenticatorFactoryInterface, SecurityFactoryInterface
{
use JWTAuthenticatorFactoryTrait;
}
');
} else {
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
* Wires the "jwt" authenticator from user configuration.
*
* @author Robin Chalas <[email protected]>
*/
class JWTAuthenticatorFactory implements AuthenticatorFactoryInterface
{
/**
* @throws \LogicException
*/
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
{
throw new \LogicException('This method is implemented for BC purpose and should never be called.');
}

/**
* Wires the "jwt" authenticator from user configuration.
*
* @author Robin Chalas <[email protected]>
* {@inheritdoc}
*/
class JWTAuthenticatorFactory implements AuthenticatorFactoryInterface
public function getPriority(): int
{
use JWTAuthenticatorFactoryTrait;
return -10;
}

/**
* {@inheritdoc}
*/
public function getKey(): string
{
return 'jwt';
}

/**
* {@inheritdoc}
*/
public function addConfiguration(NodeDefinition $node)
{
$node
->children()
->scalarNode('provider')
->defaultNull()
->end()
->scalarNode('authenticator')
->defaultValue('lexik_jwt_authentication.security.jwt_authenticator')
->end()
->end()
;
}

public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
{
$authenticatorId = 'security.authenticator.jwt.' . $firewallName;

$userProviderId = empty($config['provider']) ? $userProviderId : 'security.user.provider.concrete.' . $config['provider'];

$container
->setDefinition($authenticatorId, new ChildDefinition($config['authenticator']))
->replaceArgument(3, new Reference($userProviderId))
;

// Compile-time parameter removed by RemoveLegacyAuthenticatorPass
// Stop setting it when guard support gets removed (aka when removing Symfony<5.3 support)
$container->setParameter('lexik_jwt_authentication.authenticator_manager_enabled', true);

return $authenticatorId;
}
}

This file was deleted.

20 changes: 1 addition & 19 deletions LexikJWTAuthenticationBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory\JWTFactory;
use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory\JWTSecurityFactory;
use Lexik\Bundle\JWTAuthenticationBundle\DependencyInjection\Security\Factory\JWTUserFactory;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
use Symfony\Component\Console\Application;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
Expand Down Expand Up @@ -38,24 +37,7 @@ public function build(ContainerBuilder $container)

$extension->addUserProviderFactory(new JWTUserFactory());

// Authenticator factory for Symfony 5.4 and later
if (method_exists($extension, 'addAuthenticatorFactory')) {
$extension->addAuthenticatorFactory(new JWTAuthenticatorFactory());

return;
}

// Security listener factory for Symfony 5.3 and earlier
if (method_exists($extension, 'addSecurityListenerFactory')) {
$extension->addSecurityListenerFactory(new JWTAuthenticatorFactory());

return;
}

// Security listener factory for Symfony 4.4
if (method_exists($extension, 'addSecurityListenerFactory')) {
$extension->addSecurityListenerFactory(new JWTFactory(false)); // BC 1.x, to be removed in 3.0
}
$extension->addAuthenticatorFactory(new JWTAuthenticatorFactory());
}

/**
Expand Down
41 changes: 0 additions & 41 deletions Security/Authenticator/ForwardCompatAuthenticatorTrait.php

This file was deleted.

7 changes: 1 addition & 6 deletions Security/Authenticator/JWTAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@

class JWTAuthenticator extends AbstractAuthenticator implements AuthenticationEntryPointInterface
{
use ForwardCompatAuthenticatorTrait;

/**
* @var TokenExtractorInterface
*/
Expand Down Expand Up @@ -98,10 +96,7 @@ public function supports(Request $request): ?bool
return false !== $this->getTokenExtractor()->extract($request);
}

/**
* @return Passport
*/
public function doAuthenticate(Request $request) /*: Passport */
public function authenticate(Request $request): Passport
{
$token = $this->getTokenExtractor()->extract($request);

Expand Down
40 changes: 20 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,35 @@
}
],
"require": {
"php": ">=7.1",
"php": ">=7.2",
"ext-openssl": "*",
"lcobucci/jwt": "^3.4|^4.0",
"namshi/jose": "^7.2",
"symfony/config": "^4.4|^5.3|^6.0",
"symfony/dependency-injection": "^4.4|^5.3|^6.0",
"symfony/config": "^5.4|^6.0",
"symfony/dependency-injection": "^5.4|^6.0",
"symfony/deprecation-contracts": "^2.4|^3.0",
"symfony/event-dispatcher": "^4.4|^5.3|^6.0",
"symfony/http-foundation": "^4.4|^5.3|^6.0",
"symfony/http-kernel": "^4.4|^5.3|^6.0",
"symfony/property-access": "^4.4|^5.3|^6.0",
"symfony/security-bundle": "^4.4|^5.3|^6.0",
"symfony/security-core": "^4.4|^5.3|^6.0",
"symfony/security-http": "^4.4|^5.3|^6.0",
"symfony/event-dispatcher": "^5.4|^6.0",
"symfony/http-foundation": "^5.4|^6.0",
"symfony/http-kernel": "^5.4|^6.0",
"symfony/property-access": "^5.4|^6.0",
"symfony/security-bundle": "^5.4|^6.0",
"symfony/security-core": "^5.4|^6.0",
"symfony/security-http": "^5.4|^6.0",
"symfony/translation-contracts": "^1.0|^2.0|^3.0"
},
"require-dev": {
"symfony/browser-kit": "^4.4|^5.3|^6.0",
"symfony/console": "^4.4|^5.3|^6.0",
"symfony/dom-crawler": "^4.4|^5.3|^6.0",
"symfony/filesystem": "^4.4|^5.3|^6.0",
"symfony/framework-bundle": "^4.4|^5.3|^6.0",
"symfony/phpunit-bridge": "^4.4|^5.3|^6.0",
"symfony/security-guard": "^4.4|^5.3",
"symfony/var-dumper": "^4.4|^5.3|^6.0",
"symfony/yaml": "^4.4|^5.3|^6.0"
"symfony/browser-kit": "^5.4|^6.0",
"symfony/console": "^5.4|^6.0",
"symfony/dom-crawler": "^5.4|^6.0",
"symfony/filesystem": "^5.4|^6.0",
"symfony/framework-bundle": "^5.4|^6.0",
"symfony/phpunit-bridge": "^5.4|^6.0",
"symfony/var-dumper": "^5.4|^6.0",
"symfony/yaml": "^5.4|^6.0"
},
"conflict": {
"symfony/console": "<4.4"
"symfony/console": "<4.4",
"symfony/security-http": "<=5.3"
},
"suggest": {
"gesdinet/jwt-refresh-token-bundle": "Implements a refresh token system over Json Web Tokens in Symfony",
Expand Down