1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Eole\Sandstone\OAuth2\Security\Http\Firewall; |
4
|
|
|
|
5
|
|
|
use League\OAuth2\Server\ResourceServer; |
6
|
|
|
use League\OAuth2\Server\Exception\InvalidRequestException; |
7
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
8
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
9
|
|
|
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; |
10
|
|
|
use Symfony\Component\Security\Http\Firewall\ListenerInterface; |
11
|
|
|
use Eole\Sandstone\OAuth2\Security\Authentication\Token\OAuth2Token; |
12
|
|
|
|
13
|
|
|
class OAuth2Listener implements ListenerInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var TokenStorageInterface |
17
|
|
|
*/ |
18
|
|
|
protected $tokenStorage; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var AuthenticationManagerInterface |
22
|
|
|
*/ |
23
|
|
|
protected $authenticationManager; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var ResourceServer |
27
|
|
|
*/ |
28
|
|
|
private $resourceServer; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param TokenStorageInterface $tokenStorage |
32
|
|
|
* @param AuthenticationManagerInterface $authenticationManager |
33
|
|
|
* @param ResourceServer $resourceServer |
34
|
|
|
*/ |
35
|
|
|
public function __construct( |
36
|
|
|
TokenStorageInterface $tokenStorage, |
37
|
|
|
AuthenticationManagerInterface $authenticationManager, |
38
|
|
|
ResourceServer $resourceServer |
39
|
|
|
) { |
40
|
|
|
$this->tokenStorage = $tokenStorage; |
41
|
|
|
$this->authenticationManager = $authenticationManager; |
42
|
|
|
$this->resourceServer = $resourceServer; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@InheritDoc} |
47
|
|
|
*/ |
48
|
|
|
public function handle(GetResponseEvent $event) |
49
|
|
|
{ |
50
|
|
|
$this->resourceServer->setRequest($event->getRequest()); |
|
|
|
|
51
|
|
|
|
52
|
|
|
try { |
53
|
|
|
$tokenData = $this->resourceServer->determineAccessToken(true); |
|
|
|
|
54
|
|
|
$authenticatedToken = $this->authenticationManager->authenticate(new OAuth2Token($tokenData)); |
55
|
|
|
$this->tokenStorage->setToken($authenticatedToken); |
56
|
|
|
} catch (InvalidRequestException $e) { |
|
|
|
|
57
|
|
|
// noop, allow requests without token. |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.