From a99a169ff839d50633a61a9368132d90cef13f13 Mon Sep 17 00:00:00 2001 From: Fabien Bourigault Date: Thu, 12 Sep 2019 17:09:40 +0200 Subject: [PATCH] add Header authentication method --- CHANGELOG.md | 4 ++++ spec/Authentication/HeaderSpec.php | 31 ++++++++++++++++++++++++++++ src/Authentication/Header.php | 33 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 spec/Authentication/HeaderSpec.php create mode 100644 src/Authentication/Header.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 93427cb..6a29df8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +### Added + +- New Header authentication method for arbitrary header authentication. + ## [1.8.0] - 2019-08-05 ### Changed diff --git a/spec/Authentication/HeaderSpec.php b/spec/Authentication/HeaderSpec.php new file mode 100644 index 0000000..b6ee348 --- /dev/null +++ b/spec/Authentication/HeaderSpec.php @@ -0,0 +1,31 @@ +beConstructedWith('X-AUTH-TOKEN', 'REAL'); + } + + function it_is_initializable() + { + $this->shouldHaveType('Http\Message\Authentication\Header'); + } + + function it_is_an_authentication() + { + $this->shouldImplement('Http\Message\Authentication'); + } + + function it_authenticates_a_request(RequestInterface $request, RequestInterface $newRequest) + { + $request->withHeader('X-AUTH-TOKEN', 'REAL')->willReturn($newRequest); + + $this->authenticate($request)->shouldReturn($newRequest); + } +} diff --git a/src/Authentication/Header.php b/src/Authentication/Header.php new file mode 100644 index 0000000..97a04dd --- /dev/null +++ b/src/Authentication/Header.php @@ -0,0 +1,33 @@ +name = $name; + $this->value = $value; + } + + /** + * {@inheritdoc} + */ + public function authenticate(RequestInterface $request) + { + return $request->withHeader($this->name, $this->value); + } +}