Issues (3627)

Security/OAuth1/Firewall/OAuthListener.php (1 issue)

Severity
1
<?php
2
3
/*
4
 * @copyright   2014 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\ApiBundle\Security\OAuth1\Firewall;
13
14
use Bazinga\OAuthServerBundle\Security\Authentification\Token\OAuthToken;
15
use Symfony\Component\HttpFoundation\Response;
16
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
17
use Symfony\Component\HttpKernel\Exception\HttpException;
18
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
19
use Symfony\Component\Security\Core\Exception\AuthenticationException;
20
21
class OAuthListener extends \Bazinga\OAuthServerBundle\Security\Firewall\OAuthListener
22
{
23
    /**
24
     * @throws AuthenticationException
25
     * @throws HttpException
26
     */
27
    public function handle(GetResponseEvent $event)
28
    {
29
        $request = $event->getRequest();
30
31
        if (false === $request->attributes->get('oauth_request_parameters', false)) {
32
            return;
33
        }
34
35
        $token = new OAuthToken();
36
        $token->setRequestParameters($request->attributes->get('oauth_request_parameters'));
37
        $token->setRequestMethod($request->attributes->get('oauth_request_method'));
38
        $token->setRequestUrl($request->attributes->get('oauth_request_url'));
39
40
        try {
41
            $returnValue = $this->authenticationManager->authenticate($token);
42
43
            if ($returnValue instanceof TokenInterface) {
0 ignored issues
show
$returnValue is always a sub-type of Symfony\Component\Securi...on\Token\TokenInterface.
Loading history...
44
                return $this->tokenStorage->setToken($returnValue);
45
            } elseif ($returnValue instanceof Response) {
46
                return $event->setResponse($returnValue);
47
            }
48
        } catch (AuthenticationException $e) {
49
            throw $e;
50
        }
51
    }
52
}
53