Skip to content

Commit 78ce9a6

Browse files
committed
Merge branch '1.6' into merge-1.6
# Conflicts: # .travis.yml # Command/CleanCommand.php # Command/CreateClientCommand.php # Controller/AuthorizeController.php # DependencyInjection/Configuration.php # DependencyInjection/FOSOAuthServerExtension.php # Security/Authentication/Provider/OAuthProvider.php # Security/EntryPoint/OAuthEntryPoint.php # Storage/OAuthStorage.php # Tests/Command/CleanCommandTest.php # Tests/Command/CreateClientCommandTest.php # Tests/Controller/AuthorizeControllerTest.php # Tests/DependencyInjection/FOSOAuthServerExtensionTest.php # Tests/Functional/BootTest.php # composer.json
2 parents fe3e2b5 + a038aa7 commit 78ce9a6

26 files changed

+497
-134
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ matrix:
1313
fast_finish: true
1414
include:
1515
- php: 7.1
16-
env: SYMFONY_VERSION=3.0.*
16+
env: SYMFONY_VERSION=3.4.*
1717
- php: 7.2
1818
env: SYMFONY_VERSION=4.0.*
1919
- php: 7.2

Command/CleanCommand.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,35 @@
1515

1616
use FOS\OAuthServerBundle\Model\AuthCodeManagerInterface;
1717
use FOS\OAuthServerBundle\Model\TokenManagerInterface;
18-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
18+
use Symfony\Component\Console\Command\Command;
1919
use Symfony\Component\Console\Input\InputInterface;
2020
use Symfony\Component\Console\Output\OutputInterface;
2121

