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\Controller\oAuth1; |
||
13 | |||
14 | use Bazinga\OAuthServerBundle\Model\RequestTokenInterface; |
||
15 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
||
16 | use Symfony\Component\HttpFoundation\Request; |
||
17 | use Symfony\Component\HttpFoundation\Response; |
||
18 | use Symfony\Component\HttpKernel\Exception\HttpException; |
||
19 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
||
20 | use Symfony\Component\Security\Core\User\UserInterface; |
||
21 | |||
22 | class AuthorizeController extends Controller |
||
23 | { |
||
24 | /** |
||
25 | * @return Response |
||
26 | * |
||
27 | * @throws AccessDeniedException |
||
28 | * @throws HttpException |
||
29 | */ |
||
30 | public function allowAction(Request $request) |
||
31 | { |
||
32 | $oauth_token = $request->get('oauth_token', null); |
||
33 | $oauth_callback = $request->get('oauth_callback', null); |
||
34 | $tokenStorage = $this->container->get('security.token_storage'); |
||
35 | $tokenProvider = $this->container->get('bazinga.oauth.provider.token_provider'); |
||
36 | $user = $tokenStorage->getToken()->getUser(); |
||
37 | |||
38 | if (!$user instanceof UserInterface) { |
||
39 | throw new AccessDeniedException('This user does not have access to this section.'); |
||
40 | } |
||
41 | |||
42 | $token = $tokenProvider->loadRequestTokenByToken($oauth_token); |
||
43 | $consumer = $token->getConsumer(); |
||
44 | |||
45 | $restricted_oauth_callback = $consumer->getCallback(); |
||
46 | if (!empty($restricted_oauth_callback) && 0 !== strpos($oauth_callback, $restricted_oauth_callback)) { |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
47 | throw new AccessDeniedException('Callback is not valid.'); |
||
48 | } |
||
49 | |||
50 | if ($token instanceof RequestTokenInterface) { |
||
51 | $tokenProvider->setUserForRequestToken($token, $tokenStorage->getToken()->getUser()); |
||
52 | |||
53 | return new Response($this->container->get('templating')->render('MauticApiBundle:Authorize:oAuth1/authorize.html.php', [ |
||
54 | 'consumer' => $token->getConsumer(), |
||
55 | 'oauth_token' => $oauth_token, |
||
56 | 'oauth_callback' => $oauth_callback, |
||
57 | ])); |
||
58 | } |
||
59 | |||
60 | throw new HttpException(404); |
||
61 | } |
||
62 | } |
||
63 |