/** * Validate signature * * @throws Mage_Oauth_Exception */ protected function _validateSignature() { $util = new Zend_Oauth_Http_Utility(); $calculatedSign = $util->sign(array_merge($this->_params, $this->_protocolParams), $this->_protocolParams['oauth_signature_method'], $this->_consumer->getSecret(), $this->_token->getSecret(), $this->_request->getMethod(), $this->_request->getScheme() . '://' . $this->_request->getHttpHost() . $this->_request->getRequestUri()); if ($calculatedSign != $this->_protocolParams['oauth_signature']) { $this->_throwException('', self::ERR_SIGNATURE_INVALID); } }
/** * Send the registration data to Styla and request module configuration * * @param array $loginData * @param Mage_Oauth_Model_Consumer $consumer * @param Mage_Oauth_Model_Token $token * @param $scopeData * @return stdClass * @throws Exception * @throws Styla_Connect_Exception */ public function sendRegistrationRequest($loginData, $consumer, $token, $scopeData) { //at this point we have all the login data we need for styla to access our api $stylaApi = Mage::getSingleton('styla_connect/styla_api'); //make the api request to styla api $apiRequest = $stylaApi->getRequest(Styla_Connect_Model_Styla_Api::REQUEST_TYPE_REGISTER_MAGENTO_API); $apiRequest->setConnectionType(Zend_Http_Client::POST); $apiRequest->setParams(array('styla_email' => $loginData['email'], 'styla_password' => $loginData['password'], 'consumer_key' => $consumer->getKey(), 'consumer_secret' => $consumer->getSecret(), 'token_key' => $token->getToken(), 'token_secret' => $token->getSecret())); $apiResponse = $stylaApi->callService($apiRequest, false); if (!$apiResponse->isOk()) { throw new Exception("Couldn't connect to Styla API. Error result: " . $apiResponse->getHttpStatus() . ($apiResponse->getError() ? ' - ' . $apiResponse->getError() : '')); } //setup the api urls for this client /** @var array $connectionData */ $connectionData = $apiResponse->getResult(); return $connectionData; }
/** * Get row URL * * @param Mage_Oauth_Model_Consumer $row * @return string|null */ public function getRowUrl($row) { if ($this->_editAllow) { return $this->getUrl('*/*/edit', array('id' => $row->getId())); } return null; }
/** * Send the registration data to Styla and request module configuration * * @param array $loginData * @param Mage_Oauth_Model_Consumer $consumer * @param Mage_Oauth_Model_Token $token * @return stdClass * @throws Exception */ public function sendRegistrationRequest($loginData, $consumer, $token) { //at this point we have all the login data we need for styla to access our api $stylaApi = Mage::getSingleton('styla_connect/styla_api'); //make the api request to styla api $apiRequest = $stylaApi->getRequest(Styla_Connect_Model_Styla_Api::REQUEST_TYPE_REGISTER_MAGENTO_API); $apiRequest->setConnectionType(Zend_Http_Client::POST); $apiRequest->setParams(array('styla_email' => $loginData['email'], 'styla_password' => $loginData['password'], 'consumer_key' => $consumer->getKey(), 'consumer_secret' => $consumer->getSecret(), 'token_key' => $token->getToken(), 'token_secret' => $token->getSecret())); $apiResponse = $stylaApi->callService($apiRequest, false); if (!$apiResponse->isOk()) { throw new Exception("Couldn't connect to Styla API. Error result: " . $apiResponse->getHttpStatus() . ($apiResponse->getError() ? " - " . $apiResponse->getError() : "")); } //setup the api urls for this client /** @var array $connectionData */ $connectionData = $apiResponse->getResult(); /** * store the result data, so we don't have to call the api anymore in the future (on every change of the module's operating mode * the configuration gets overwritten, so otherwise we'd have to call the api every time we change it) */ $this->cacheConnectionData($connectionData, Mage::helper('styla_connect/config')->getMode()); return $connectionData; }