Skip to content
Open
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
5 changes: 5 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ jobs:
doctrine-orm: "^2.14"
composer-flags: '--prefer-stable --prefer-lowest'
can-fail: false
- php: "8.4"
symfony: "8.0.*"
doctrine-orm: "^3.0"
composer-flags: ''
can-fail: true
exclude:
- php: "8.1"
symfony: "7.1.*"
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
"nyholm/psr7": "^1.4",
"psr/http-factory": "^1.0",
"symfony/deprecation-contracts": "^3",
"symfony/event-dispatcher": "^6.4|^7.0",
"symfony/filesystem": "^6.4|^7.0",
"symfony/framework-bundle": "^6.4|^7.0",
"symfony/psr-http-message-bridge": "^6.4|^7",
"symfony/security-bundle": "^6.4|^7.0"
"symfony/event-dispatcher": "^6.4|^7.0|^8.0",
"symfony/filesystem": "^6.4|^7.0|^8.0",
"symfony/framework-bundle": "^6.4|^7.0|^8.0",
"symfony/psr-http-message-bridge": "^6.4|^7.0|^8.0",
"symfony/security-bundle": "^6.4|^7.0|^8.0"
},
"require-dev": {
"ext-pdo": "*",
"ext-pdo_sqlite": "*",
"doctrine/doctrine-bundle": "^2.8.0",
"doctrine/doctrine-bundle": "^2.8|^3.0",
"doctrine/orm": "^2.14|^3.0",
"symfony/browser-kit": "^6.4|^7.0",
"symfony/phpunit-bridge": "^7.2"
"symfony/browser-kit": "^6.4|^7.0|^8.0",
"symfony/phpunit-bridge": "^7.3"
},
"conflict": {
"doctrine/doctrine-bundle": "<2.8.0",
Expand Down
14 changes: 3 additions & 11 deletions src/DependencyInjection/LeagueOAuth2ServerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@
final class LeagueOAuth2ServerExtension extends Extension implements PrependExtensionInterface, CompilerPassInterface
{
/**
* @return void
*
* @throws \Exception
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
$loader->load('services.php');
Expand Down Expand Up @@ -90,10 +88,7 @@ public function getAlias(): string
return 'league_oauth2_server';
}

/**
* @return void
*/
public function prepend(ContainerBuilder $container)
public function prepend(ContainerBuilder $container): void
{
// If no doctrine connection is configured, the DBAL connection should
// be left alone as adding any configuration setting with no connection
Expand All @@ -114,10 +109,7 @@ public function prepend(ContainerBuilder $container)
]);
}

/**
* @return void
*/
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
$this->assertRequiredBundlesAreEnabled($container);
}
Expand Down
5 changes: 1 addition & 4 deletions src/LeagueOAuth2ServerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

final class LeagueOAuth2ServerBundle extends Bundle
{
/**
* @return void
*/
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

Expand Down
15 changes: 14 additions & 1 deletion src/Security/Authenticator/OAuth2Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\AttributesBasedUserProviderInterface;
use Symfony\Component\Security\Core\User\ChainUserProvider;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
Expand Down Expand Up @@ -70,6 +72,14 @@ public function authenticate(Request $request): Passport

/** @var string $userIdentifier */
$userIdentifier = $psr7Request->getAttribute('oauth_user_id', '');
if ('' === $userIdentifier) {
/**
* BC layer for Symfony < 8.0
*/
if (is_a(ChainUserProvider::class, AttributesBasedUserProviderInterface::class, true)) {
throw OAuth2AuthenticationFailedException::create('The access token has either an empty or missing "oauth_user_id" attribute.');
}
}

/** @var string $accessTokenId */
$accessTokenId = $psr7Request->getAttribute('oauth_access_token_id');
Expand All @@ -81,7 +91,10 @@ public function authenticate(Request $request): Passport
$oauthClientId = $psr7Request->getAttribute('oauth_client_id', '');

$userLoader = function (string $userIdentifier) use ($oauthClientId): UserInterface {
if ('' === $userIdentifier || $oauthClientId === $userIdentifier) {
if (
$oauthClientId === $userIdentifier
|| ('' === $userIdentifier && is_a(ChainUserProvider::class, AttributesBasedUserProviderInterface::class, true)) // BC layer for Symfony < 8.0
) {
return new ClientCredentialsUser($oauthClientId);
}

Expand Down
4 changes: 1 addition & 3 deletions tests/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace League\Bundle\OAuth2ServerBundle\Tests;

use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\ORM\Mapping\Annotation;
use League\Bundle\OAuth2ServerBundle\Manager\AccessTokenManagerInterface;
use League\Bundle\OAuth2ServerBundle\Manager\AuthorizationCodeManagerInterface;
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
Expand Down Expand Up @@ -90,8 +89,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
],
];

$doctrine['orm'] = ['enable_lazy_ghost_objects' => !interface_exists(Annotation::class)];

$doctrine['orm'] = [];
$container->loadFromExtension('doctrine', $doctrine);

$framework = [
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/OAuth2AuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public function testAuthenticateCreatePassportWithClientCredentialsUser(): void
{
$serverRequest = (new ServerRequest('GET', '/foo'))
->withAttribute('oauth_access_token_id', 'accessTokenId')
->withAttribute('oauth_user_id', 'clientId')
->withAttribute('oauth_client_id', 'clientId')
;

$httpMessageFactory = $this->createMock(HttpMessageFactoryInterface::class);
Expand Down