Skip to content

Commit 2711479

Browse files
committed
feature #59 Add support for Symfony 5.4 & 6 (chalasr)
This PR was merged into the 0.1-dev branch. Discussion ---------- Add support for Symfony 5.4 & 6 Commits ------- 7d27687 Add support for Symfony 5.4 & 6
2 parents c8c657e + 7d27687 commit 2711479

20 files changed

+284
-119
lines changed

.github/workflows/static-analysis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
tools: composer:v2, cs2pr
1919
extensions: intl, bcmath, curl, openssl, mbstring, pdo, pdo_sqlite
2020

21+
- name: "installing psalm"
22+
run: "composer require vimeo/psalm:^4.6 psalm/plugin-symfony:^2.2 --dev --no-update && composer require --no-update"
23+
2124
- name: "installing dependencies"
2225
run: "composer update --no-interaction --no-progress"
2326

.github/workflows/unit-tests.yml

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,65 @@ name: "unit tests"
33
on: [ "pull_request", "push" ]
44

55
jobs:
6-
unit-tests:
7-
name: "unit tests"
8-
9-
runs-on: "ubuntu-latest"
10-
6+
tests:
7+
runs-on: ubuntu-latest
8+
continue-on-error: ${{ matrix.can-fail }}
119
strategy:
10+
fail-fast: false
1211
matrix:
13-
symfony-version:
14-
- "5.3.*"
15-
php-version:
16-
- "7.2"
17-
- "7.3"
18-
- "7.4"
19-
- "8.0"
20-
dependencies:
21-
- "lowest"
22-
- "highest"
12+
include:
13+
# Lowest supported stable Symfony branches
14+
- php: 7.2
15+
symfony: 5.3.*
16+
composer-flags: '--prefer-stable'
17+
can-fail: false
18+
# Development Symfony branches
19+
- php: 7.3
20+
symfony: 5.4.*@dev
21+
composer-flags: '--prefer-stable' # Needed to force `lcobucci/jwt` to install a usable version
22+
can-fail: false
23+
- php: 7.4
24+
symfony: 5.4.*@dev
25+
composer-flags: ''
26+
can-fail: false
27+
- php: 8.0
28+
symfony: 5.4.*@dev
29+
composer-flags: ''
30+
can-fail: false
31+
- php: 8.1
32+
symfony: 6.0.*@dev
33+
composer-flags: ''
34+
can-fail: false
2335

24-
steps:
25-
- name: "checkout"
26-
uses: "actions/checkout@v2"
36+
name: "PHP ${{ matrix.php }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"
2737

28-
- name: "installing PHP"
29-
uses: "shivammathur/setup-php@v2"
30-
with:
31-
php-version: "${{ matrix.php-version }}"
32-
tools: composer:v2, cs2pr
33-
extensions: intl, bcmath, curl, openssl, mbstring, pdo, pdo_sqlite
34-
coverage: pcov
35-
ini-values: memory_limit=-1
36-
37-
- name: "caching dependencies"
38-
uses: "actions/cache@v2"
39-
with:
40-
path: |
41-
~/.composer/cache
42-
vendor
43-
key: "php-${{ matrix.php-version }}"
44-
restore-keys: "php-${{ matrix.php-version }}"
38+
steps:
39+
- name: "Checkout"
40+
uses: "actions/checkout@v2"
41+
with:
42+
fetch-depth: 2
4543

46-
- name: "configuring composer platform"
47-
if: (startsWith(matrix.php, '8.0'))
48-
run: composer config platform.php 7.4.99
44+
- name: "Cache Composer packages"
45+
uses: "actions/cache@v2"
46+
with:
47+
path: "~/.composer/cache"
48+
key: "php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-composer-${{ hashFiles('composer.json') }}-flags-${{ matrix.composer-flags }}"
49+
restore-keys: "php-"
4950

50-
- name: "install lowest dependencies"
51-
if: ${{ matrix.dependencies == 'lowest' }}
52-
run: composer update --prefer-lowest --no-interaction --no-progress --prefer-dist
51+
- name: "Install PHP"
52+
uses: "shivammathur/setup-php@v2"
53+
with:
54+
php-version: "${{ matrix.php }}"
55+
tools: "composer:v2,flex"
5356

54-
- name: "install highest dependencies"
55-
if: ${{ matrix.dependencies == 'highest' }}
56-
run: |
57-
composer require --no-update symfony/config=${{ matrix.symfony-version }} symfony/http-kernel=${{ matrix.symfony-version }} symfony/dependency-injection=${{ matrix.symfony-version }} symfony/options-resolver=${{ matrix.symfony-version }}
58-
composer require --no-update --dev symfony/framework-bundle=${{ matrix.symfony-version }} symfony/yaml=${{ matrix.symfony-version }}
59-
composer update --no-interaction --no-progress --prefer-dist
57+
- name: "Set Composer stability"
58+
if: "matrix.symfony == '5.4.*@dev' || matrix.symfony == '6.0.*@dev'"
59+
run: "composer config minimum-stability dev"
6060

