diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 85f21621..0bc7306e 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -521,6 +521,10 @@ private function createAuthenticationPluginNode() case 'wsse': $this->validateAuthenticationType(['username', 'password'], $config, 'wsse'); + break; + case 'query_param': + $this->validateAuthenticationType(['params'], $config, 'query_param'); + break; } @@ -529,7 +533,7 @@ private function createAuthenticationPluginNode() ->end() ->children() ->enumNode('type') - ->values(['basic', 'bearer', 'wsse', 'service']) + ->values(['basic', 'bearer', 'wsse', 'service', 'query_param']) ->isRequired() ->cannotBeEmpty() ->end() @@ -537,6 +541,7 @@ private function createAuthenticationPluginNode() ->scalarNode('password')->end() ->scalarNode('token')->end() ->scalarNode('service')->end() + ->arrayNode('params')->prototype('scalar')->end() ->end() ->end() ->end(); // End authentication plugin @@ -556,6 +561,10 @@ private function createAuthenticationPluginNode() private function validateAuthenticationType(array $expected, array $actual, $authName) { unset($actual['type']); + // Empty array is always provided, even if the config is not filled. + if (empty($actual['params'])) { + unset($actual['params']); + } $actual = array_keys($actual); sort($actual); sort($expected); diff --git a/DependencyInjection/HttplugExtension.php b/DependencyInjection/HttplugExtension.php index 261afefb..93977b1c 100644 --- a/DependencyInjection/HttplugExtension.php +++ b/DependencyInjection/HttplugExtension.php @@ -11,6 +11,7 @@ use Http\Client\HttpClient; use Http\Message\Authentication\BasicAuth; use Http\Message\Authentication\Bearer; +use Http\Message\Authentication\QueryParam; use Http\Message\Authentication\Wsse; use Http\Mock\Client as MockClient; use Psr\Http\Message\UriInterface; @@ -265,6 +266,11 @@ private function configureAuthentication(ContainerBuilder $container, array $con ->addArgument($values['username']) ->addArgument($values['password']); + break; + case 'query_param': + $container->register($authServiceKey, QueryParam::class) + ->addArgument($values['params']); + break; case 'service': $authServiceKey = $values['service']; diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php index 1d7e443f..a92b5ab8 100644 --- a/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -170,6 +170,7 @@ public function testSupportsAllConfigFormats() 'type' => 'basic', 'username' => 'foo', 'password' => 'bar', + 'params' => [], ], ], ], @@ -188,19 +189,23 @@ public function testSupportsAllConfigFormats() 'type' => 'basic', 'username' => 'foo', 'password' => 'bar', + 'params' => [], ], 'my_wsse' => [ 'type' => 'wsse', 'username' => 'foo', 'password' => 'bar', + 'params' => [], ], 'my_bearer' => [ 'type' => 'bearer', 'token' => 'foo', + 'params' => [], ], 'my_service' => [ 'type' => 'service', 'service' => 'my_auth_service', + 'params' => [], ], ], 'cache' => [