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 |
|
|
|
|
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()); |
|
|
|
|
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
|
|
|
|
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.