22-
class CleanCommand extends ContainerAwareCommand
22+
class CleanCommand extends Command
2323
{
24+
private $accessTokenManager;
25+
private $refreshTokenManager;
26+
private $authCodeManager;
27+
28+
public function __construct(
29+
TokenManagerInterface $accessTokenManager,
30+
TokenManagerInterface $refreshTokenManager,
31+
AuthCodeManagerInterface $authCodeManager)
32+
{
33+
parent::__construct();
34+
35+
$this->accessTokenManager = $accessTokenManager;
36+
$this->refreshTokenManager = $refreshTokenManager;
37+
$this->authCodeManager = $authCodeManager;
38+
}
39+
2440
/**
2541
* {@inheritdoc}
2642
*/
2743
protected function configure()
2844
{
45+
parent::configure();
46+
2947
$this
3048
->setName('fos:oauth-server:clean')
3149
->setDescription('Clean expired tokens')
@@ -43,19 +61,9 @@ protected function configure()
4361
*/
4462
protected function execute(InputInterface $input, OutputInterface $output)
4563
{
46-
$services = [
47-
'fos_oauth_server.access_token_manager' => 'Access token',
48-
'fos_oauth_server.refresh_token_manager' => 'Refresh token',
49-
'fos_oauth_server.auth_code_manager' => 'Auth code',
50-
];
51-
52-
foreach ($services as $service => $name) {
53-
/** @var TokenManagerInterface $instance */
54-
$instance = $this->getContainer()->get($service);
55-
if ($instance instanceof TokenManagerInterface || $instance instanceof AuthCodeManagerInterface) {
56-
$result = $instance->deleteExpired();
57-
$output->writeln(sprintf('Removed <info>%d</info> items from <comment>%s</comment> storage.', $result, $name));
58-
}
64+
foreach ([$this->accessTokenManager, $this->refreshTokenManager, $this->authCodeManager] as $service) {
65+
$result = $service->deleteExpired();
66+
$output->writeln(sprintf('Removed <info>%d</info> items from <comment>%s</comment> storage.', $result, get_class($service)));
5967
}
6068
}
6169
}

Command/CreateClientCommand.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,32 @@
1313

1414
namespace FOS\OAuthServerBundle\Command;
1515

16+
use Symfony\Component\Console\Command\Command;
1617
use FOS\OAuthServerBundle\Model\ClientManagerInterface;
1718
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
1819
use Symfony\Component\Console\Input\InputInterface;
1920
use Symfony\Component\Console\Input\InputOption;
2021
use Symfony\Component\Console\Output\OutputInterface;
2122
use Symfony\Component\Console\Style\SymfonyStyle;
2223

23-
class CreateClientCommand extends ContainerAwareCommand
24+
class CreateClientCommand extends Command
2425
{
26+
private $clientManager;
27+
28+
public function __construct(ClientManagerInterface $clientManager)
29+
{
30+
parent::__construct();
31+
32+
$this->clientManager = $clientManager;
33+
}
34+
2535
/**
2636
* {@inheritdoc}
2737
*/
2838
protected function configure()
2939
{
40+
parent::configure();
41+
3042
$this
3143
->setName('fos:oauth-server:create-client')
3244
->setDescription('Creates a new client')
@@ -63,18 +75,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
6375

6476
$io->title('Client Credentials');
6577

66-
// Get the client manager
67-
/** @var ClientManagerInterface $clientManager */
68-
$clientManager = $this->getContainer()->get('fos_oauth_server.client_manager.default');
69-
7078
// Create a new client
71-
$client = $clientManager->createClient();
79+
$client = $this->clientManager->createClient();
7280

7381
$client->setRedirectUris($input->getOption('redirect-uri'));
7482
$client->setAllowedGrantTypes($input->getOption('grant-type'));
7583

7684
// Save the client
77-
$clientManager->updateClient($client);
85+
$this->clientManager->updateClient($client);
7886

7987
// Give the credentials back to the user
8088
$headers = ['Client ID', 'Client Secret'];

Controller/AuthorizeController.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
2424
use Symfony\Component\DependencyInjection\ContainerInterface;
2525
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
26+
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
27+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2628
use Symfony\Component\Form\Form;
2729
use Symfony\Component\HttpFoundation\Request;
2830
use Symfony\Component\HttpFoundation\RequestStack;
@@ -39,7 +41,7 @@
3941
*
4042
* @author Chris Jones <[email protected]>
4143
*/
42-
class AuthorizeController implements ContainerAwareInterface
44+
class AuthorizeController
4345
{
4446
/**
4547
* @var ContainerInterface
@@ -107,25 +109,23 @@ class AuthorizeController implements ContainerAwareInterface
107109

108110
/**
109111
* This controller had been made as a service due to support symfony 4 where all* services are private by default.
110-
* Thus, there is considered a bad practice to fetch services directly from container.
112+
* Thus, this is considered a bad practice to fetch services directly from container.
111113
*
112-
* @todo This controller could be refactored to do not rely on so many dependencies
114+
* @todo This controller could be refactored to not rely on so many dependencies
113115
*
114-
* @param RequestStack $requestStack
115-
* @param SessionInterface $session
116-
* @param Form $authorizeForm
117-
* @param AuthorizeFormHandler $authorizeFormHandler
118-
* @param OAuth2 $oAuth2Server
119-
* @param EngineInterface $templating
120-
* @param TokenStorageInterface $tokenStorage
121-
* @param UrlGeneratorInterface $router
122-
* @param ClientManagerInterface $clientManager
123-
* @param EventDispatcherInterface $eventDispatcher
124-
* @param string $templateEngineType
116+
* @param RequestStack $requestStack
117+
* @param Form $authorizeForm
118+
* @param AuthorizeFormHandler $authorizeFormHandler
119+
* @param OAuth2 $oAuth2Server
120+
* @param EngineInterface $templating
121+
* @param TokenStorageInterface $tokenStorage
122+
* @param UrlGeneratorInterface $router
123+
* @param ClientManagerInterface $clientManager
124+
* @param EventDispatcherInterface $eventDispatcher* @param SessionInterface $session
125+
* @param string $templateEngineType
125126
*/
126127
public function __construct(
127128
RequestStack $requestStack,
128-
SessionInterface $session,
129129
Form $authorizeForm,
130130
AuthorizeFormHandler $authorizeFormHandler,
131131
OAuth2 $oAuth2Server,
@@ -134,6 +134,7 @@ public function __construct(
134134
UrlGeneratorInterface $router,
135135
ClientManagerInterface $clientManager,
136136
EventDispatcherInterface $eventDispatcher,
137+
SessionInterface $session = null,
137138
$templateEngineType = 'twig'
138139
) {
139140
$this->requestStack = $requestStack;
@@ -170,7 +171,7 @@ public function authorizeAction(Request $request)
170171
throw new AccessDeniedException('This user does not have access to this section.');
171172
}
172173

173-
if (true === $this->session->get('_fos_oauth_server.ensure_logout')) {
174+
if ($this->session && true === $this->session->get('_fos_oauth_server.ensure_logout')) {
174175
$this->session->invalidate(600);
175176
$this->session->set('_fos_oauth_server.ensure_logout', true);
176177
}
@@ -211,7 +212,7 @@ public function authorizeAction(Request $request)
211212
*/
212213
protected function processSuccess(UserInterface $user, AuthorizeFormHandler $formHandler, Request $request)
213214
{
214-
if (true === $this->session->get('_fos_oauth_server.ensure_logout')) {
215+
if ($this->session && true === $this->session->get('_fos_oauth_server.ensure_logout')) {
215216
$this->tokenStorage->setToken(null);
216217
$this->session->invalidate();
217218
}

DependencyInjection/Configuration.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,34 @@ public function getConfigTreeBuilder()
3434
/** @var ArrayNodeDefinition $rootNode */
3535
$rootNode = $treeBuilder->root('fos_oauth_server');
3636

37-
$supportedDrivers = ['orm', 'mongodb', 'propel'];
37+
$supportedDrivers = ['orm', 'mongodb', 'propel', 'custom'];
3838

3939
$rootNode
40+
->validate()
41+
->always(function($v) {
42+
if ('custom' !== $v['db_driver']) {
43+
return $v;
44+
}
45+
46+
if (empty($v['service']['client_manager']) || $v['service']['client_manager'] === 'fos_oauth_server.client_manager.default') {
47+
throw new \InvalidArgumentException('The service client_manager must be set explicitly for custom db_driver.');
48+
}
49+
50+
if (empty($v['service']['access_token_manager']) || $v['service']['access_token_manager'] === 'fos_oauth_server.access_token_manager.default') {
51+
throw new \InvalidArgumentException('The service access_token_manager must be set explicitly for custom db_driver.');
52+
}
53+
54+
if (empty($v['service']['refresh_token_manager']) || $v['service']['refresh_token_manager'] === 'fos_oauth_server.refresh_token_manager.default') {
55+
throw new \InvalidArgumentException('The service refresh_token_manager must be set explicitly for custom db_driver.');
56+
}
57+
58+
if (empty($v['service']['auth_code_manager']) || $v['service']['auth_code_manager'] === 'fos_oauth_server.auth_code_manager.default') {
59+
throw new \InvalidArgumentException('The service auth_code_manager must be set explicitly for custom db_driver.');
60+
}
61+
62+
return $v;
63+
})
64+
->end()
4065
->children()
4166
->scalarNode('db_driver')
4267
->validate()

DependencyInjection/FOSOAuthServerExtension.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public function load(array $configs, ContainerBuilder $container)
3636
$config = $processor->processConfiguration($configuration, $configs);
3737

3838
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
39-
$loader->load(sprintf('%s.xml', $config['db_driver']));
39+
40+
if ('custom' !== $config['db_driver']) {
41+
$loader->load(sprintf('%s.xml', $config['db_driver']));
42+
}
4043

4144
foreach (['oauth', 'security'] as $basename) {
4245
$loader->load(sprintf('%s.xml', $basename));
@@ -92,12 +95,12 @@ public function load(array $configs, ContainerBuilder $container)
9295

9396
if (!empty($config['authorize'])) {
9497
$this->loadAuthorize($config['authorize'], $container, $loader);
95-
}
9698

97-
// Authorize form factory definition
98-
// TODO: Go back to xml configuration when bumping the requirement to Symfony >=2.6
99-
$authorizeFormDefinition = $container->getDefinition('fos_oauth_server.authorize.form');
100-
$authorizeFormDefinition->setFactory([new Reference('form.factory'), 'createNamed']);
99+
// Authorize form factory definition
100+
// TODO: Go back to xml configuration when bumping the requirement to Symfony >=2.6
101+
$authorizeFormDefinition = $container->getDefinition('fos_oauth_server.authorize.form');
102+
$authorizeFormDefinition->setFactory([new Reference('form.factory'), 'createNamed']);
103+
}
101104
}
102105

103106
/**

Resources/config/authorize.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
<service id="fos_oauth_server.controller.authorize" class="FOS\OAuthServerBundle\Controller\AuthorizeController" public="true">
2727
<argument type="service" id="request_stack" />
28-
<argument type="service" id="session" />
2928
<argument type="service" id="fos_oauth_server.authorize.form" />
3029
<argument type="service" id="fos_oauth_server.authorize.form.handler" />
3130
<argument type="service" id="fos_oauth_server.server" />
@@ -34,6 +33,7 @@
3433
<argument type="service" id="router" />
3534
<argument type="service" id="fos_oauth_server.client_manager" />
3635
<argument type="service" id="event_dispatcher" />
36+
<argument type="service" id="session" on-invalid="null" />
3737
<argument>%fos_oauth_server.template.engine%</argument>
3838
</service>
3939
</services>

Resources/config/couchdb.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
<service id="fos_user.document_manager" factory-service="doctrine_couchdb" factory-method="getObjectManager" class="Doctrine\ODM\CouchDB\DocumentManager" public="false">
2929
<argument>%fos_oauth_server.model_manager_name%</argument>
3030
</service>
31+
32+
<service id="FOS\OAuthServerBundle\Model\ClientManagerInterface" alias="fos_oauth_server.client_manager.default" />
33+
<service id="FOS\OAuthServerBundle\Model\AccessTokenManagerInterface" alias="fos_oauth_server.access_token_manager.default" />
34+
<service id="FOS\OAuthServerBundle\Model\RefreshTokenManagerInterface" alias="fos_oauth_server.refresh_token_manager.default" />
35+
<service id="FOS\OAuthServerBundle\Model\AuthCodeManagerInterface" alias="fos_oauth_server.auth_code_manager.default" />
3136
</services>
3237

3338
</container>

Resources/config/mongodb.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
<argument type="service" id="fos_oauth_server.document_manager" />
2525
<argument>%fos_oauth_server.model.refresh_token.class%</argument>
2626
</service>
27+
28+
<service id="FOS\OAuthServerBundle\Model\ClientManagerInterface" alias="fos_oauth_server.client_manager.default" />
29+
<service id="FOS\OAuthServerBundle\Model\AccessTokenManagerInterface" alias="fos_oauth_server.access_token_manager.default" />
30+
<service id="FOS\OAuthServerBundle\Model\RefreshTokenManagerInterface" alias="fos_oauth_server.refresh_token_manager.default" />
31+
<service id="FOS\OAuthServerBundle\Model\AuthCodeManagerInterface" alias="fos_oauth_server.auth_code_manager.default" />
2732
</services>
2833

2934
</container>

Resources/config/oauth.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,22 @@
2323
<argument>%fos_oauth_server.server.options%</argument>
2424
</service>
2525

26-
<service id="FOS\OAuthServerBundle\Controller\TokenController">
26+
<service id="FOS\OAuthServerBundle\Controller\TokenController" class="FOS\OAuthServerBundle\Controller\TokenController">
2727
<argument type="service" id="fos_oauth_server.server" />
2828
</service>
29+
2930
<service id="fos_oauth_server.controller.token" alias="FOS\OAuthServerBundle\Controller\TokenController" public="true" />
31+
32+
<service id="fos_oauth_server.clean_command" class="FOS\OAuthServerBundle\Command\CleanCommand">
33+
<argument type="service" id="fos_oauth_server.access_token_manager" />
34+
<argument type="service" id="fos_oauth_server.refresh_token_manager" />
35+
<argument type="service" id="fos_oauth_server.auth_code_manager" />
36+
<tag name="console.command" />
37+
</service>
38+
39+
<service id="fos_oauth_server.create_client_command" class="FOS\OAuthServerBundle\Command\CreateClientCommand">
40+
<argument type="service" id="fos_oauth_server.client_manager" />
41+
<tag name="console.command" />
42+
</service>
3043
</services>
3144
</container>

0 commit comments

Comments
 (0)