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

HttpBearer::setRealm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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