1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Acquia\Hmac\Symfony; |
4
|
|
|
|
5
|
|
|
use Acquia\Hmac\RequestAuthenticatorInterface; |
6
|
|
|
use Laminas\Diactoros\ResponseFactory; |
7
|
|
|
use Laminas\Diactoros\ServerRequestFactory; |
8
|
|
|
use Laminas\Diactoros\StreamFactory; |
9
|
|
|
use Laminas\Diactoros\UploadedFileFactory; |
10
|
|
|
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory; |
|
|
|
|
11
|
|
|
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory; |
12
|
|
|
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface; |
13
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
14
|
|
|
use Symfony\Component\Security\Core\Exception\AuthenticationException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Provides the means to authenticate an HTTP HMAC request. |
18
|
|
|
*/ |
19
|
|
|
class HmacAuthenticationProvider implements AuthenticationProviderInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var \Acquia\Hmac\RequestAuthenticatorInterface |
23
|
|
|
* A HMAC request authenticator service. |
24
|
|
|
*/ |
25
|
|
|
protected $authenticator; |
26
|
|
|
|
27
|
|
|
/** |
28
|
3 |
|
* Initializes the authentication provider. |
29
|
|
|
* |
30
|
3 |
|
* @param \Acquia\Hmac\RequestAuthenticatorInterface $authenticator |
31
|
3 |
|
* The HMAC request authenticator service. |
32
|
|
|
*/ |
33
|
|
|
public function __construct(RequestAuthenticatorInterface $authenticator) |
34
|
|
|
{ |
35
|
|
|
$this->authenticator = $authenticator; |
36
|
2 |
|
} |
37
|
|
|
|
38
|
2 |
|
/** |
39
|
2 |
|
* {@inheritDoc} |
40
|
|
|
*/ |
41
|
|
|
public function authenticate(TokenInterface $token) |
42
|
2 |
|
{ |
43
|
|
|
if (class_exists(DiactorosFactory::class)) { |
44
|
1 |
|
$httpMessageFactory = new DiactorosFactory(); |
45
|
1 |
|
} else { |
46
|
1 |
|
$httpMessageFactory = new PsrHttpFactory(new ServerRequestFactory(), new StreamFactory(), new UploadedFileFactory(), new ResponseFactory()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$psr7Request = $httpMessageFactory->createRequest($token->getRequest()); |
|
|
|
|
50
|
|
|
|
51
|
|
|
try { |
52
|
|
|
$key = $this->authenticator->authenticate($psr7Request); |
53
|
1 |
|
|
54
|
|
|
return new HmacToken($token->getRequest(), $key); |
55
|
1 |
|
} catch (\Exception $e) { |
56
|
|
|
throw new AuthenticationException($e->getMessage()); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritDoc} |
62
|
|
|
*/ |
63
|
|
|
public function supports(TokenInterface $token) |
64
|
|
|
{ |
65
|
|
|
return $token instanceof HmacToken; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths