CustomerSessionUserContext.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Webapi\Model\Plugin\Authorization;
  7. use Magento\Framework\App\RequestInterface;
  8. /**
  9. * This plugin allows only AJAX requests when customers access web APIs.
  10. */
  11. class CustomerSessionUserContext
  12. {
  13. /**
  14. * @var RequestInterface
  15. */
  16. private $request;
  17. /**
  18. * Initialize dependencies.
  19. *
  20. * @param RequestInterface $request
  21. */
  22. public function __construct(RequestInterface $request)
  23. {
  24. $this->request = $request;
  25. }
  26. /**
  27. * Allow only AJAX requests when customers access web APIs.
  28. *
  29. * @param \Magento\Customer\Model\Authorization\CustomerSessionUserContext $userContext
  30. * @param int|null $result
  31. * @return int|null
  32. * @codeCoverageIgnore
  33. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  34. */
  35. public function afterGetUserId(
  36. \Magento\Customer\Model\Authorization\CustomerSessionUserContext $userContext,
  37. $result
  38. ) {
  39. return $this->request->isXmlHttpRequest() ? $result : null;
  40. }
  41. }