Skip to content

Commit

Permalink
feat: header authentication service configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
soullivaneuh committed Oct 31, 2023
1 parent 57284fb commit e484090
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

- Added configuration for the `header` authentication plugin (#437).

# 1.30.1 - 2023-09-07

- Added alias to allow autowiring the `AsyncHttpClient` interface (#436).
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"php-http/discovery": "^1.14",
"php-http/httplug": "^2.0",
"php-http/logger-plugin": "^1.1",
"php-http/message": "^1.4",
"php-http/message": "^1.9",
"php-http/message-factory": "^1.0.2",
"php-http/stopwatch-plugin": "^1.2",
"psr/http-message": "^1.0 || ^2.0",
Expand Down
8 changes: 7 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,10 @@ private function createAuthenticationPluginNode(): NodeDefinition
case 'query_param':
$this->validateAuthenticationType(['params'], $config, 'query_param');

break;
case 'header':
$this->validateAuthenticationType(['key', 'value'], $config, 'header');

break;
}

Expand All @@ -670,14 +674,16 @@ private function createAuthenticationPluginNode(): NodeDefinition
->end()
->children()
->enumNode('type')
->values(['basic', 'bearer', 'wsse', 'service', 'query_param'])
->values(['basic', 'bearer', 'wsse', 'service', 'query_param', 'header'])
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode('username')->end()
->scalarNode('password')->end()
->scalarNode('token')->end()
->scalarNode('service')->end()
->scalarNode('key')->end()
->scalarNode('value')->end()
->arrayNode('params')->prototype('scalar')->end()
->end()
->end()
Expand Down
7 changes: 7 additions & 0 deletions src/DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Http\Client\Plugin\Vcr\ReplayPlugin;
use Http\Message\Authentication\BasicAuth;
use Http\Message\Authentication\Bearer;
use Http\Message\Authentication\Header;
use Http\Message\Authentication\QueryParam;
use Http\Message\Authentication\Wsse;
use Http\Mock\Client as MockClient;
Expand Down Expand Up @@ -380,6 +381,12 @@ private function configureAuthentication(ContainerBuilder $container, array $con
$container->register($authServiceKey, QueryParam::class)
->addArgument($values['params']);

break;
case 'header':
$container->register($authServiceKey, Header::class)
->addArgument($values['key'])
->addArgument($values['value']);

break;
case 'service':
$authServiceKey = $values['service'];
Expand Down
5 changes: 5 additions & 0 deletions tests/Resources/Fixtures/config/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
'type' => 'bearer',
'token' => 'foo',
],
'my_header' => [
'type' => 'header',
'key' => 'foo',
'value' => 'bar',
],
'my_service' => [
'type' => 'service',
'service' => 'my_auth_service',
Expand Down
1 change: 1 addition & 0 deletions tests/Resources/Fixtures/config/full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<my_basic type="basic" username="foo" password="bar"/>
<my_wsse type="wsse" username="foo" password="bar"/>
<my_bearer type="bearer" token="foo"/>
<my_header type="header" key="foo" value="bar" />
<my_service type="service" service="my_auth_service"/>
</authentication>
<cache cache-pool="my_cache_pool" stream-factory="my_other_stream_factory">
Expand Down
4 changes: 4 additions & 0 deletions tests/Resources/Fixtures/config/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ httplug:
my_bearer:
type: bearer
token: foo
my_header:
type: header
key: foo
value: bar
my_service:
type: service
service: my_auth_service
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ public function testSupportsAllConfigFormats(): void
'token' => 'foo',
'params' => [],
],
'my_header' => [
'type' => 'header',
'key' => 'foo',
'value' => 'bar',
'params' => [],
],
'my_service' => [
'type' => 'service',
'service' => 'my_auth_service',
Expand Down

0 comments on commit e484090

Please sign in to comment.