Skip to content

Commit ec01a67

Browse files
soullivaneuhNyholm
authored andcommitted
Add QueryParam auth plugin support (#267)
1 parent f1c0223 commit ec01a67

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

DependencyInjection/Configuration.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,10 @@ private function createAuthenticationPluginNode()
521521
case 'wsse':
522522
$this->validateAuthenticationType(['username', 'password'], $config, 'wsse');
523523

524+
break;
525+
case 'query_param':
526+
$this->validateAuthenticationType(['params'], $config, 'query_param');
527+
524528
break;
525529
}
526530

@@ -529,14 +533,15 @@ private function createAuthenticationPluginNode()
529533
->end()
530534
->children()
531535
->enumNode('type')
532-
->values(['basic', 'bearer', 'wsse', 'service'])
536+
->values(['basic', 'bearer', 'wsse', 'service', 'query_param'])
533537
->isRequired()
534538
->cannotBeEmpty()
535539
->end()
536540
->scalarNode('username')->end()
537541
->scalarNode('password')->end()
538542
->scalarNode('token')->end()
539543
->scalarNode('service')->end()
544+
->arrayNode('params')->prototype('scalar')->end()
540545
->end()
541546
->end()
542547
->end(); // End authentication plugin
@@ -556,6 +561,10 @@ private function createAuthenticationPluginNode()
556561
private function validateAuthenticationType(array $expected, array $actual, $authName)
557562
{
558563
unset($actual['type']);
564+
// Empty array is always provided, even if the config is not filled.
565+
if (empty($actual['params'])) {
566+
unset($actual['params']);
567+
}
559568
$actual = array_keys($actual);
560569
sort($actual);
561570
sort($expected);

DependencyInjection/HttplugExtension.php

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Http\Client\HttpClient;
1212
use Http\Message\Authentication\BasicAuth;
1313
use Http\Message\Authentication\Bearer;
14+
use Http\Message\Authentication\QueryParam;
1415
use Http\Message\Authentication\Wsse;
1516
use Http\Mock\Client as MockClient;
1617
use Psr\Http\Message\UriInterface;
@@ -265,6 +266,11 @@ private function configureAuthentication(ContainerBuilder $container, array $con
265266
->addArgument($values['username'])
266267
->addArgument($values['password']);
267268

269+
break;
270+
case 'query_param':
271+
$container->register($authServiceKey, QueryParam::class)
272+
->addArgument($values['params']);
273+
268274
break;
269275
case 'service':
270276
$authServiceKey = $values['service'];

Tests/Unit/DependencyInjection/ConfigurationTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public function testSupportsAllConfigFormats()
170170
'type' => 'basic',
171171
'username' => 'foo',
172172
'password' => 'bar',
173+
'params' => [],
173174
],
174175
],
175176
],
@@ -188,19 +189,23 @@ public function testSupportsAllConfigFormats()
188189
'type' => 'basic',
189190
'username' => 'foo',
190191
'password' => 'bar',
192+
'params' => [],
191193
],
192194
'my_wsse' => [
193195
'type' => 'wsse',
194196
'username' => 'foo',
195197
'password' => 'bar',
198+
'params' => [],
196199
],
197200
'my_bearer' => [
198201
'type' => 'bearer',
199202
'token' => 'foo',
203+
'params' => [],
200204
],
201205
'my_service' => [
202206
'type' => 'service',
203207
'service' => 'my_auth_service',
208+
'params' => [],
204209
],
205210
],
206211
'cache' => [

0 commit comments

Comments
 (0)