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

HttpBearerAuth::challenge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

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 0
cts 3
cp 0
crap 2
rs 10
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