Skip to content

Commit fad0aec

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

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-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

+61
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,25 @@
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;
20+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
1721
use Symfony\Component\Routing\Loader\XmlFileLoader;
1822

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

0 commit comments

Comments
 (0)