Completed
Push — master ( 99c4e8...3c79d6 )
by Alexander
02:19
created

HttpBearerAuth   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

2 Methods

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