61-
- name: "installing phpunit"
62-
run: vendor/bin/simple-phpunit install
61+
- name: "Install dependencies"
62+
run: "composer update ${{ matrix.composer-flags }} --prefer-dist"
63+
env:
64+
SYMFONY_REQUIRE: "${{ matrix.symfony }}"
6365

64-
- name: "running unit tests"
65-
run: vendor/bin/simple-phpunit
66+
- name: "Run PHPUnit Tests"
67+
run: "vendor/bin/simple-phpunit"

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@
2222
"league/oauth2-server": "^8.0",
2323
"nyholm/psr7": "^1.4",
2424
"psr/http-factory": "^1.0",
25-
"symfony/framework-bundle": "^5.3",
25+
"symfony/framework-bundle": "^5.3|^6.0",
26+
"symfony/polyfill-php81": "^1.22",
2627
"symfony/psr-http-message-bridge": "^2.0",
27-
"symfony/security-bundle": "^5.3"
28+
"symfony/security-bundle": "^5.3|^6.0"
2829
},
2930
"require-dev": {
3031
"ext-pdo": "*",
3132
"ext-pdo_sqlite": "*",
32-
"psalm/plugin-symfony": "^2.2",
33-
"symfony/browser-kit": "^5.3",
34-
"symfony/phpunit-bridge": "^5.3",
35-
"vimeo/psalm": "^4.6"
33+
"symfony/browser-kit": "^5.3|^6.0",
34+
"symfony/phpunit-bridge": "^5.3|^6.0"
3635
},
3736
"autoload": {
3837
"psr-4": { "League\\Bundle\\OAuth2ServerBundle\\": "src/" }
@@ -47,5 +46,6 @@
4746
"branch-alias": {
4847
"dev-master": "0.1-dev"
4948
}
50-
}
49+
},
50+
"minimum-stability": "dev"
5151
}

psalm.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
forbidEcho="true"
55
strictBinaryOperands="true"
66
phpVersion="7.1"
7-
allowPhpStormGenerics="true"
87
allowStringToStandInForClass="true"
98
rememberPropertyAssignmentsAfterCall="false"
109
checkForThrowsInGlobalScope="true"

src/DependencyInjection/LeagueOAuth2ServerExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function load(array $configs, ContainerBuilder $container)
7474
/**
7575
* {@inheritdoc}
7676
*/
77-
public function getAlias()
77+
public function getAlias(): string
7878
{
7979
return 'league_oauth2_server';
8080
}

src/DependencyInjection/Security/OAuth2Factory.php

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,38 @@
44

55
namespace League\Bundle\OAuth2ServerBundle\DependencyInjection\Security;
66

