Passed
Push — master ( 9f5b15...3a86cf )
by Alexander
01:15
created

HttpBearer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 20
ccs 4
cts 4
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A challenge() 0 3 1
A setRealm() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Auth\Method;
6
7
use Psr\Http\Message\ResponseInterface;
8
9
/**
10
 * HttpBearerAuth supports the authentication method based on HTTP Bearer token.
11
 */
12
final class HttpBearer extends HttpHeader
13
{
14
    private const HEADER_NAME = 'Authorization';
15
    private const PATTERN = '/^Bearer\s+(.*?)$/';
16
17
    protected string $headerName = self::HEADER_NAME;
18
    protected string $pattern = self::PATTERN;
19
    /**
20
     * @var string the HTTP authentication realm
21
     */
22
    private string $realm = 'api';
23
24 3
    public function challenge(ResponseInterface $response): ResponseInterface
25
    {
26 3
        return $response->withHeader('WWW-Authenticate', "{$this->headerName} realm=\"{$this->realm}\"");
27
    }
28
29 1
    public function setRealm(string $realm): void
30
    {
31 1
        $this->realm = $realm;
32 1
    }
33
}
34