Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Access.php
Go to the documentation of this file.
1 <?php
8 
14 use Magento\Integration\Api\OauthServiceInterface as IntegrationOauthService;
16 
17 class Access extends Action implements CsrfAwareActionInterface
18 {
22  protected $oauthService;
23 
27  protected $intOauthService;
28 
33 
37  protected $helper;
38 
46  public function __construct(
47  \Magento\Framework\App\Action\Context $context,
48  \Magento\Framework\Oauth\OauthInterface $oauthService,
49  IntegrationOauthService $intOauthService,
50  IntegrationService $integrationService,
51  \Magento\Framework\Oauth\Helper\Request $helper
52  ) {
53  parent::__construct($context);
54  $this->oauthService = $oauthService;
55  $this->intOauthService = $intOauthService;
56  $this->integrationService = $integrationService;
57  $this->helper = $helper;
58  }
59 
66  return null;
67  }
68 
72  public function validateForCsrf(RequestInterface $request): ?bool
73  {
74  return true;
75  }
76 
82  public function execute()
83  {
84  try {
85  $requestUrl = $this->helper->getRequestUrl($this->getRequest());
86  $request = $this->helper->prepareRequest($this->getRequest(), $requestUrl);
87 
88  // Request access token in exchange of a pre-authorized token
89  $response = $this->oauthService->getAccessToken($request, $requestUrl, $this->getRequest()->getMethod());
90  //After sending the access token, update the integration status to active;
91  $consumer = $this->intOauthService->loadConsumerByKey($request['oauth_consumer_key']);
92  $integration = $this->integrationService->findByConsumerId($consumer->getId());
93  $integration->setStatus(IntegrationModel::STATUS_ACTIVE);
94  $integration->save();
95  } catch (\Exception $exception) {
96  $response = $this->helper->prepareErrorResponse($exception, $this->getResponse());
97  }
98  $this->getResponse()->setBody(http_build_query($response));
99  }
100 }
$response
Definition: 404.php:11
validateForCsrf(RequestInterface $request)
Definition: Access.php:72
createCsrfValidationException(RequestInterface $request)
Definition: Access.php:63
__construct(\Magento\Framework\App\Action\Context $context, \Magento\Framework\Oauth\OauthInterface $oauthService, IntegrationOauthService $intOauthService, IntegrationService $integrationService, \Magento\Framework\Oauth\Helper\Request $helper)
Definition: Access.php:46