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

2.0 Proposal #347

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0f3f175
Bump PHP and Symfony requirements
mbabker Apr 21, 2022
16e9678
Remove deprecated document/entity classes
mbabker Apr 21, 2022
f066954
Removed deprecated RefreshTokenManagerInterface::create()
mbabker Apr 21, 2022
a8a706f
Removed classes supporting authentication for Symfony 5.3 and earlier
mbabker Apr 21, 2022
a697c4d
Remove deprecated RefreshTokenManager class
mbabker Apr 21, 2022
a4aa872
Removed deprecated configuration nodes
mbabker Apr 21, 2022
da21b75
Use the AsCommand attribute to configure console commands
mbabker Apr 21, 2022
f688fe8
Remove token auto-generation from AbstractRefreshToken::setRefreshTok…
mbabker Apr 21, 2022
c9cc9e5
Remove compatibility code for older PHP and Symfony versions
mbabker Apr 21, 2022
61d9517
Use the check_path configuration when determining if the authenticato…
mbabker Apr 21, 2022
5e8b925
Require the refresh_token_class config node to be set
mbabker Apr 21, 2022
8b8e9c8
Remove more compatibility code
mbabker Apr 21, 2022
71de272
Inline ObjectManagerCompilerPass into the container extension
mbabker Apr 21, 2022
fe15ec4
Remove manager_type config node, use feature detection when object_ma…
mbabker Apr 21, 2022
3f5671b
Register logout event through the security factory
mbabker Apr 21, 2022
4c043a5
Remove unused code
mbabker Apr 21, 2022
b97fb7e
Standardize container ID prefixes
mbabker Apr 21, 2022
f0947f6
Bump dependency ranges
mbabker Apr 21, 2022
6faca1a
Use attributes for fixtures
mbabker Apr 21, 2022
0c98d0d
Add final keyword to classes which shouldn't be extended
mbabker May 8, 2022
e374069
Add typehints everywhere
mbabker May 8, 2022
111277a
The ODM returns an iterable object, change the typehint accordingly
mbabker May 8, 2022
f1b9b29
Style fixes
mbabker Dec 1, 2022
03763dc
Drop configuration documentation for Symfony <5.4
GwendolenLynch Jul 25, 2023
a2c500f
Bump Mongo server
mbabker Dec 31, 2024
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
39 changes: 5 additions & 34 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,22 @@ on: [push, pull_request]

jobs:
test:
runs-on: 'ubuntu-20.04'
runs-on: 'ubuntu-22.04'
continue-on-error: ${{ matrix.can-fail }}
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1', '8.2', '8.3']
symfony: ['5.4.*', '6.0.*', '6.1.*', '6.2.*', '6.3.*', '6.4.*', '7.0.*']
php: ['8.2', '8.3', '8.4']
symfony: ['5.4.*', '6.4.*', '7.2.*']
composer-flags: ['--prefer-stable']
can-fail: [false]
extensions: ['curl, iconv, mbstring, mongodb, pdo, pdo_sqlite, sqlite, zip']
include:
- php: '7.4'
- php: '8.2'
symfony: '5.4.*'
composer-flags: '--prefer-stable --prefer-lowest'
can-fail: false
extensions: 'curl, iconv, mbstring, mongodb, pdo, pdo_sqlite, sqlite, zip'
exclude:
- php: '7.4'
symfony: '6.0.*'
- php: '7.4'
symfony: '6.1.*'
- php: '7.4'
symfony: '6.2.*'
- php: '7.4'
symfony: '6.3.*'
- php: '7.4'
symfony: '6.4.*'
- php: '7.4'
symfony: '7.0.*'
- php: '8.0'
symfony: '6.1.*'
- php: '8.0'
symfony: '6.2.*'
- php: '8.0'
symfony: '6.3.*'
- php: '8.0'
symfony: '6.4.*'
- php: '8.0'
symfony: '7.0.*'
- php: '8.1'
symfony: '7.0.*'

name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"

