AbstractAuthenticator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Bundle\ApiAuthBundle\Security;
6
7
use Damax\Bundle\ApiAuthBundle\Extractor\Extractor;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
11
use Symfony\Component\Security\Core\Exception\AuthenticationException;
12
use Symfony\Component\Security\Core\User\UserInterface;
13
use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
14
15
/**
16
 * @see https://symfony.com/doc/current/_images/authentication-guard-methods.png
17
 */
18
abstract class AbstractAuthenticator extends AbstractGuardAuthenticator
19
{
20
    private $extractor;
21
    private $response;
22
23
    public function __construct(Extractor $extractor, ResponseFactory $response)
24
    {
25
        $this->extractor = $extractor;
26
        $this->response = $response;
27
    }
28
29
    public function supports(Request $request): bool
30
    {
31
        return null !== $this->extractor->extractKey($request);
32
    }
33
34
    public function start(Request $request, AuthenticationException $exception = null): Response
35
    {
36
        return $this->response->fromError(Response::HTTP_UNAUTHORIZED, $exception);
37
    }
38
39
    public function getCredentials(Request $request): string
40
    {
41
        return (string) $this->extractor->extractKey($request);
42
    }
43
44
    public function checkCredentials($credentials, UserInterface $user): bool
45
    {
46
        return true;
47
    }
48
49
    public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey): ?Response
50
    {
51
        return null;
52
    }
53
54
    public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
55
    {
56
        return $this->response->fromError(Response::HTTP_FORBIDDEN, $exception);
57
    }
58
59
    public function supportsRememberMe(): bool
60
    {
61
        return false;
62
    }
63
}
64