Request.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Integration\Controller\Token;
  8. use Magento\Framework\App\Action\Action;
  9. use Magento\Framework\App\CsrfAwareActionInterface;
  10. use Magento\Framework\App\Request\InvalidRequestException;
  11. use Magento\Framework\App\RequestInterface;
  12. class Request extends Action implements CsrfAwareActionInterface
  13. {
  14. /**
  15. * @var \Magento\Framework\Oauth\OauthInterface
  16. */
  17. protected $oauthService;
  18. /**
  19. * @var \Magento\Framework\Oauth\Helper\Request
  20. */
  21. protected $helper;
  22. /**
  23. * @param \Magento\Framework\App\Action\Context $context
  24. * @param \Magento\Framework\Oauth\OauthInterface $oauthService
  25. * @param \Magento\Framework\Oauth\Helper\Request $helper
  26. */
  27. public function __construct(
  28. \Magento\Framework\App\Action\Context $context,
  29. \Magento\Framework\Oauth\OauthInterface $oauthService,
  30. \Magento\Framework\Oauth\Helper\Request $helper
  31. ) {
  32. parent::__construct($context);
  33. $this->oauthService = $oauthService;
  34. $this->helper = $helper;
  35. }
  36. /**
  37. * @inheritDoc
  38. */
  39. public function createCsrfValidationException(
  40. RequestInterface $request
  41. ): ?InvalidRequestException {
  42. return null;
  43. }
  44. /**
  45. * @inheritDoc
  46. */
  47. public function validateForCsrf(RequestInterface $request): ?bool
  48. {
  49. return true;
  50. }
  51. /**
  52. * Initiate RequestToken request operation
  53. *
  54. * @return void
  55. */
  56. public function execute()
  57. {
  58. try {
  59. $requestUrl = $this->helper->getRequestUrl($this->getRequest());
  60. $request = $this->helper->prepareRequest($this->getRequest(), $requestUrl);
  61. // Request request token
  62. $response = $this->oauthService->getRequestToken($request, $requestUrl, $this->getRequest()->getMethod());
  63. } catch (\Exception $exception) {
  64. $response = $this->helper->prepareErrorResponse($exception, $this->getResponse());
  65. }
  66. $this->getResponse()->setBody(http_build_query($response));
  67. }
  68. }