Expand All @@ -70,13 +45,9 @@ jobs:
id: setup-mongodb
uses: mongodb-labs/drivers-evergreen-tools@master
with:
version: '5.0'
version: '6'
topology: server

- name: Remove Guard (Symfony >=6.0)
if: contains(fromJSON('["6.0.*", "6.1.*", "6.2.*", "6.3.*", "6.4.*", "7.0.*"]'), matrix.symfony)
run: composer remove --dev --no-update symfony/security-guard

- name: Install dependencies
run: composer update ${{ matrix.composer-flags }} --prefer-dist --no-suggest
env:
Expand Down
20 changes: 3 additions & 17 deletions Command/ClearInvalidRefreshTokensCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(name: 'gesdinet:jwt:clear', description: 'Clear invalid refresh tokens.')]
class ClearInvalidRefreshTokensCommand extends Command
final class ClearInvalidRefreshTokensCommand extends Command
{
/**
* @deprecated
*/
protected static $defaultName = 'gesdinet:jwt:clear';

private RefreshTokenManagerInterface $refreshTokenManager;

public function __construct(RefreshTokenManagerInterface $refreshTokenManager)
Expand All @@ -39,23 +34,14 @@ public function __construct(RefreshTokenManagerInterface $refreshTokenManager)

protected function configure(): void
{
$this
->setDescription('Clear invalid refresh tokens.')
->addArgument('datetime', InputArgument::OPTIONAL, 'An optional date, all tokens before this date will be removed; the value should be able to be parsed by DateTime.');
$this->addArgument('datetime', InputArgument::OPTIONAL, 'An optional date, all tokens before this date will be removed; the value should be able to be parsed by DateTime.', 'now');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

/** @var string|null $datetime */
$datetime = $input->getArgument('datetime');

if (null === $datetime) {
$datetime = new \DateTime();
} else {
$datetime = new \DateTime($datetime);
}
$datetime = new \DateTime($input->getArgument('datetime'));

$revokedTokens = $this->refreshTokenManager->revokeAllInvalid($datetime);

Expand Down
13 changes: 3 additions & 10 deletions Command/RevokeRefreshTokenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(name: 'gesdinet:jwt:revoke', description: 'Revoke a refresh token')]
class RevokeRefreshTokenCommand extends Command
#[AsCommand(name: 'gesdinet:jwt:revoke', description: 'Revoke a refresh token.')]
final class RevokeRefreshTokenCommand extends Command
{
/**
* @deprecated
*/
protected static $defaultName = 'gesdinet:jwt:revoke';

private RefreshTokenManagerInterface $refreshTokenManager;

public function __construct(RefreshTokenManagerInterface $refreshTokenManager)
Expand All @@ -38,9 +33,7 @@ public function __construct(RefreshTokenManagerInterface $refreshTokenManager)

protected function configure(): void
{
$this
->setDescription('Revoke a refresh token')
->addArgument('refresh_token', InputArgument::REQUIRED, 'The refresh token to revoke');
$this->addArgument('refresh_token', InputArgument::REQUIRED, 'The refresh token to revoke');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ final class AddExtractorsToChainCompilerPass implements CompilerPassInterface

public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('gesdinet.jwtrefreshtoken.request.extractor.chain')) {
if (!$container->hasDefinition('gesdinet_jwt_refresh_token.request.extractor.chain')) {
return;
}

$definition = $container->getDefinition('gesdinet.jwtrefreshtoken.request.extractor.chain');
$definition = $container->getDefinition('gesdinet_jwt_refresh_token.request.extractor.chain');

foreach ($this->findAndSortTaggedServices('gesdinet_jwt_refresh_token.request_extractor', $container) as $extractorService) {
$definition->addMethodCall('addExtractor', [$extractorService]);
Expand Down
47 changes: 0 additions & 47 deletions DependencyInjection/Compiler/CustomUserProviderCompilerPass.php

This file was deleted.

20 changes: 0 additions & 20 deletions DependencyInjection/Compiler/ObjectManagerCompilerPass.php

This file was deleted.

37 changes: 0 additions & 37 deletions DependencyInjection/Compiler/UserCheckerCompilerPass.php

This file was deleted.

54 changes: 7 additions & 47 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

namespace Gesdinet\JWTRefreshTokenBundle\DependencyInjection;

use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
final class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
Expand All @@ -32,54 +32,23 @@ public function getConfigTreeBuilder(): TreeBuilder
->defaultFalse()
->info('The default update TTL flag for all authenticators.')
->end()
->scalarNode('firewall')
->setDeprecated('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%node%" node is deprecated without replacement.')
->defaultValue('api')
->end()
->scalarNode('user_provider')
->setDeprecated('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%node%" node is deprecated without replacement.')
->defaultNull()
->end()
->scalarNode('user_identity_field')
->setDeprecated('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%node%" node is deprecated without replacement.')
->defaultValue('username')
->end()
->scalarNode('manager_type')
->defaultValue('orm')
->info('Set the type of object manager to use (default: orm)')
->end()
->scalarNode('refresh_token_class')
->defaultNull()
->info(sprintf('Set the refresh token class to use (default: %s)', RefreshToken::class))
->isRequired()
->cannotBeEmpty()
->info('Set the refresh token class to use')
->validate()
->ifTrue(static fn ($v): bool => null === $v)
->then(static function () {
trigger_deprecation(
'gesdinet/jwt-refresh-token-bundle',
'1.1',
'Not setting the "refresh_token_class" option is deprecated, as of 2.0 a class must be set.'
);
})
->ifTrue(static fn ($v): bool => null === $v || !\in_array(RefreshTokenInterface::class, class_implements($v), true))
->thenInvalid(sprintf('The "refresh_token_class" class must implement "%s".', RefreshTokenInterface::class))
->end()
->end()
->scalarNode('object_manager')
->defaultNull()
->info('Set the object manager to use (default: doctrine.orm.entity_manager)')
->end()
->scalarNode('user_checker')
->setDeprecated('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%node%" node is deprecated without replacement.')
->defaultValue('security.user_checker')
->end()
->scalarNode('refresh_token_entity')
->setDeprecated('gesdinet/jwt-refresh-token-bundle', '0.5', 'The "%node%" node is deprecated, use the "refresh_token_class" node instead.')
->defaultNull()
->info(sprintf('Set the refresh token class to use (default: %s)', RefreshToken::class))
->end()
->scalarNode('entity_manager')
->setDeprecated('gesdinet/jwt-refresh-token-bundle', '0.5', 'The "%node%" node is deprecated, use the "object_manager" node instead.')
->defaultNull()
->info('Set the entity manager to use')
->end()
->scalarNode('single_use')
->defaultFalse()
->info('When true, generate a new refresh token on consumption (deleting the old one)')
Expand All @@ -88,11 +57,6 @@ public function getConfigTreeBuilder(): TreeBuilder
->defaultValue('refresh_token')
->info('The default request parameter name containing the refresh token for all authenticators.')
->end()
->booleanNode('doctrine_mappings')
->setDeprecated('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%node%" node is deprecated without replacement.')
->info('When true, resolving of Doctrine mapping is done automatically to use either ORM or ODM object manager')
->defaultTrue()
->end()
->arrayNode('cookie')
->canBeEnabled()
->children()
Expand All @@ -108,10 +72,6 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarNode('remove_token_from_body')->defaultTrue()->end()
->end()
->end()
->scalarNode('logout_firewall')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should depreciate it before we delete it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thanks for the reminder here. There are definitely a few things that could use a proper deprecation in a 1.x release that I'm now forgetting about since I've been sitting on this branch for so long 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#350 for compat layer

->defaultValue('api')
->info('Name of the firewall that triggers the logout event to hook into (default: api)')
->end()
->scalarNode('return_expiration')
->defaultFalse()
->info('When true, the response will include the token expiration timestamp')
Expand Down
Loading