Skip to content

Commit 14b5096

Browse files
committed
add exception if supported_scopes mixes array notation and string notation
1 parent 45a4afe commit 14b5096

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

DependencyInjection/FOSOAuthServerExtension.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace FOS\OAuthServerBundle\DependencyInjection;
1515

1616
use FOS\OAuthServerBundle\Util\LegacyFormHelper;
17+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1718
use Symfony\Component\Config\Definition\Processor;
1819
use Symfony\Component\Config\FileLocator;
1920
use Symfony\Component\DependencyInjection\Alias;
@@ -53,7 +54,7 @@ public function load(array $configs, ContainerBuilder $container)
5354

5455
$options = $config['service']['options'];
5556
if (is_array($options['supported_scopes'] ?? null)) {
56-
$options['supported_scopes'] = implode(' ', $options['supported_scopes']);
57+
$options['supported_scopes'] = $this->computeArraySupportedScopes($options['supported_scopes']);
5758
}
5859
$container->setParameter('fos_oauth_server.server.options', $options);
5960

@@ -154,4 +155,15 @@ protected function loadAuthorize(array $config, ContainerBuilder $container, Xml
154155
'form' => 'fos_oauth_server.authorize.form.%s',
155156
]);
156157
}
158+
159+
private function computeArraySupportedScopes(array $supportedScopes)
160+
{
161+
foreach ($supportedScopes as $scope) {
162+
if (false !== strpos($scope, ' ')) {
163+
throw new InvalidConfigurationException('The array notation for supported_scopes should not contain spaces in array items. Either use full array notation or use the string notation for supported_scopes. See https://git.io/vx1X0 for more informations.');
164+
}
165+
}
166+
167+
return implode(' ', $supportedScopes);
168+
}
157169
}

Tests/DependencyInjection/FOSOAuthServerExtensionTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace FOS\OAuthServerBundle\Tests\DependencyInjection;
1515

1616
use FOS\OAuthServerBundle\DependencyInjection\FOSOAuthServerExtension;
17+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1718
use Symfony\Component\Config\FileLocator;
1819
use Symfony\Component\DependencyInjection\ContainerBuilder;
1920
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -127,4 +128,28 @@ public function testArraySupportedScopes()
127128
]
128129
);
129130
}
131+
132+
public function testArraySupportedScopesWithSpace()
133+
{
134+
$scopes = ['scope1 scope2', 'scope3', 'scope4'];
135+
136+
$config = [
137+
'db_driver' => 'orm',
138+
'client_class' => 'dumb_class',
139+
'access_token_class' => 'dumb_access_token_class',
140+
'refresh_token_class' => 'dumb_refresh_token_class',
141+
'auth_code_class' => 'dumb_auth_code_class',
142+
'service' => [
143+
'options' => [
144+
'supported_scopes' => $scopes,
145+
'enforce_redirect' => true,
146+
],
147+
],
148+
];
149+
$instance = new FOSOAuthServerExtension();
150+
151+
$this->expectException(InvalidConfigurationException::class);
152+
$this->expectExceptionMessage('The array notation for supported_scopes should not contain spaces in array items. Either use full array notation or use the string notation for supported_scopes. See https://git.io/vx1X0 for more informations.');
153+
$instance->load([$config], $this->container);
154+
}
130155
}

0 commit comments

Comments
 (0)