Skip to content

Commit fe81c0a

Browse files
committed
feature #24 Add support for authenticator security system (mtarld)
This PR was squashed before being merged into the 0.1-dev branch. Discussion ---------- Add support for authenticator security system - Added support for the authenticator security system - Updated OAuth2Token to not keep the whole request in token - Added `LegacyTestKernel` to test the old security system - Improved exception inheritance - Return a `NullUser` when user is not found (for old and new system to be consistent) - Removed support for Symfony < 5.1 Should we trigger deprecations when the bundle is used with the old security system? Commits ------- 8fad2ae Fix for php-cs-fixer 3 d5bc3f8 Drop support for legacy security system 5695774 Drop support for Symfony < 5.2 61d4c2f Drop support for Symfony < 5.1 61b7e38 Add support for authenticator security system
2 parents a654afe + 8fad2ae commit fe81c0a

35 files changed

+712
-603
lines changed

.github/workflows/unit-tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jobs:
1111
strategy:
1212
matrix:
1313
symfony-version:
14-
- "4.4.*"
1514
- "5.2.*"
1615
php-version:
1716
- "7.2"

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ composer.lock
33
vendor/
44

55
# PHP Coding Standards Fixer
6-
.php_cs
7-
.php_cs.cache
6+
.php-cs-fixer.php
7+
.php-cs-fixer.cache
88

99
# PHPUnit
1010
phpunit.xml

.php_cs.dist renamed to .php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
->append([__FILE__])
1010
;
1111

