|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace League\Bundle\OAuth2ServerBundle\Controller; |
| 6 | + |
| 7 | +use League\Bundle\OAuth2ServerBundle\Converter\UserConverterInterface; |
| 8 | +use League\Bundle\OAuth2ServerBundle\Event\AuthorizationRequestResolveEventFactory; |
| 9 | +use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface; |
| 10 | +use League\Bundle\OAuth2ServerBundle\Model\AbstractClient; |
| 11 | +use League\Bundle\OAuth2ServerBundle\OAuth2Events; |
| 12 | +use League\OAuth2\Server\AuthorizationServer; |
| 13 | +use League\OAuth2\Server\Exception\OAuthServerException; |
| 14 | +use Psr\Http\Message\ResponseFactoryInterface; |
| 15 | +use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface; |
| 16 | +use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface; |
| 17 | +use Symfony\Component\HttpFoundation\Request; |
| 18 | +use Symfony\Component\HttpFoundation\Response; |
| 19 | +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; |
| 20 | + |
| 21 | +final class DeviceCodeController |
| 22 | +{ |
| 23 | + /** |
| 24 | + * @var AuthorizationServer |
| 25 | + */ |
| 26 | + private $server; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var EventDispatcherInterface |
| 30 | + */ |
| 31 | + private $eventDispatcher; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var AuthorizationRequestResolveEventFactory |
| 35 | + */ |
| 36 | + private $eventFactory; |
| 37 | + |
| 38 | + /** |
| 39 | + * @var UserConverterInterface |
| 40 | + */ |
| 41 | + private $userConverter; |
| 42 | + |
| 43 | + /** |
| 44 | + * @var ClientManagerInterface |
| 45 | + */ |
| 46 | + private $clientManager; |
| 47 | + |
| 48 | + /** |
| 49 | + * @var HttpMessageFactoryInterface |
| 50 | + */ |
| 51 | + private $httpMessageFactory; |
| 52 | + |
| 53 | + /** |
| 54 | + * @var HttpFoundationFactoryInterface |
| 55 | + */ |
| 56 | + private $httpFoundationFactory; |
| 57 | + |
| 58 | + /** |
| 59 | + * @var ResponseFactoryInterface |
| 60 | + */ |
| 61 | + private $responseFactory; |
| 62 | + |
| 63 | + public function __construct( |
| 64 | + AuthorizationServer $server, |
| 65 | + EventDispatcherInterface $eventDispatcher, |
| 66 | + AuthorizationRequestResolveEventFactory $eventFactory, |
| 67 | + UserConverterInterface $userConverter, |
| 68 | + ClientManagerInterface $clientManager, |
| 69 | + HttpMessageFactoryInterface $httpMessageFactory, |
| 70 | + HttpFoundationFactoryInterface $httpFoundationFactory, |
| 71 | + ResponseFactoryInterface $responseFactory, |
| 72 | + ) { |
| 73 | + $this->server = $server; |
| 74 | + $this->eventDispatcher = $eventDispatcher; |
| 75 | + $this->eventFactory = $eventFactory; |
| 76 | + $this->userConverter = $userConverter; |
| 77 | + $this->clientManager = $clientManager; |
| 78 | + $this->httpMessageFactory = $httpMessageFactory; |
| 79 | + $this->httpFoundationFactory = $httpFoundationFactory; |
| 80 | + $this->responseFactory = $responseFactory; |
| 81 | + } |
| 82 | + |
| 83 | + public function indexAction(Request $request): Response |
| 84 | + { |
| 85 | + $serverRequest = $this->httpMessageFactory->createRequest($request); |
| 86 | + $serverResponse = $this->responseFactory->createResponse(); |
| 87 | + |
| 88 | + try { |
| 89 | + $response = $this->server->respondToDeviceAuthorizationRequest($serverRequest, $serverResponse); |
| 90 | + } catch (OAuthServerException $e) { |
| 91 | + $response = $e->generateHttpResponse($serverResponse); |
| 92 | + } |
| 93 | + |
| 94 | + return $this->httpFoundationFactory->createResponse($response); |
| 95 | + } |
| 96 | +} |
0 commit comments