Ejemplo n.º 1
0
 /**
  * Ensures everything works as expected.
  */
 public function testGetOauthCallbackUrl()
 {
     $accountService = new Conjoon_Service_Twitter_AccountService();
     foreach ($this->input as $expected => $input) {
         $this->assertSame($expected, $accountService->getOauthCallbackUrl($input));
     }
 }
 /**
  * This is the action to which Twitter redirects once the user has authorized
  * conjoon to use a specific Twitter account.
  * Necessary configuration will be stored in the session. The Session parameters
  * oauthToken and oauthTokenSecret must be available.
  */
 public function authorizeOkayAction()
 {
     $this->view->title = "conjoon - Twitter Account Authorization";
     /**
      * @see Zend_Session_Namespace
      */
     require_once 'Zend/Session/Namespace.php';
     /**
      * @see Conjoon_Keys
      */
     require_once 'Conjoon/Keys.php';
     $sessionOauth = new Zend_Session_Namespace(Conjoon_Keys::SESSION_SERVICE_TWITTER_OAUTH);
     if (!isset($sessionOauth->oauthToken) || !isset($sessionOauth->oauthTokenSecret)) {
         die("invalid data.");
     }
     /**
      * @see Zend_Oauth_Consumer
      */
     require_once 'Zend/Oauth/Consumer.php';
     $config = Zend_Registry::get(Conjoon_Keys::REGISTRY_CONFIG_OBJECT);
     /**
      * @see Conjoon_Modules_Default_Registry_Facade
      */
     require_once 'Conjoon/Modules/Default/Registry/Facade.php';
     $registry = Conjoon_Modules_Default_Registry_Facade::getInstance();
     $userId = $this->_helper->registryAccess()->getUserId();
     $port = $registry->getValueForKeyAndUserId('/server/environment/port', $userId);
     $protocol = $registry->getValueForKeyAndUserId('/server/environment/protocol', $userId);
     $host = $registry->getValueForKeyAndUserId('/server/environment/host', $userId);
     /**
      * @see Conjoon_Service_Twitter_AccountService
      */
     require_once 'Conjoon/Service/Twitter/AccountService.php';
     $accountService = new Conjoon_Service_Twitter_AccountService();
     $callbackUrl = $accountService->getOauthCallbackUrl(array('port' => $port, 'protocol' => $protocol, 'host' => $host, 'baseUrl' => $config->environment->base_url, 'oauthCallbackUrl' => $config->application->twitter->oauth->callbackUrl));
     $siteUrl = $config->application->twitter->oauth->siteUrl;
     $consumerKey = $config->application->twitter->oauth->consumerKey;
     $consumerSecret = $config->application->twitter->oauth->consumerSecret;
     $options = array('callbackUrl' => $callbackUrl, 'siteUrl' => $siteUrl, 'consumerKey' => $consumerKey, 'consumerSecret' => $consumerSecret);
     $consumer = new Zend_Oauth_Consumer($options);
     require_once 'Zend/Oauth/Token/Request.php';
     $requestToken = new Zend_Oauth_Token_Request();
     $requestToken->setParams(array('oauth_token' => $sessionOauth->oauthToken, 'oauth_token_secret' => $sessionOauth->oauthTokenSecret));
     $accessToken = $consumer->getAccessToken($_GET, $requestToken);
     require_once 'Zend/Oauth/Token/Access.php';
     $screenName = $accessToken->getParam('screen_name');
     $userId = $accessToken->getParam('user_id');
     $oauthToken = $accessToken->getParam('oauth_token');
     $oauthTokenSecret = $accessToken->getParam('oauth_token_secret');
     require_once 'Conjoon/Service/Twitter/Proxy.php';
     /**
      * @see Conjoon_Modules_Default_Registry_Facade
      */
     require_once 'Conjoon/Modules/Default/Registry/Facade.php';
     $protocolContext = Conjoon_Modules_Default_Registry_Facade::getInstance()->getValueForKeyAndUserId('/server/environment/protocol', $this->_helper->registryAccess()->getUserId());
     $twitter = new Conjoon_Service_Twitter_Proxy(array('screen_name' => $screenName, 'user_id' => $userId, 'oauth_token' => $oauthToken, 'oauth_token_secret' => $oauthTokenSecret, 'consumer_key' => $consumerKey, 'consumer_secret' => $consumerSecret, 'protocol_context' => $protocolContext));
     $dto = $twitter->accountVerifyCredentials();
     if ($dto instanceof Conjoon_Error) {
         $this->view->success = false;
         $this->view->error = $dto->getDto();
         $this->view->connectionFailure = true;
         return;
     }
     /**
      * @ticket CN-675
      * We could possibly remove this due to CN-676, but decided to leave it
      * in here to double check... doesn't hurt
      */
     if ($dto->twitterId != $userId) {
         throw new RuntimeException("userId does not equal to user id from Twitter API Service");
     }
     unset($sessionOauth->oauthToken);
     unset($sessionOauth->oauthTokenSecret);
     $dto->oauthToken = $oauthToken;
     $dto->oauthTokenSecret = $oauthTokenSecret;
     $this->view->success = true;
     $this->view->account = $dto;
 }