/**
  *
  * @example /profile/group-oauth/consume/provider2?oauth_token=request-token
  *
  * @param string $providerId
  * @return void
  */
 public function consumeAction($providerId)
 {
     $this->setNoRender();
     $providerConfig = $this->_getProviderConfiguration($providerId);
     $consumer = new Zend_Oauth_Consumer($providerConfig->auth);
     $queryParameters = $this->_getRequest()->getQueryParameters();
     if (empty($queryParameters)) {
         throw new EngineBlock_Exception('Unable to consume access token, no query parameters given');
     }
     if (!isset($_SESSION['request_token'][$providerId])) {
         throw new EngineBlock_Exception("Unable to consume access token, no request token (session lost?)");
     }
     $requestToken = unserialize($_SESSION['request_token'][$providerId]);
     $token = $consumer->getAccessToken($queryParameters, $requestToken);
     $userId = $this->attributes['nameid'][0];
     $provider = EngineBlock_Group_Provider_OpenSocial_Oauth_ThreeLegged::createFromConfigs($providerConfig, $userId);
     $provider->setAccessToken($token);
     if (!$provider->validatePreconditions()) {
         EngineBlock_ApplicationSingleton::getLog()->err("Unable to test OpenSocial 3-legged Oauth provider because not all preconditions have been matched?", new EngineBlock_Log_Message_AdditionalInfo($userId, null, null, null));
         $this->providerId = $providerId;
         $this->renderAction("Error");
     } else {
         // Now that we have an Access Token, we can discard the Request Token
         $_SESSION['request_token'][$providerId] = null;
         $this->_redirectToUrl($_SESSION['return_url']);
     }
 }
示例#2
0
 public function callbackAction()
 {
     //oAuth parameters
     $params = array('siteUrl' => 'http://ecschina.com/oauth', 'requestTokenUrl' => 'http://ecschina.com/oauth/initiate', 'accessTokenUrl' => 'http://ecschina.com/oauth/token', 'consumerKey' => 'ufs7anw8j9duj754vplvczyxmcdvor5b', 'consumerSecret' => 'i8mcujolcsglsx3egi2do10cmvelkly8');
     // Get session
     $session = Mage::getSingleton('core/session');
     // Read and unserialize request token from session
     $requestToken = unserialize($session->getRequestToken());
     // Initiate oAuth consumer
     $consumer = new Zend_Oauth_Consumer($params);
     // Using oAuth parameters and request Token we got, get access token
     $acessToken = $consumer->getAccessToken($_GET, $requestToken);
     // Get HTTP client from access token object
     $restClient = $acessToken->getHttpClient($params);
     // Set REST resource URL
     $restClient->setUri('http://magento.loc/api/rest/products');
     // In Magento it is neccesary to set json or xml headers in order to work
     $restClient->setHeaders('Accept', 'application/json');
     // Get method
     $restClient->setMethod(Zend_Http_Client::GET);
     //Make REST request
     $response = $restClient->request();
     // Here we can see that response body contains json list of products
     Zend_Debug::dump($response);
     return;
 }
