SignedRequestAuthenticator   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 15
c 1
b 0
f 0
dl 0
loc 55
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A checkCredentials() 0 3 1
A onAuthenticationSuccess() 0 3 1
A supportsRememberMe() 0 3 1
A getUser() 0 3 1
A onAuthenticationFailure() 0 7 1
A supports() 0 3 1
A getCredentials() 0 3 1
A __construct() 0 3 1
A start() 0 7 1
1
<?php
2
3
namespace App\Security;
4
5
use App\Entity\User;
6
use Symfony\Component\HttpFoundation\JsonResponse;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpFoundation\Response;
9
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
10
use Symfony\Component\Security\Core\Exception\AuthenticationException;
11
use Symfony\Component\Security\Core\User\UserInterface;
12
use Symfony\Component\Security\Core\User\UserProviderInterface;
13
use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
14
15
final class SignedRequestAuthenticator extends AbstractGuardAuthenticator
16
{
17
    private $requestDecoder;
18
19
    public function __construct(RequestDecoderInterface $requestDecoder)
20
    {
21
        $this->requestDecoder = $requestDecoder;
22
    }
23
24
    public function supports(Request $request)
25
    {
26
        return $request->headers->has(RequestDecoder::REQUEST_TOKEN_KEY);
27
    }
28
29
    public function getCredentials(Request $request): Request
30
    {
31
        return $request;
32
    }
33
34
    public function getUser($credentials, UserProviderInterface $userProvider)
35
    {
36
        return new User();
37
    }
38
39
    public function checkCredentials($request, UserInterface $user)
40
    {
41
        return $this->requestDecoder->decode($request);
42
    }
43
44
    public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
45
    {
46
        return null;
47
    }
48
49
    public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
50
    {
51
        $data = [
52
            'message' => strtr($exception->getMessageKey(), $exception->getMessageData()),
53
        ];
54
55
        return new JsonResponse($data, Response::HTTP_FORBIDDEN);
56
    }
57
58
    public function start(Request $request, AuthenticationException $authException = null)
59
    {
60
        $data = [
61
            'message' => 'Authentication Required',
62
        ];
63
64
        return new JsonResponse($data, Response::HTTP_UNAUTHORIZED);
65
    }
66
67
    public function supportsRememberMe()
68
    {
69
        return false;
70
    }
71
}
72