Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions spec/Authentication/HeaderSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace spec\Http\Message\Authentication;

use PhpSpec\ObjectBehavior;
use Psr\Http\Message\RequestInterface;

class HeaderSpec extends ObjectBehavior
{
function let()
{
$this->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);
}
}
33 changes: 33 additions & 0 deletions src/Authentication/Header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Http\Message\Authentication;

use Http\Message\Authentication;
use Psr\Http\Message\RequestInterface;

class Header implements Authentication
{
/**
* @var string
*/
private $name;

/**
* @var string|array
*/
private $value;

public function __construct(string $name, $value)
{
$this->name = $name;
$this->value = $value;
}

/**
* {@inheritdoc}
*/
public function authenticate(RequestInterface $request)
{
return $request->withHeader($this->name, $this->value);
}
}