Skip to content

The authorize form should be used only if authorize option true. #554

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

Merged
merged 2 commits into from
Apr 5, 2018
Merged
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
18 changes: 9 additions & 9 deletions DependencyInjection/FOSOAuthServerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ public function load(array $configs, ContainerBuilder $container)

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

// Authorize form factory definition
// TODO: Go back to xml configuration when bumping the requirement to Symfony >=2.6
$authorizeFormDefinition = $container->getDefinition('fos_oauth_server.authorize.form');
if (method_exists($authorizeFormDefinition, 'setFactory')) {
$authorizeFormDefinition->setFactory(array(new Reference('form.factory'), 'createNamed'));
} else {
$authorizeFormDefinition->setFactoryService('form.factory');
$authorizeFormDefinition->setFactoryMethod('createNamed');
// Authorize form factory definition
// TODO: Go back to xml configuration when bumping the requirement to Symfony >=2.6
$authorizeFormDefinition = $container->getDefinition('fos_oauth_server.authorize.form');
if (method_exists($authorizeFormDefinition, 'setFactory')) {
$authorizeFormDefinition->setFactory(array(new Reference('form.factory'), 'createNamed'));
} else {
$authorizeFormDefinition->setFactoryService('form.factory');
$authorizeFormDefinition->setFactoryMethod('createNamed');
}
}
}

Expand Down
55 changes: 55 additions & 0 deletions Tests/DependencyInjection/FOSOAuthServerExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,66 @@

namespace DependencyInjection;

use FOS\OAuthServerBundle\DependencyInjection\FOSOAuthServerExtension;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\Routing\Loader\XmlFileLoader;

class FOSOAuthServerExtensionTest extends \PHPUnit_Framework_TestCase
{
public function testShouldImplementConfigurationInterface()
{
$rc = new \ReflectionClass(FOSOAuthServerExtension::class);

$this->assertTrue($rc->isSubclassOf(Extension::class));
}

public function testCouldBeConstructedWithoutAnyArguments()
{
new FOSOAuthServerExtension();
}

public function testShouldLoadAuthorizeRelatedServicesIfAuthorizationIsEnabled()
{
$container = new ContainerBuilder();

$extension = new FOSOAuthServerExtension();
$extension->load([[
'db_driver' => 'orm',
'client_class' => 'aClientClass',
'access_token_class' => 'anAccessTokenClass',
'refresh_token_class' => 'aRefreshTokenClass',
'auth_code_class' => 'anAuthCodeClass',
'authorize' => true,
]], $container);

$this->assertTrue($container->hasDefinition('fos_oauth_server.authorize.form'));
$this->assertTrue($container->hasDefinition('fos_oauth_server.authorize.form.type'));
$this->assertTrue($container->hasDefinition('fos_oauth_server.authorize.form.handler.default'));
$this->assertTrue($container->hasDefinition('fos_oauth_server.controller.authorize'));
}

public function testShouldNotLoadAuthorizeRelatedServicesIfAuthorizationIsDisabled()
{
$container = new ContainerBuilder();

$extension = new FOSOAuthServerExtension();
$extension->load([[
'db_driver' => 'orm',
'client_class' => 'aClientClass',
'access_token_class' => 'anAccessTokenClass',
'refresh_token_class' => 'aRefreshTokenClass',
'auth_code_class' => 'anAuthCodeClass',
'authorize' => false,
]], $container);

$this->assertFalse($container->hasDefinition('fos_oauth_server.authorize.form'));
$this->assertFalse($container->hasDefinition('fos_oauth_server.authorize.form.type'));
$this->assertFalse($container->hasDefinition('fos_oauth_server.authorize.form.handler.default'));
$this->assertFalse($container->hasDefinition('fos_oauth_server.controller.authorize'));
}

public function testLoadAuthorizeRouting()
{
$locator = new FileLocator();
Expand Down