示例#3
0
文件: Twitter.php 项目: nnixaa/sauth
 /**
  * Authenticate user by twitter OAuth
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     $config = $this->getConfig();
     if (empty($config['consumerKey']) || empty($config['consumerSecret']) || empty($config['userAuthorizationUrl']) || empty($config['accessTokenUrl']) || empty($config['callbackUrl'])) {
         require_once 'Zend/Auth/Adapter/Exception.php';
         throw new Zend_Auth_Adapter_Exception('Twitter auth configuration not specifed');
     }
     $consumer = new Zend_Oauth_Consumer($config);
     $tokenRequest = $this->_getTokenRequest();
     if (!empty($tokenRequest) && !empty($_GET)) {
         $tokenAccess = $consumer->getAccessToken($_GET, $tokenRequest);
         $response = $tokenAccess->getResponse();
         if ($response->isError()) {
             //TODO:change on custom
             $error = 'Twitter Oauth service unavailable';
             return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, false, array($error));
         } elseif ($response->isSuccessful()) {
             $parsedResponse = $this->parseResponseUrl($response->getBody());
             $this->_unsetTokenRequest();
             $identity = $this->_prepareIdentity($parsedResponse);
             return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
         }
     } else {
         $tokenRequest = $consumer->getRequestToken();
         $this->_setTokenRequest($tokenRequest);
         $consumer->redirect();
     }
 }
 public function Callback()
 {
     $this->view->setVar('config', $va_config = $this->_getOauthConfig());
     $this->view->setVar('consumer', $o_consumer = new Zend_Oauth_Consumer($va_config));
     $o_token = $o_consumer->getAccessToken($_GET, unserialize(file_get_contents(__CA_APP_DIR__ . '/tmp/twitter.token')));
     file_put_contents(__CA_APP_DIR__ . '/tmp/twitter.token', serialize($o_token));
     $this->render('handle_callback_html.php');
 }
示例#5
0
 public static function getAuthorizationUrl()
 {
     $options = Zend_Registry::get('config');
     $consumer = new Zend_Oauth_Consumer($options['twitter']);
     $token = $consumer->getRequestToken();
     $twitterToken = new Zend_Session_Namespace('twitterToken');
     $twitterToken->rt = serialize($token);
     return $consumer->getRedirectUrl(null, $token);
 }
示例#6
0
文件: Twitter.php 项目: hYOUstone/tsg
 public static function getAuthorizationUrl()
 {
     $config = Registry::get('config');
     $options = is_object($config) ? $config->toArray() : $config;
     $consumer = new Consumer($options['twitter']);
     $token = $consumer->getRequestToken();
     $twitterToken = new SessionNamespace('twitterToken');
     $twitterToken->rt = serialize($token);
     return $consumer->getRedirectUrl(null, $token);
 }
 public function getAccessToken($responseParams)
 {
     if (!empty($responseParams) && isset($_SESSION['REQUEST_TOKEN'])) {
         $oauthConsumer = new Zend_Oauth_Consumer($this->configParams);
         $token = $oauthConsumer->getAccessToken($responseParams, unserialize($_SESSION['REQUEST_TOKEN']));
         $_SESSION['ACCESS_TOKEN'] = serialize($token);
         $_SESSION['REQUEST_TOKEN'] = null;
         return true;
     } else {
         return false;
         //exit('Invalid callback request. Oops. Sorry.');
     }
 }
示例#8
0
 public function _getAccessToken($accessToken = null)
 {
     if (!empty($accessToken)) {
         $this->_accessToken = $accessToken;
     } elseif (!empty($_SESSION['linkedin']['accessToken'])) {
         $this->_accessToken = unserialize($_SESSION['linkedin']['accessToken']);
     } elseif (!empty($_SESSION['linkedin']['requestToken'])) {
         $this->_accessToken = $this->_oConsumer->getAccessToken($_REQUEST, unserialize($_SESSION['linkedin']['requestToken']));
     }
     if ($this->_accessToken) {
         $_SESSION['linkedin']['accessToken'] = serialize($this->_accessToken);
         return $this->_accessToken;
     }
 }
示例#9
0
 public function twitterAction()
 {
     $this->view->layout()->disableLayout();
     $this->_helper->viewRenderer->setNoRender(true);
     $config = array('callbackUrl' => 'http://we.com/employee/twitter-callback', 'siteUrl' => 'http://twitter.com/oauth', 'consumerKey' => 'pVq8Yq0ZdsR7Zdzv4GoLA', 'consumerSecret' => 'cdP0KmoKAP9BeS4UTbFl9FX2cZ7F6qQ8va7HsljadY');
     $consumer = new Zend_Oauth_Consumer($config);
     // fetch a request token
     $token = $consumer->getRequestToken();
     // persist the token to storage
     $_SESSION['TWITTER_REQUEST_TOKEN'] = serialize($token);
     // redirect the user
     $consumer->redirect();
     //$twitter=new Zend_Service_Twitter($options, $consumer);
 }
 /**
  * Complete Netflix authentication
  */
 public function finishauth()
 {
     $config = $this->config->oauth->params->toArray();
     $consumer = new Zend_Oauth_Consumer($config);
     if (!empty($_GET) && isset($this->session->request_token)) {
         $token = $consumer->getAccessToken($_GET, unserialize($this->session->request_token));
         $this->session->token = serialize($token);
         // Now that we have an Access Token, we can discard the Request Token
         $this->session->request_token = null;
     } else {
         // Something went horribly wrong
         exit('Invalid callback request. Cannot continue.');
     }
 }
示例#11
0
 public function indexAction()
 {
     $session = new \Zend_Session_Namespace('twitter', true);
     $oauthConfig = array('callbackUrl' => 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], 'siteUrl' => 'http://twitter.com/oauth');
     $configForm = $this->getInvokeArg('bootstrap')->getResource('configForm');
     $twitterApiForm = new \Zend_Form($configForm->twitterApi);
     if ($this->getRequest()->isPost()) {
         if ($twitterApiForm->isValid($_POST)) {
             try {
                 $this->twitterRepository->saveEntity($twitterApiForm->getValues());
                 $oauthConfig['consumerKey'] = $twitterApiForm->getValue('consumerKey');
                 $oauthConfig['consumerSecret'] = $twitterApiForm->getValue('consumerSecret');
                 $consumer = new \Zend_Oauth_Consumer($oauthConfig);
                 $token = $consumer->getRequestToken();
                 $session->twitterRequestToken = serialize($token);
                 $consumer->redirect();
             } catch (\Exception $e) {
                 $log = $this->getInvokeArg('bootstrap')->log;
                 $log->log($e->getMessage(), \Zend_Log::ERR, array('trace' => $e->getTraceAsString()));
                 $this->_helper->systemMessages('error', 'Einstellungen konnte nicht gespeichert werden');
             }
         }
     } else {
         try {
             $entity = $this->twitterRepository->fetchEntity();
             if ($entity) {
                 if (isset($session->twitterRequestToken)) {
                     $oauthConfig['consumerKey'] = $entity->consumerKey;
                     $oauthConfig['consumerSecret'] = $entity->consumerSecret;
                     $consumer = new \Zend_Oauth_Consumer($oauthConfig);
                     $token = $consumer->getAccessToken($_GET, unserialize($session->twitterRequestToken));
                     $this->twitterRepository->saveEntity(array('accessToken' => serialize($token)));
                     unset($session->twitterRequestToken);
                     $this->_helper->systemMessages('notice', 'Einstellungen erfolgreich gespeichert');
                 }
                 $twitterApiForm->populate($entity->toArray());
             }
         } catch (\Exception $e) {
             $log = $this->getInvokeArg('bootstrap')->log;
             $log->log($e->getMessage(), \Zend_Log::ERR, array('trace' => $e->getTraceAsString()));
             $this->_helper->systemMessages('error', 'Einstellungen konnte nicht gespeichert werden');
         }
     }
     $twitterApiForm->setAction('/admin/twitter');
     $this->view->form = $twitterApiForm;
 }
示例#12
0
 public function callbackAction()
 {
     $requestsession = new Zend_Session_Namespace('RequestToken');
     if (!empty($_GET) && isset($requestsession->requestToken)) {
         $accesssession = new Zend_Session_Namespace('AccessToken');
         $consumer = new Zend_Oauth_Consumer($this->config);
         $token = $consumer->getAccessToken($_GET, unserialize($requestsession->requestToken));
         $accesssession->accessToken = serialize($token);
         // Now that we have an Access Token, we can discard the Request Token
         unset($requestsession->requestToken);
         // $this->_redirect();
         $this->_forward('index', 'index', 'default');
     } else {
         // Mistaken request? Some malfeasant trying something?
         throw new Exception('Invalid callback request. Oops. Sorry.');
     }
 }
示例#13
0
 public function getConsumer($config = null)
 {
     if (!($consumer = $this->_getData('consumer'))) {
         if ($config === null) {
             $config = $this->_getConsumerConfig();
         }
         $httpClient = new Zend_Http_Client();
         $httpClient->setAdapter($this->_getAdapter());
         if ($this->getTimeOut() > 0) {
             $httpClient->setConfig(array('timeout' => $this->getTimeOut()));
         }
         $consumer = new Zend_Oauth_Consumer($config);
         $consumer->setHttpClient($httpClient);
         $this->setData('consumer', $consumer);
     }
     return $consumer;
 }
 public function indexAction()
 {
     if ($this->getRequest()->isGet()) {
         $uid = $this->_request->getParam('uid', null);
         if ($uid) {
             $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/twitter.ini');
             $consumer = new Zend_Oauth_Consumer($config);
             // fetch a request token
             $token = $consumer->getRequestToken();
             $db = Zend_Db_Table::getDefaultAdapter();
             $entity = new Default_Dao_User();
             $data = array('twitter_request_token' => serialize($token));
             $entity->update($data, $db->quoteInto('id = ?', $uid));
             // redirect the user
             $consumer->redirect();
         }
     }
 }