12-
return PhpCsFixer\Config::create()
12+
return (new PhpCsFixer\Config())
1313
->setUsingCache(true)
1414
->setRules([
1515
'@DoctrineAnnotation' => true,

.psalm.baseline.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<files psalm-version="4.7.1@cd53e047a58f71f646dd6bf45476076ab07b5d44">
3+
<file src="src/Resources/config/routes.php">
4+
<InvalidArgument occurrences="2">
5+
<code>['league.oauth2_server.controller.authorization', 'indexAction']</code>
6+
<code>['league.oauth2_server.controller.token', 'indexAction']</code>
7+
</InvalidArgument>
8+
</file>
9+
<file src="src/Resources/config/services.php">
10+
<ImplicitToStringCast occurrences="1">
11+
<code>service(GrantConfigurator::class)</code>
12+
</ImplicitToStringCast>
13+
</file>
14+
</files>

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
"league/oauth2-server": "^8.0",
2323
"nyholm/psr7": "^1.4",
2424
"psr/http-factory": "^1.0",
25-
"symfony/framework-bundle": "^4.4|^5.0",
25+
"symfony/framework-bundle": "^5.2",
2626
"symfony/psr-http-message-bridge": "^2.0",
27-
"symfony/security-bundle": "^4.4|^5.0"
27+
"symfony/security-bundle": "^5.2"
2828
},
2929
"require-dev": {
3030
"ext-pdo": "*",
3131
"ext-pdo_sqlite": "*",
3232
"psalm/plugin-symfony": "^2.2",
33-
"symfony/browser-kit": "^4.4|^5.0",
33+
"symfony/browser-kit": "^5.2",
3434
"symfony/phpunit-bridge": "^5.2",
3535
"vimeo/psalm": "^4.6"
3636
},

docs/basic-setup.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ Options:
9595
9696
## Configuring the Security layer
9797
98-
Add two new firewalls in your security configuration:
98+
Add two new firewalls in your security configuration and enable the authenticator security system:
9999
100100
```yaml
101101
security:
102+
enable_authenticator_manager: true
103+
102104
firewalls:
103105
api_token:
104106
pattern: ^/api/token$

docs/index.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ For implementation into Symfony projects, please see [bundle documentation](docs
1313
## Requirements
1414

1515
* [PHP 7.2](http://php.net/releases/7_2_0.php) or greater
16-
* [Symfony 4.4](https://symfony.com/roadmap/4.4) or [Symfony 5.x](https://symfony.com/roadmap/5.0)
16+
* [Symfony 5.2](https://symfony.com/roadmap/5.2) or greater
1717

1818
## Installation
1919

@@ -91,9 +91,6 @@ For implementation into Symfony projects, please see [bundle documentation](docs
9191
entity_manager: default
9292
in_memory: ~
9393
94-
# The priority of the event listener that converts an Exception to a Response
95-
exception_event_listener_priority: 10
96-
9794
# Set a custom prefix that replaces the default 'ROLE_OAUTH2_' role prefix
9895
role_prefix: ROLE_OAUTH2_
9996
```
@@ -110,6 +107,13 @@ For implementation into Symfony projects, please see [bundle documentation](docs
110107
bin/console doctrine:schema:update --force
111108
```
112109

110+
1. Enable the authenticator security system in `config/security.yaml` file:
111+
112+
```yaml
113+
security:
114+
enable_authenticator_manager: true
115+
```
116+
113117
1. Import the routes inside your `config/routes.yaml` file:
114118

115119
```yaml
@@ -121,7 +125,7 @@ You can verify that everything is working by issuing a `POST` request to the `/t
121125

122126
**❮ NOTE ❯** It is recommended to control the access to the authorization endpoint
123127
so that only logged in users can approve authorization requests.
124-
You should review your `security.yml` file. Here is a sample configuration:
128+
You should review your `config/security.yaml` file. Here is a sample configuration:
125129

126130
```yaml
127131
security:

psalm.xml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1212
xmlns="https://getpsalm.org/schema/config"
1313
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
14+
errorBaseline=".psalm.baseline.xml"
1415
>
1516
<projectFiles>
1617
<directory name="src"/>
@@ -44,27 +45,6 @@
4445
<RawObjectIteration errorLevel="error"/>
4546
<InvalidStringClass errorLevel="error"/>
4647
<UnresolvableInclude errorLevel="error"/>
47-
<ImplicitToStringCast errorLevel="error">
48-
<errorLevel type="suppress">
49-
<file name="src/Resources/config/services.php" />
50-
</errorLevel>
51-
</ImplicitToStringCast>
52-
<MixedInferredReturnType errorLevel="error">
53-
<errorLevel type="suppress">
54-
<file name="src/Resources/config/services.php" />
55-
</errorLevel>
56-
</MixedInferredReturnType>
57-
<MixedReturnStatement errorLevel="error">
58-
<errorLevel type="suppress">
59-
<file name="src/Resources/config/services.php" />
60-
</errorLevel>
61-
</MixedReturnStatement>
62-
<InvalidArgument errorLevel="error">
63-
<errorLevel type="suppress">
64-
<file name="src/Resources/config/routes.php" />
65-
<referencedFunction name="Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator::controller" />
66-
</errorLevel>
67-
</InvalidArgument>
6848
</issueHandlers>
6949

7050
<plugins>

src/DependencyInjection/Configuration.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ public function getConfigTreeBuilder(): TreeBuilder
2626

2727
$rootNode
2828
->children()
29-
->scalarNode('exception_event_listener_priority')
30-
->info('The priority of the event listener that converts an Exception to a Response')
31-
->defaultValue(10)
32-
->end()
3329
->scalarNode('role_prefix')
3430
->info('Set a custom prefix that replaces the default \'ROLE_OAUTH2_\' role prefix')
3531
->defaultValue('ROLE_OAUTH2_')

src/DependencyInjection/LeagueOAuth2ServerExtension.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
use League\Bundle\OAuth2ServerBundle\DBAL\Type\Grant as GrantType;
1010
use League\Bundle\OAuth2ServerBundle\DBAL\Type\RedirectUri as RedirectUriType;
1111
use League\Bundle\OAuth2ServerBundle\DBAL\Type\Scope as ScopeType;
12-
use League\Bundle\OAuth2ServerBundle\EventListener\ConvertExceptionToResponseListener;
1312
use League\Bundle\OAuth2ServerBundle\League\AuthorizationServer\GrantTypeInterface;
1413
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\AccessTokenManager;
1514
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\AuthorizationCodeManager;
1615
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\ClientManager;
1716
use League\Bundle\OAuth2ServerBundle\Manager\Doctrine\RefreshTokenManager;
1817
use League\Bundle\OAuth2ServerBundle\Manager\ScopeManagerInterface;
1918
use League\Bundle\OAuth2ServerBundle\Model\Scope as ScopeModel;
20-
use League\Bundle\OAuth2ServerBundle\Security\Authentication\Token\OAuth2TokenFactory;
19+
use League\Bundle\OAuth2ServerBundle\Security\Authenticator\OAuth2Authenticator;
2120
use League\Bundle\OAuth2ServerBundle\Service\CredentialsRevoker\DoctrineCredentialsRevoker;
2221
use League\OAuth2\Server\AuthorizationServer;
2322
use League\OAuth2\Server\CryptKey;
@@ -37,7 +36,6 @@
3736
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
3837
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
3938
use Symfony\Component\DependencyInjection\Reference;
40-
use Symfony\Component\HttpKernel\KernelEvents;
4139

4240
final class LeagueOAuth2ServerExtension extends Extension implements PrependExtensionInterface, CompilerPassInterface
4341
{
@@ -60,15 +58,8 @@ public function load(array $configs, ContainerBuilder $container)
6058
$this->configureResourceServer($container, $config['resource_server']);
6159
$this->configureScopes($container, $config['scopes']);
6260

63-
$container->findDefinition(OAuth2TokenFactory::class)
64-
->setArgument(0, $config['role_prefix']);
65-
66-
$container->findDefinition(ConvertExceptionToResponseListener::class)
67-
->addTag('kernel.event_listener', [
68-
'event' => KernelEvents::EXCEPTION,
69-
'method' => 'onKernelException',
70-
'priority' => $config['exception_event_listener_priority'],
71-
]);
61+
$container->findDefinition(OAuth2Authenticator::class)
62+
->setArgument(3, $config['role_prefix']);
7263

7364
$container->registerForAutoconfiguration(GrantTypeInterface::class)
7465
->addTag('league.oauth2_server.authorization_server.grant');

0 commit comments

Comments
 (0)