From b87e59ff5359efc86649f38846a7aae2ccfdd82b Mon Sep 17 00:00:00 2001 From: Sullivan SENECHAL Date: Tue, 31 Oct 2023 17:04:22 +0100 Subject: [PATCH] feat: header authentication service configuration --- CHANGELOG.md | 2 ++ composer.json | 2 +- src/DependencyInjection/Configuration.php | 8 +++++++- src/DependencyInjection/HttplugExtension.php | 7 +++++++ tests/Resources/Fixtures/config/full.php | 5 +++++ tests/Resources/Fixtures/config/full.xml | 1 + tests/Resources/Fixtures/config/full.yml | 4 ++++ tests/Unit/DependencyInjection/ConfigurationTest.php | 6 ++++++ 8 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91553b95..d8dc34b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/composer.json b/composer.json index fbfa2b4e..2a7a03d4 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index ab6263df..12ec833d 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -662,6 +662,10 @@ private function createAuthenticationPluginNode(): NodeDefinition case 'query_param': $this->validateAuthenticationType(['params'], $config, 'query_param'); + break; + case 'header': + $this->validateAuthenticationType(['header_name', 'header_value'], $config, 'header'); + break; } @@ -670,7 +674,7 @@ 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() @@ -678,6 +682,8 @@ private function createAuthenticationPluginNode(): NodeDefinition ->scalarNode('password')->end() ->scalarNode('token')->end() ->scalarNode('service')->end() + ->scalarNode('header_name')->end() + ->scalarNode('header_value')->end() ->arrayNode('params')->prototype('scalar')->end() ->end() ->end() diff --git a/src/DependencyInjection/HttplugExtension.php b/src/DependencyInjection/HttplugExtension.php index 466320fa..a70e0b6c 100644 --- a/src/DependencyInjection/HttplugExtension.php +++ b/src/DependencyInjection/HttplugExtension.php @@ -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; @@ -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['header_name']) + ->addArgument($values['header_value']); + break; case 'service': $authServiceKey = $values['service']; diff --git a/tests/Resources/Fixtures/config/full.php b/tests/Resources/Fixtures/config/full.php index f73b0769..1ad5ff88 100644 --- a/tests/Resources/Fixtures/config/full.php +++ b/tests/Resources/Fixtures/config/full.php @@ -96,6 +96,11 @@ 'type' => 'bearer', 'token' => 'foo', ], + 'my_header' => [ + 'type' => 'header', + 'header_name' => 'foo', + 'header_value' => 'bar', + ], 'my_service' => [ 'type' => 'service', 'service' => 'my_auth_service', diff --git a/tests/Resources/Fixtures/config/full.xml b/tests/Resources/Fixtures/config/full.xml index b109dbb3..2e4f3f22 100644 --- a/tests/Resources/Fixtures/config/full.xml +++ b/tests/Resources/Fixtures/config/full.xml @@ -58,6 +58,7 @@ + diff --git a/tests/Resources/Fixtures/config/full.yml b/tests/Resources/Fixtures/config/full.yml index 1f4269cd..a0c41421 100644 --- a/tests/Resources/Fixtures/config/full.yml +++ b/tests/Resources/Fixtures/config/full.yml @@ -65,6 +65,10 @@ httplug: my_bearer: type: bearer token: foo + my_header: + type: header + header_name: foo + header_value: bar my_service: type: service service: my_auth_service diff --git a/tests/Unit/DependencyInjection/ConfigurationTest.php b/tests/Unit/DependencyInjection/ConfigurationTest.php index c05a9bd0..a1f648ab 100644 --- a/tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/tests/Unit/DependencyInjection/ConfigurationTest.php @@ -244,6 +244,12 @@ public function testSupportsAllConfigFormats(): void 'token' => 'foo', 'params' => [], ], + 'my_header' => [ + 'type' => 'header', + 'header_name' => 'foo', + 'header_value' => 'bar', + 'params' => [], + ], 'my_service' => [ 'type' => 'service', 'service' => 'my_auth_service',