7-
use League\Bundle\OAuth2ServerBundle\Security\Authenticator\OAuth2Authenticator;
87
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
98
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
10-
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
11-
use Symfony\Component\DependencyInjection\ChildDefinition;
12-
use Symfony\Component\DependencyInjection\ContainerBuilder;
13-
use Symfony\Component\DependencyInjection\Reference;
14-
15-
/**
16-
* @author Mathias Arlaud <[email protected]>
17-
*/
18-
final class OAuth2Factory implements SecurityFactoryInterface, AuthenticatorFactoryInterface
19-
{
20-
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint): array
21-
{
22-
throw new \LogicException('OAuth2 is not supported when "security.enable_authenticator_manager" is not set to true.');
23-
}
24-
25-
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
26-
{
27-
$authenticator = sprintf('security.authenticator.oauth2.%s', $firewallName);
28-
29-
$definition = new ChildDefinition(OAuth2Authenticator::class);
30-
$definition->replaceArgument(2, new Reference($userProviderId));
31-
32-
$container->setDefinition($authenticator, $definition);
33-
34-
return $authenticator;
35-
}
36-
37-
public function getPosition(): string
9+
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
10+
11+
if (interface_exists(SecurityFactoryInterface::class) && !interface_exists(AuthenticatorFactoryInterface::class)) {
12+
/**
13+
* Wires the "oauth" authenticator from user configuration.
14+
*
15+
* @author Mathias Arlaud <[email protected]>
16+
*/
17+
class OAuth2Factory implements SecurityFactoryInterface
3818
{
39-
return 'pre_auth';
19+
use OAuth2FactoryTrait;
4020
}
41-
42-
public function getKey(): string
21+
} elseif (!method_exists(SecurityExtension::class, 'addAuthenticatorFactory')) {
22+
/**
23+
* Wires the "oauth" authenticator from user configuration.
24+
*
25+
* @author Mathias Arlaud <[email protected]>
26+
*/
27+
class OAuth2Factory implements AuthenticatorFactoryInterface, SecurityFactoryInterface
4328
{
44-
return 'oauth2';
29+
use OAuth2FactoryTrait;
4530
}
46-
47-
public function addConfiguration(NodeDefinition $builder): void
31+
} else {
32+
/**
33+
* Wires the "oauth" authenticator from user configuration.
34+
*
35+
* @author Mathias Arlaud <[email protected]>
36+
*/
37+
class OAuth2Factory implements AuthenticatorFactoryInterface
4838
{
39+
use OAuth2FactoryTrait;
4940
}
5041
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace League\Bundle\OAuth2ServerBundle\DependencyInjection\Security;
6+
7+
use League\Bundle\OAuth2ServerBundle\Security\Authenticator\OAuth2Authenticator;
8+
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
9+
use Symfony\Component\DependencyInjection\ChildDefinition;
10+
use Symfony\Component\DependencyInjection\ContainerBuilder;
11+
use Symfony\Component\DependencyInjection\Reference;
12+
13+
/**
14+
* @author Mathias Arlaud <[email protected]>
15+
* @author Robin Chalas <[email protected]>
16+
*/
17+
trait OAuth2FactoryTrait
18+
{
19+
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint): array
20+
{
21+
throw new \LogicException('OAuth2 is not supported when "security.enable_authenticator_manager" is not set to true.');
22+
}
23+
24+
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
25+
{
26+
$authenticator = sprintf('security.authenticator.oauth2.%s', $firewallName);
27+
28+
$definition = new ChildDefinition(OAuth2Authenticator::class);
29+
$definition->replaceArgument(2, new Reference($userProviderId));
30+
31+
$container->setDefinition($authenticator, $definition);
32+
33+
return $authenticator;
34+
}
35+
36+
public function getPosition(): string
37+
{
38+
return 'pre_auth';
39+
}
40+
41+
public function getPriority(): int
42+
{
43+
return -10;
44+
}
45+
46+
public function getKey(): string
47+
{
48+
return 'oauth2';
49+
}
50+
51+
public function addConfiguration(NodeDefinition $builder): void
52+
{
53+
}
54+
}

src/Entity/Scope.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ final class Scope implements ScopeEntityInterface
1313

1414
/**
1515
* {@inheritdoc}
16+
*
17+
* @return mixed
1618
*/
19+
#[\ReturnTypeWillChange]
1720
public function jsonSerialize()
1821
{
1922
return $this->getIdentifier();

src/LeagueOAuth2ServerBundle.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use League\Bundle\OAuth2ServerBundle\DependencyInjection\Security\OAuth2Factory;
1111
use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
1212
use Symfony\Component\DependencyInjection\ContainerBuilder;
13+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
1314
use Symfony\Component\HttpKernel\Bundle\Bundle;
1415

1516
final class LeagueOAuth2ServerBundle extends Bundle
@@ -30,7 +31,7 @@ public function build(ContainerBuilder $container)
3031
/**
3132
* {@inheritdoc}
3233
*/
33-
public function getContainerExtension()
34+
public function getContainerExtension(): ExtensionInterface
3435
{
3536
return new LeagueOAuth2ServerExtension();
3637
}
@@ -39,6 +40,17 @@ private function configureSecurityExtension(ContainerBuilder $container): void
3940
{
4041
/** @var SecurityExtension $extension */
4142
$extension = $container->getExtension('security');
43+
44+
if (method_exists($extension, 'addAuthenticatorFactory')) {
45+
$extension->addAuthenticatorFactory(new OAuth2Factory());
46+
47+
return;
48+
}
49+
50+
/**
51+
* @psalm-suppress DeprecatedMethod
52+
* @psalm-suppress InvalidArgument
53+
*/
4254
$extension->addSecurityListenerFactory(new OAuth2Factory());
4355
}
4456

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace League\Bundle\OAuth2ServerBundle\Security\Authenticator;
6+
7+
use Symfony\Component\HttpFoundation\Request;
8+
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
9+
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
10+
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
11+
12+
/** @var \ReflectionNamedType|null $r */
13+
$r = (new \ReflectionMethod(AuthenticatorInterface::class, 'authenticate'))->getReturnType();
14+
15+
if ($r && Passport::class === $r->getName()) {
16+
/**
17+
* @internal
18+
*
19+
* @psalm-suppress UnrecognizedStatement
20+
*/
21+
trait ForwardCompatAuthenticatorTrait
22+
{
23+
public function authenticate(Request $request): Passport
24+
{
25+
return $this->doAuthenticate($request);
26+
}
27+
}
28+
} else {
29+
/**
30+
* @internal
31+
*
32+
* @psalm-suppress UnrecognizedStatement
33+
*/
34+
trait ForwardCompatAuthenticatorTrait
35+
{
36+
public function authenticate(Request $request): PassportInterface
37+
{
38+
return $this->doAuthenticate($request);
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)