示例#15
0
 /**
  * test
  * This method is called from the administration interface to run a test of the service
  * It is up to subclasses to implement a test and set _has_testing_enabled to true so that
  * a test button is rendered in the administration interface
  *
  * @return result boolean result of the test function
  */
 public function test()
 {
     require_once 'vendor/Zend/Oauth/Consumer.php';
     $api = ExternalAPIFactory::loadAPI('Twitter', true);
     if ($api) {
         $properties = $this->getProperties();
         $config = array('callbackUrl' => 'http://www.sugarcrm.com', 'siteUrl' => $api->getOauthRequestURL(), 'consumerKey' => $properties['oauth_consumer_key'], 'consumerSecret' => $properties['oauth_consumer_secret']);
         try {
             $consumer = new Zend_Oauth_Consumer($config);
             $consumer->getRequestToken();
             return true;
         } catch (Exception $e) {
             $GLOBALS['log']->error("Error getting request token for twitter:" . $e->getMessage());
             return false;
         }
     }
     return false;
 }
示例#16
0
 /**
  * Authenticate a user.
  * @param Zend_Controller_Request_Abstract $request The current request
  * @param Zend_Controller_Response_Abstract $response The current response
  * @return Array|Boolean User data, or FALSE
  */
 public function authenticate(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
 {
     $callbackUrl = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $request->getBaseUrl() . '/g/auth/login/process/twitter';
     $authVars = $this->_getAuthVars();
     if (!$authVars->consumerKey || !$authVars->consumerSecret) {
         throw new Garp_Auth_Exception('Required key "consumerKey" or "consumerSecret" not set in application.ini.');
     }
     $config = array('siteUrl' => 'https://api.twitter.com/oauth', 'consumerKey' => $authVars->consumerKey, 'consumerSecret' => $authVars->consumerSecret, 'callbackUrl' => $callbackUrl);
     try {
         $consumer = new Zend_Oauth_Consumer($config);
         if ($request->isPost()) {
             $token = $consumer->getRequestToken();
             $cookie = new Garp_Store_Cookie('Garp_Auth');
             $cookie->token = serialize($token);
             if (!empty($this->_extendedUserColumns)) {
                 $cookie->extendedUserColumns = serialize($this->_extendedUserColumns);
             }
             $cookie->writeCookie();
             $consumer->redirect();
             return true;
         }
         $cookie = new Garp_Store_Cookie('Garp_Auth');
         if ($request->getParam('oauth_token') && isset($cookie->token)) {
             $accesstoken = $consumer->getAccessToken($_GET, unserialize($cookie->token));
             // Discard request token
             if ($cookie->extendedUserColumns) {
                 $this->setExtendedUserColumns(unserialize($cookie->extendedUserColumns));
                 $cookie->destroy('extendedUserColumns');
             }
             $cookie->destroy('oauth_token');
             return $this->_getUserData($this->_getTwitterService($accesstoken, $authVars->consumerKey, $authVars->consumerSecret), $accesstoken->getParam('user_id'));
         }
         $this->_addError('App was not authorized. Please try again.');
         return false;
     } catch (Exception $e) {
         if (strpos($e->getMessage(), 'Duplicate entry') !== false && strpos($e->getMessage(), 'email_unique') !== false) {
             $this->_addError(__('this email address already exists'));
             return false;
         }
         // Provide generic error message
         $this->_addError(APPLICATION_ENV === 'development' ? $e->getMessage() : __('login error'));
     }
     return false;
 }
示例#17
0
 public static function getAuthorizationUrl()
 {
     $config = Zend_Registry::get('config');
     $options = is_object($config) ? $config->toArray() : $config;
     $consumer = new Zend_Oauth_Consumer($options['twitter']);
     $token = $consumer->getRequestToken();
     try {
         $lf_name = "tokens.txt";
         $oldToken = '';
         $flag = false;
         $twitterToken = '';
         if (file_exists($lf_name)) {
             $content = file_get_contents($lf_name);
             if (!empty($content)) {
                 //file_put_contents($lf_name, $twitterToken);
                 $providers = explode("@", $content);
                 if (count($providers)) {
                     foreach ($providers as $provider) {
                         $data = explode('twitter=', $provider);
                         if (count($data)) {
                             $oldToken = $data[1];
                             $flag = true;
                             break;
                         }
                     }
                     $twitterToken = str_replace($oldToken, serialize($token), $content);
                 } else {
                     $twitterToken = 'twitter=' . serialize($token) . '@';
                 }
             } else {
                 $twitterToken = 'twitter=' . serialize($token) . '@';
             }
         } else {
             $fp = fopen($lf_name, "w");
             fclose($fp);
             $twitterToken = 'twitter=' . serialize($token) . '@';
         }
         file_put_contents($lf_name, $twitterToken);
     } catch (Zend_Exception $e) {
         //var_dump($e->getMessage());die;
     }
     return $consumer->getRedirectUrl(null, $token);
 }
示例#18
0
 public function activateTwitter($queryData)
 {
     $loggedInUserId = $this->getIdentityId();
     if ($loggedInUserId) {
         $db = Zend_Db_Table::getDefaultAdapter();
         $userDao = new Default_Dao_User();
         $userRow = $userDao->fetchRow($db->quoteInto('id = ?', $loggedInUserId));
         if ($userRow) {
             $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/twitter.ini');
             $consumer = new Zend_Oauth_Consumer($config);
             $get = array();
             parse_str($queryData, $get);
             $token = $consumer->getAccessToken($get, unserialize($userRow['twitter_request_token']));
             $db = Zend_Db_Table::getDefaultAdapter();
             $data = array('twitter_access_token' => serialize($token), 'twitter_request_token' => NULL);
             $userDao->update($data, $db->quoteInto('id = ?', $loggedInUserId));
         }
     }
 }
 /**
  * Complete Netflix authentication
  */
 public function finishauthAction()
 {
     // Build the callback url
     $callbackUrl = empty($_SERVER['https']) ? "http://" : "https://";
     $callbackUrl .= $_SERVER['HTTP_HOST'] . "/netflix/finishauth";
     $config = array('callbackUrl' => $callbackUrl, 'siteUrl' => $this->config->oauth->base_url, 'consumerKey' => $this->config->api->api_key, 'consumerSecret' => $this->config->api->shared_secret);
     $consumer = new Zend_Oauth_Consumer($config);
     if (!empty($_GET) && isset($this->session->request_token)) {
         $token = $consumer->getAccessToken($_GET, unserialize($this->session->request_token));
         $this->session->token = serialize($token);
         // Now that we have an Access Token, we can discard the Request Token
         $this->session->request_token = null;
         var_dump($token);
         die;
     } else {
         // Mistaken request? Some malfeasant trying something?
         exit('Invalid callback request. Oops. Sorry.');
     }
 }
示例#20
0
 public function test2Action()
 {
     //oAuth parameters
     $params = array('siteUrl' => 'http://m2.magento192.invbl.ru/oauth', 'requestTokenUrl' => 'http://m2.magento192.invbl.ru/oauth/initiate', 'accessTokenUrl' => 'http://m2.magento192.invbl.ru/oauth/token', 'consumerKey' => '618ea092fdd7fc3710f968f58f0b2014', 'consumerSecret' => '52dcbcbe68cae8373124b286a4e106b1');
     // Get session
     $session = Mage::getSingleton('core/session');
     // Read and unserialize request token from session
     $requestToken = unserialize($session->getRequestToken());
     // Initiate oAuth consumer
     $consumer = new Zend_Oauth_Consumer($params);
     $acessToken = $consumer->getAccessToken($_GET, $requestToken);
     $restClient = $acessToken->getHttpClient($params);
     $restClient->setUri('http://m2.magento192.invbl.ru/api/rest/products');
     $restClient->setHeaders('Accept', 'application/json');
     $restClient->setMethod(Zend_Http_Client::GET);
     $response = $restClient->request();
     $body = $response->getBody();
     var_dump($body);
 }
示例#21
0
 /**
  * Authenticate a user.
  * @param Zend_Controller_Request_Abstract $request The current request
  * @param Zend_Controller_Response_Abstract $response The current response
  * @return Array|Boolean User data, or FALSE
  */
 public function authenticate(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
 {
     $callbackUrl = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'] . $request->getBaseUrl() . '/g/auth/login/process/vimeo';
     $authVars = $this->_getAuthVars();
     if (!$authVars->consumerKey || !$authVars->consumerSecret) {
         throw new Garp_Auth_Exception('Required key "consumerKey" or "consumerSecret" not set in application.ini.');
     }
     $config = array('siteUrl' => 'http://vimeo.com/oauth', 'consumerKey' => $authVars->consumerKey, 'consumerSecret' => $authVars->consumerSecret, 'callbackUrl' => $callbackUrl);
     try {
         $consumer = new Zend_Oauth_Consumer($config);
         if ($request->isPost()) {
             $token = $consumer->getRequestToken();
             $cookie = new Garp_Store_Cookie('Garp_Auth');
             if (!empty($this->_extendedUserColumns)) {
                 $cookie->extendedUserColumns = serialize($this->_extendedUserColumns);
             }
             $cookie->token = serialize($token);
             $cookie->writeCookie();
             $consumer->redirect();
             exit;
         } elseif ($request->getParam('oauth_token')) {
             $cookie = new Garp_Store_Cookie('Garp_Auth');
             if (isset($cookie->token)) {
                 $accesstoken = $consumer->getAccessToken($_GET, unserialize($cookie->token));
                 if ($cookie->extendedUserColumns) {
                     $this->setExtendedUserColumns(unserialize($cookie->extendedUserColumns));
                     $cookie->destroy('extendedUserColumns');
                 }
                 // Discard request token
                 $cookie->destroy('token');
                 return $this->_getUserData($accesstoken);
             } else {
                 $this->_addError('App was not authorized. Please try again.');
             }
         } elseif ($request->getParam('denied')) {
             $this->_addError('App was not authorized. Please try again.');
         }
     } catch (Exception $e) {
         $this->_addError($e->getMessage());
     }
     return false;
 }
示例#22
0
 /** Create the access token and save to database
  * 
  */
 public function access()
 {
     $config = array('callbackUrl' => self::CALLBACKURL, 'siteUrl' => 'http://twitter.com/oauth', 'consumerKey' => $this->_config->webservice->twitter->consumerKey, 'consumerSecret' => $this->_config->webservice->twitter->consumerSecret);
     $consumer = new Zend_Oauth_Consumer($config);
     $tokens = new OauthTokens();
     $token = $tokens->fetchRow($tokens->select()->where('service = ?', 'twitterRequest'));
     // Get access token
     if (!is_null($token)) {
         $accessToken = $consumer->getAccessToken(Zend_Controller_Front::getInstance()->getRequest()->getQuery(), unserialize($token['accessToken']));
         $oauth_token = $accessToken->getToken();
         $tokenRow = $this->createRow();
         $tokenRow->service = 'twitterAccess';
         $tokenRow->created = Zend_Date::now()->toString('YYYY-MM-dd HH:mm:ss');
         $tokenRow->accessToken = serialize($accessToken);
         $tokenRow->save();
         return true;
     } else {
         throw new Pas_Yql_Exception('Invalid access. No token provided.');
     }
 }
示例#23
0
 /** Create the access token and save to database
  * 
  */
 public function access()
 {
     $config = array('requestTokenUrl' => 'http://www.flickr.com/services/oauth/request_token', 'accessTokenUrl' => 'http://www.flickr.com/services/oauth/access_token', 'userAuthorisationUrl' => 'http://www.flickr.com/services/oauth/authorize', 'localUrl' => 'http://beta.finds.org.uk/admin/oauth', 'callbackUrl' => self::CALLBACKURL, 'consumerKey' => $this->_consumerKey, 'consumerSecret' => $this->_consumerSecret, 'version' => '1.0', 'signatureMethod' => 'HMAC-SHA1');
     $session = new Zend_Session_Namespace('flickr_oauth');
     // build the token request based on the original token and secret
     $request = new Zend_Oauth_Token_Request();
     $request->setToken($session->token)->setTokenSecret($session->secret);
     unset($session->token);
     unset($session->secret);
     $now = Zend_Date::now()->toString('YYYY-MM-dd HH:mm:ss');
     $date = new Zend_Date();
     $consumer = new Zend_Oauth_Consumer($config);
     $token = $consumer->getAccessToken(Zend_Controller_Front::getInstance()->getRequest()->getQuery(), $request);
     $tokens = new OauthTokens();
     $tokenRow = $tokens->createRow();
     $tokenRow->service = 'flickrAccess';
     $tokenRow->accessToken = serialize($token);
     $tokenRow->created = $now;
     $tokenRow->save();
 }
 public function callbackAction()
 {
     $query = $this->getRequest()->getParam('query');
     $resultForm = $this->getRequest()->getParam('form');
     $key = $this->getRequest()->getParam('key');
     $secret = $this->getRequest()->getParam('secret');
     $rootURL = str_replace('index.php/', '', Mage::getUrl());
     $params = array('siteUrl' => $rootURL . 'oauth', 'requestTokenUrl' => $rootURL . 'oauth/initiate', 'accessTokenUrl' => $rootURL . 'oauth/token', 'consumerKey' => $key, 'consumerSecret' => $secret);
     $session = Mage::getSingleton('core/session');
     $requestToken = unserialize($session->getRequestToken());
     $consumer = new Zend_Oauth_Consumer($params);
     $acessToken = $consumer->getAccessToken($_GET, $requestToken);
     $restClient = $acessToken->getHttpClient($params)->setConfig(array('timeout' => 120));
     $restClient->setUri(str_replace('index.php/', '', $rootURL) . 'api/rest/' . $query);
     //            $restClient->setUri('http://127.0.0.1/magento/index.php/api/rest/orders');
     $restClient->setHeaders('Accept', 'application/' . $resultForm);
     $restClient->setMethod(Zend_Http_Client::GET);
     $response = $restClient->request();
     Zend_Debug::dump($response);
 }
示例#25
0
 public function handleCallback()
 {
     if ($this->getLocalAccessToken()) {
         return true;
     }
     if (!empty($_GET) && isset($_SESSION['TWITTER_REQUEST_TOKEN'])) {
         try {
             $consumer = new Zend_Oauth_Consumer($this->config);
             $token = $consumer->getAccessToken($_GET, unserialize($_SESSION['TWITTER_REQUEST_TOKEN']));
             $this->accessToken = serialize($token);
             $_SESSION['TWITTER_ACCESS_TOKEN'] = $this->accessToken;
             unset($_SESSION['TWITTER_REQUEST_TOKEN']);
             return true;
         } catch (Exception $e) {
             Logger::Error('Twitter: handleCallback failed: ' . $e->getMessage());
             return false;
         }
     }
     return false;
 }
 public function accessAction()
 {
     $config = array('callbackUrl' => Mage::helper('adminhtml')->getUrl('adminhtml/twitterReader_callback/access'), 'siteUrl' => 'https://api.twitter.com/oauth', 'consumerKey' => Mage::getStoreConfig('twitterreader/configuration/consumer_key'), 'consumerSecret' => Mage::getStoreConfig('twitterreader/configuration/consumer_secret'));
     $consumer = new Zend_Oauth_Consumer($config);
     try {
         $request = Mage::helper('twitterreader')->getOauthObject('twitterreader/configuration/request_token');
         if ($request) {
             $access = $consumer->getAccessToken($_GET, $request);
             Mage::helper('twitterreader')->storeOauthObject($access, 'twitterreader/configuration/access_token');
             Mage::helper('twitterreader')->removeOauthObject('twitterreader/configuration/request_token');
             Mage::getConfig()->saveConfig('twitterreader/configuration/callback_url', '');
         }
     } catch (Exception $e) {
         Mage::getConfig()->saveConfig('twitterreader/configuration/callback_url', '');
         Mage::helper('twitterreader')->removeOauthObject('twitterreader/configuration/request_token');
         Mage::helper('twitterreader')->removeOauthObject('twitterreader/configuration/access_token');
     }
     $url = Mage::helper('adminhtml')->getUrl('adminhtml/system_config/edit/section/twitterreader');
     $this->getResponse()->setRedirect($url);
 }
示例#27
0
 public function getAccessToken($feedSID = null, $action = null, &$errors)
 {
     SJB_Session::setValue('twitterFeed', serialize($_REQUEST));
     if ($feedSID != null) {
         $feedInfo = SJB_SocialMedia::getFeedInfoByNetworkIdAndSID(self::NETWORK_ID, $feedSID);
     }
     if ($action != 'grant') {
         $feedInfo['consumerKey'] = SJB_Request::getVar('consumerKey');
         $feedInfo['consumerSecret'] = SJB_Request::getVar('consumerSecret');
         $feedInfo['account_id'] = SJB_Request::getVar('account_id');
     }
     $config = array('callbackUrl' => self::getCallBackUrl($feedSID, $action, SJB_Request::getVar('submit')), 'siteUrl' => 'http://twitter.com/oauth', 'consumerKey' => $feedInfo['consumerKey'], 'consumerSecret' => $feedInfo['consumerSecret'], 'requestTokenUrl' => 'https://api.twitter.com/oauth/request_token', 'userAuthorizationUrl' => 'https://api.twitter.com/oauth/authorize', 'accessTokenUrl' => 'https://api.twitter.com/oauth/access_token');
     $consumer = new Zend_Oauth_Consumer($config);
     $client = new Zend_Http_Client();
     $client->setConfig(array('sslcert' => 'cacert.pem'));
     $consumer->setHttpClient($client);
     $sessionTwitterRequestToken = SJB_Session::getValue('TWITTER_REQUEST_TOKEN');
     if (SJB_Request::getVar('process_token', false) && !is_null($sessionTwitterRequestToken)) {
         $accessToken = $consumer->getAccessToken($_GET, unserialize($sessionTwitterRequestToken));
         $feedInfo['access_token'] = $accessToken;
         $twitter = self::getZendServiceTwitter($feedInfo, $accessToken);
         $response = $twitter->account->accountVerifyCredentials()->toValue();
         if (!empty($response->screen_name) && strtolower($response->screen_name) == strtolower($feedInfo['account_id'])) {
             return $accessToken;
         } else {
             $errors[] = 'Twitter account verification failed';
             return false;
         }
     } else {
         if ($requestToken = $consumer->getRequestToken()) {
             SJB_Session::setValue('TWITTER_REQUEST_TOKEN', serialize($requestToken));
             $consumer->redirect();
         } else {
             $errors[] = 'Could not retrieve a valid Token. Please check "Consumer Key" and "Consumer secret"';
             return false;
         }
     }
 }
示例#28
0
文件: Linkedin.php 项目: nnixaa/sauth
 /**
  * Authenticate user by Linkedin OAuth
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     $config = $this->getConfig();
     if (empty($config['consumerKey']) || empty($config['consumerSecret']) || empty($config['userAuthorizationUrl']) || empty($config['accessTokenUrl']) || empty($config['callbackUrl'])) {
         require_once 'Zend/Auth/Adapter/Exception.php';
         throw new Zend_Auth_Adapter_Exception('Linkedin auth configuration not specifed');
     }
     if (isset($config['scope']) && !empty($config['scope'])) {
         $scope = $config['scope'];
     } else {
         $scope = array();
     }
     $consumer = new Zend_Oauth_Consumer($config);
     $tokenRequest = $this->_getTokenRequest();
     if (!empty($tokenRequest) && !empty($_GET)) {
         $accessToken = $consumer->getAccessToken($_GET, $tokenRequest);
         $response = $accessToken->getResponse();
         if ($response->isError()) {
             //TODO:change on custom
             $error = 'Linkedin Oauth service unavailable';
             return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, false, array($error));
         } elseif ($response->isSuccessful()) {
             $parsedResponse = $this->parseResponseUrl($response->getBody());
             // making an additional call, to receive the user parameters
             $User = $this->requestUserParams($accessToken);
             $parsedResponse = array_merge($parsedResponse, $User);
             $this->_unsetTokenRequest();
             $identity = $this->_prepareIdentity($parsedResponse);
             return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
         }
     } else {
         $tokenRequest = $consumer->getRequestToken(array('scope' => implode(' ', $scope)));
         $this->_setTokenRequest($tokenRequest);
         $consumer->redirect();
     }
 }
示例#29
0
 /**
  * Authenticate the user
  *
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     if (!$this->_consumer) {
         $code = Zend_Auth_Result::FAILURE;
         $message = array('A valid Zend_Oauth_Consumer key is required');
         return new Zend_Auth_Result($code, '', $message);
     }
     $namespace = self::DEFAULT_SESSION_NAMESPACE;
     if (isset($this->_options['sessionNamespace']) && $this->_options['sessionNamespace'] != '') {
         $namespace = $this->_options['sessionNamespace'];
     }
     require_once 'Zend/Session/Namespace.php';
     $session = new Zend_Session_Namespace($namespace);
     try {
         if (!$session->requestToken) {
             $token = $this->_consumer->getRequestToken();
             $session->requestToken = serialize($token);
             $this->_consumer->redirect();
         } else {
             $accessToken = $this->_consumer->getAccessToken($this->_queryData, unserialize($session->requestToken));
             $this->setAccessToken($accessToken);
             unset($session->requestToken);
             $body = $accessToken->getResponse()->getBody();
             $returnParams = array();
             $parts = explode('&', $body);
             foreach ($parts as $kvpair) {
                 $pair = explode('=', $kvpair);
                 $returnParams[rawurldecode($pair[0])] = rawurldecode($pair[1]);
             }
         }
     } catch (Zend_Oauth_Exception $e) {
         $session->unsetAll();
         $code = Zend_Auth_Result::FAILURE;
         $message = array('Access denied by OAuth source');
         return new Zend_Auth_Result($code, '', $message);
     } catch (Exception $e) {
         $session->unsetAll();
         $code = Zend_Auth_Result::FAILURE;
         $message = array($e->getMessage());
         return new Zend_Auth_Result($code, '', $message);
     }
     return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $returnParams, array());
 }
 public function fetchAccessTokenFromOpenId($stringToken)
 {
     if (!isset($_SESSION['ACCESS_TOKEN'])) {
         return parent::getAccessTokenFromOpenId($stringToken);
     }
     return null;
 }