TokenHeaderAuthentication::authenticate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Lookyman\Rundeck\Api\Authentication;
5
6
use Psr\Http\Message\RequestInterface;
7
8
class TokenHeaderAuthentication implements AuthenticationInterface
9
{
10
	/**
11
	 * @var string
12
	 */
13
	private $token;
14
15
	/**
16
	 * @param string $token
17
	 */
18
	public function __construct(string $token)
19
	{
20
		$this->token = $token;
21
	}
22
23
	/**
24
	 * @param callable $handler
25
	 * @return callable
26
	 */
27
	public function authenticate(callable $handler): callable
28
	{
29
		return function (RequestInterface $request, array $options) use ($handler) {
30
			return $handler($request->withAddedHeader('X-Rundeck-Auth-Token', $this->token), $options);
31
		};
32
	}
33
}
34