OAuth2Listener::handle()   A
last analyzed

Complexity

Conditions 2
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 4
nop 1
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());
0 ignored issues
show
Bug introduced by
The method setRequest() does not seem to exist on object<League\OAuth2\Server\ResourceServer>.

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.

Loading history...
51
52
        try {
53
            $tokenData = $this->resourceServer->determineAccessToken(true);
0 ignored issues
show
Bug introduced by
The method determineAccessToken() does not seem to exist on object<League\OAuth2\Server\ResourceServer>.

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.

Loading history...
54
            $authenticatedToken = $this->authenticationManager->authenticate(new OAuth2Token($tokenData));
55
            $this->tokenStorage->setToken($authenticatedToken);
56
        } catch (InvalidRequestException $e) {
0 ignored issues
show
Bug introduced by
The class League\OAuth2\Server\Exc...InvalidRequestException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
57
            // noop, allow requests without token.
58
        }
59
    }
60
}
61