Skip to content

Commit 49fe499

Browse files
committed
Allow multiline in supported_scopes option
1 parent 07f6471 commit 49fe499

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

DependencyInjection/FOSOAuthServerExtension.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ public function load(array $configs, ContainerBuilder $container)
5151
$container->setAlias('fos_oauth_server.user_provider', new Alias($config['service']['user_provider'], false));
5252
}
5353

54-
$container->setParameter('fos_oauth_server.server.options', $config['service']['options']);
54+
$options = $config['service']['options'];
55+
if (!empty($options['supported_scopes'])) {
56+
$options['supported_scopes'] = str_replace("\n", ' ', $options['supported_scopes']);
57+
}
58+
$container->setParameter('fos_oauth_server.server.options', $options);
5559

5660
$this->remapParametersNamespaces($config, $container, [
5761
'' => [

Tests/DependencyInjection/FOSOAuthServerExtensionTest.php

+60
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,24 @@
1313

1414
namespace FOS\OAuthServerBundle\Tests\DependencyInjection;
1515

16+
use FOS\OAuthServerBundle\DependencyInjection\FOSOAuthServerExtension;
1617
use Symfony\Component\Config\FileLocator;
18+
use Symfony\Component\DependencyInjection\ContainerBuilder;
19+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
1720
use Symfony\Component\Routing\Loader\XmlFileLoader;
1821

1922
class FOSOAuthServerExtensionTest extends \PHPUnit\Framework\TestCase
2023
{
24+
private $container;
25+
26+
public function setUp()
27+
{
28+
$parameterBag = new ParameterBag();
29+
$this->container = new ContainerBuilder($parameterBag);
30+
31+
parent::setUp();
32+
}
33+
2134
public function testLoadAuthorizeRouting()
2235
{
2336
$locator = new FileLocator();
@@ -39,4 +52,51 @@ public function testLoadTokenRouting()
3952
$this->assertSame('/oauth/v2/token', $tokenRoute->getPath());
4053
$this->assertSame(['GET', 'POST'], $tokenRoute->getMethods());
4154
}
55+
56+
public function testWithoutService()
57+
{
58+
$config = [
59+
'db_driver' => 'orm',
60+
'client_class' => 'dumb_class',
61+
'access_token_class' => 'dumb_access_token_class',
62+
'refresh_token_class' => 'dumb_refresh_token_class',
63+
'auth_code_class' => 'dumb_auth_code_class',
64+
];
65+
$instance = new FOSOAuthServerExtension();
66+
$instance->load([$config], $this->container);
67+
68+
$this->assertSame(
69+
$this->container->getParameter('fos_oauth_server.server.options'),
70+
[]
71+
);
72+
}
73+
74+
public function testMultilineScopes()
75+
{
76+
$scopes = <<<'SCOPES'
77+
scope1
78+
scope2
79+
scope3 scope4
80+
SCOPES;
81+
82+
$config = [
83+
'db_driver' => 'orm',
84+
'client_class' => 'dumb_class',
85+
'access_token_class' => 'dumb_access_token_class',
86+
'refresh_token_class' => 'dumb_refresh_token_class',
87+
'auth_code_class' => 'dumb_auth_code_class',
88+
'service' => [
89+
'options' => [
90+
'supported_scopes' => $scopes,
91+
],
92+
],
93+
];
94+
$instance = new FOSOAuthServerExtension();
95+
$instance->load([$config], $this->container);
96+
97+
$this->assertSame(
98+
$this->container->getParameter('fos_oauth_server.server.options'),
99+
['supported_scopes' => 'scope1 scope2 scope3 scope4']
100+
);
101+
}
42102
}

0 commit comments

Comments
 (0)