Skip to content

Add QueryParam auth plugin support #267

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 1 commit into from
Jul 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
11 changes: 10 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -529,14 +533,15 @@ private function createAuthenticationPluginNode()
->end()
->children()
->enumNode('type')
->values(['basic', 'bearer', 'wsse', 'service'])
->values(['basic', 'bearer', 'wsse', 'service', 'query_param'])
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode('username')->end()
->scalarNode('password')->end()
->scalarNode('token')->end()
->scalarNode('service')->end()
->arrayNode('params')->prototype('scalar')->end()
->end()
->end()
->end(); // End authentication plugin
Expand All @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'];
Expand Down
5 changes: 5 additions & 0 deletions Tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public function testSupportsAllConfigFormats()
'type' => 'basic',
'username' => 'foo',
'password' => 'bar',
'params' => [],
],
],
],
Expand All @@ -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' => [
Expand Down