Skip to content

Commit b87e59f

Browse files
committed
feat: header authentication service configuration
1 parent 57284fb commit b87e59f

File tree

8 files changed

+33
-2
lines changed

8 files changed

+33
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5+
- Added configuration for the `header` authentication plugin (#437).
6+
57
# 1.30.1 - 2023-09-07
68

79
- Added alias to allow autowiring the `AsyncHttpClient` interface (#436).

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"php-http/discovery": "^1.14",
3232
"php-http/httplug": "^2.0",
3333
"php-http/logger-plugin": "^1.1",
34-
"php-http/message": "^1.4",
34+
"php-http/message": "^1.9",
3535
"php-http/message-factory": "^1.0.2",
3636
"php-http/stopwatch-plugin": "^1.2",
3737
"psr/http-message": "^1.0 || ^2.0",

src/DependencyInjection/Configuration.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,10 @@ private function createAuthenticationPluginNode(): NodeDefinition
662662
case 'query_param':
663663
$this->validateAuthenticationType(['params'], $config, 'query_param');
664664

665+
break;
666+
case 'header':
667+
$this->validateAuthenticationType(['header_name', 'header_value'], $config, 'header');
668+
665669
break;
666670
}
667671

@@ -670,14 +674,16 @@ private function createAuthenticationPluginNode(): NodeDefinition
670674
->end()
671675
->children()
672676
->enumNode('type')
673-
->values(['basic', 'bearer', 'wsse', 'service', 'query_param'])
677+
->values(['basic', 'bearer', 'wsse', 'service', 'query_param', 'header'])
674678
->isRequired()
675679
->cannotBeEmpty()
676680
->end()
677681
->scalarNode('username')->end()
678682
->scalarNode('password')->end()
679683
->scalarNode('token')->end()
680684
->scalarNode('service')->end()
685+
->scalarNode('header_name')->end()
686+
->scalarNode('header_value')->end()
681687
->arrayNode('params')->prototype('scalar')->end()
682688
->end()
683689
->end()

src/DependencyInjection/HttplugExtension.php

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Http\Client\Plugin\Vcr\ReplayPlugin;
1919
use Http\Message\Authentication\BasicAuth;
2020
use Http\Message\Authentication\Bearer;
21+
use Http\Message\Authentication\Header;
2122
use Http\Message\Authentication\QueryParam;
2223
use Http\Message\Authentication\Wsse;
2324
use Http\Mock\Client as MockClient;
@@ -380,6 +381,12 @@ private function configureAuthentication(ContainerBuilder $container, array $con
380381
$container->register($authServiceKey, QueryParam::class)
381382
->addArgument($values['params']);
382383

384+
break;
385+
case 'header':
386+
$container->register($authServiceKey, Header::class)
387+
->addArgument($values['header_name'])
388+
->addArgument($values['header_value']);
389+
383390
break;
384391
case 'service':
385392
$authServiceKey = $values['service'];

tests/Resources/Fixtures/config/full.php

+5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696
'type' => 'bearer',
9797
'token' => 'foo',
9898
],
99+
'my_header' => [
100+
'type' => 'header',
101+
'header_name' => 'foo',
102+
'header_value' => 'bar',
103+
],
99104
'my_service' => [
100105
'type' => 'service',
101106
'service' => 'my_auth_service',

tests/Resources/Fixtures/config/full.xml

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<my_basic type="basic" username="foo" password="bar"/>
5959
<my_wsse type="wsse" username="foo" password="bar"/>
6060
<my_bearer type="bearer" token="foo"/>
61+
<my_header type="header" header_name="foo" header_value="bar" />
6162
<my_service type="service" service="my_auth_service"/>
6263
</authentication>
6364
<cache cache-pool="my_cache_pool" stream-factory="my_other_stream_factory">

tests/Resources/Fixtures/config/full.yml

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ httplug:
6565
my_bearer:
6666
type: bearer
6767
token: foo
68+
my_header:
69+
type: header
70+
header_name: foo
71+
header_value: bar
6872
my_service:
6973
type: service
7074
service: my_auth_service

tests/Unit/DependencyInjection/ConfigurationTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ public function testSupportsAllConfigFormats(): void
244244
'token' => 'foo',
245245
'params' => [],
246246
],
247+
'my_header' => [
248+
'type' => 'header',
249+
'header_name' => 'foo',
250+
'header_value' => 'bar',
251+
'params' => [],
252+
],
247253
'my_service' => [
248254
'type' => 'service',
249255
'service' => 'my_auth_service',

0 commit comments

Comments
 (0)