/** * Initiate RequestToken request operation * * @return void */ public function execute() { try { $requestUrl = $this->_helper->getRequestUrl($this->getRequest()); $request = $this->_helper->prepareRequest($this->getRequest(), $requestUrl); // Request request token $response = $this->_oauthService->getRequestToken($request, $requestUrl, $this->getRequest()->getMethod()); } catch (\Exception $exception) { $response = $this->_helper->prepareErrorResponse($exception, $this->getResponse()); } $this->getResponse()->setBody(http_build_query($response)); }
/** * {@inheritdoc} */ public function getUserId() { if ($this->integrationId) { return $this->integrationId; } $oauthRequest = $this->oauthHelper->prepareRequest($this->request); //If its not a valid Oauth request no further processing is needed if (empty($oauthRequest)) { return null; } $consumerId = $this->oauthService->validateAccessTokenRequest($oauthRequest, $this->oauthHelper->getRequestUrl($this->request), $this->request->getMethod()); $integration = $this->integrationService->findActiveIntegrationByConsumerId($consumerId); return $this->integrationId = $integration->getId() ? (int) $integration->getId() : null; }
/** * Initiate AccessToken request operation * * @return void */ public function execute() { try { $requestUrl = $this->_helper->getRequestUrl($this->getRequest()); $request = $this->_helper->prepareRequest($this->getRequest(), $requestUrl); // Request access token in exchange of a pre-authorized token $response = $this->_oauthService->getAccessToken($request, $requestUrl, $this->getRequest()->getMethod()); //After sending the access token, update the integration status to active; $consumer = $this->_intOauthService->loadConsumerByKey($request['oauth_consumer_key']); $this->_integrationService->findByConsumerId($consumer->getId())->setStatus(IntegrationModel::STATUS_ACTIVE)->save(); } catch (\Exception $exception) { $response = $this->_helper->prepareErrorResponse($exception, $this->getResponse()); } $this->getResponse()->setBody(http_build_query($response)); }
/** * Perform authentication and authorization. * * Authentication can be based on active customer/guest session or it can be based on OAuth headers. * * @throws \Magento\Framework\Exception\AuthorizationException * @return void */ protected function _checkPermissions() { /** * All mobile clients are expected to pass session cookie along with the request which will allow * to start session automatically. User ID and user type are initialized when session is created * during login call. */ $userId = $this->session->getUserId(); $userType = $this->session->getUserType(); $userIdentifier = null; $consumerId = null; if ($userType) { /** @var \Magento\Authz\Model\UserIdentifier $userIdentifier */ $userIdentifier = $this->_objectManager->create('Magento\\Authz\\Model\\UserIdentifier', ['userType' => $userType, 'userId' => $userId]); } else { $oauthRequest = $this->_oauthHelper->prepareRequest($this->_request); $consumerId = $this->_oauthService->validateAccessTokenRequest($oauthRequest, $this->_oauthHelper->getRequestUrl($this->_request), $this->_request->getMethod()); $this->_request->setConsumerId($consumerId); } $route = $this->_getCurrentRoute(); if (!$this->_authorizationService->isAllowed($route->getAclResources(), $userIdentifier)) { $params = ['resources' => implode(', ', $route->getAclResources())]; throw new AuthorizationException(AuthorizationException::NOT_AUTHORIZED, $params); } }