HmacAuthenticationProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 43
ccs 12
cts 12
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A authenticate() 0 12 2
A supports() 0 3 1
1
<?php
2
3
namespace Acquia\Hmac\Symfony;
4
5
use Acquia\Hmac\RequestAuthenticatorInterface;
6
use Nyholm\Psr7\Factory\Psr17Factory;
7
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
8
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
9
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
10
use Symfony\Component\Security\Core\Exception\AuthenticationException;
11
12
/**
13
 * Provides the means to authenticate an HTTP HMAC request.
14
 */
15
class HmacAuthenticationProvider implements AuthenticationProviderInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Symfony\Component\Securi...cationProviderInterface has been deprecated: since Symfony 5.3, use the new authenticator system instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

15
class HmacAuthenticationProvider implements /** @scrutinizer ignore-deprecated */ AuthenticationProviderInterface

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
16
{
17
    /**
18
     * @var \Acquia\Hmac\RequestAuthenticatorInterface
19
     *   A HMAC request authenticator service.
20
     */
21
    protected $authenticator;
22
23
    /**
24
     * Initializes the authentication provider.
25
     *
26
     * @param \Acquia\Hmac\RequestAuthenticatorInterface $authenticator
27
     *   The HMAC request authenticator service.
28 3
     */
29
    public function __construct(RequestAuthenticatorInterface $authenticator)
30 3
    {
31 3
        $this->authenticator = $authenticator;
32
    }
33
34
    /**
35
     * {@inheritDoc}
36 2
     */
37
    public function authenticate(TokenInterface $token)
38 2
    {
39 2
        $psr17Factory = new Psr17Factory();
40
        $httpMessageFactory = new PsrHttpFactory($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);
41
        $psr7Request = $httpMessageFactory->createRequest($token->getRequest());
0 ignored issues
show
Bug introduced by
The method getRequest() does not exist on Symfony\Component\Securi...on\Token\TokenInterface. It seems like you code against a sub-type of Symfony\Component\Securi...on\Token\TokenInterface such as Acquia\Hmac\Symfony\HmacToken. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        $psr7Request = $httpMessageFactory->createRequest($token->/** @scrutinizer ignore-call */ getRequest());
Loading history...
42 2
43
        try {
44 1
            $key = $this->authenticator->authenticate($psr7Request);
45 1
46 1
            return new HmacToken($token->getRequest(), $key);
47
        } catch (\Exception $e) {
48
            throw new AuthenticationException($e->getMessage());
49
        }
50
    }
51
52
    /**
53 1
     * {@inheritDoc}
54
     */
55 1
    public function supports(TokenInterface $token)
56
    {
57
        return $token instanceof HmacToken;
58
    }
59
}
60