Example #1
0
 /**
  * Store the user's profile data in the database, if it doesn't exist yet.
  * @param Zend_Oauth_Token_Access $accessToken
  * @return Void
  */
 protected function _getUserData(Zend_Oauth_Token_Access $accessToken)
 {
     $authVars = $this->_getAuthVars();
     $token = $accessToken->getToken();
     $tokenSecret = $accessToken->getTokenSecret();
     $vimeoService = new Garp_Service_Vimeo_Pro($authVars->consumerKey, $authVars->consumerSecret, $token, $tokenSecret);
     $userDataFromVimeo = $vimeoService->people->getInfo($token);
     $id = $userDataFromVimeo['id'];
     $ini = Zend_Registry::get('config');
     $sessionColumns = Zend_Db_Select::SQL_WILDCARD;
     if (!empty($ini->auth->login->sessionColumns)) {
         $sessionColumns = $ini->auth->login->sessionColumns;
         $sessionColumns = explode(',', $sessionColumns);
     }
     $userModel = new Model_User();
     $userConditions = $userModel->select()->from($userModel->getName(), $sessionColumns);
     $model = new Model_AuthVimeo();
     $model->bindModel('Model_User', array('conditions' => $userConditions));
     $userData = $model->fetchRow($model->select()->where('vimeo_id = ?', $id));
     if (!$userData || !$userData->Model_User) {
         $userData = $model->createNew($id, $accessToken, $this->_mapProperties($userDataFromVimeo));
     } else {
         $model->getObserver('Authenticatable')->updateLoginStats($userData->user_id);
         $userData = $userData->Model_User;
     }
     return $userData;
 }
Example #2
0
 function __construct($options = array())
 {
     $this->_twitter = Zend_Registry::get('Zkernel_Twitter');
     if (isset($this->_twitter[$this->_name]['service'])) {
         $this->_service = $this->_twitter[$this->_name]['service'];
     } else {
         $consumer_key = isset($options['consumer_key']) ? $options['consumer_key'] : $this->_twitter['consumer_key'];
         $consumer_secret = isset($options['consumer_secret']) ? $options['consumer_secret'] : $this->_twitter['consumer_secret'];
         $callback_url = isset($options['callback_url']) ? $options['callback_url'] : $this->_twitter['callback_url'];
         $token = isset($options['token']) ? $options['token'] : $this->_twitter['token'];
         $token_secret = isset($options['token_secret']) ? $options['token_secret'] : $this->_twitter['token_secret'];
         $at = new Zend_Oauth_Token_Access();
         $at->setToken($token);
         $at->setTokenSecret($token_secret);
         $opt = array('accessToken' => $at);
         if ($consumer_key) {
             $opt['consumerKey'] = $consumer_key;
         }
         if ($consumer_secret) {
             $opt['consumerSecret'] = $consumer_secret;
         }
         if ($callback_url) {
             $opt['callbackUrl'] = $callback_url;
         }
         $opt['oauthOptions'] = array('consumerKey' => $opt['consumerKey'], 'consumerSecret' => $opt['consumerSecret']);
         $this->_service = new Zkernel_Service_Twitter($opt);
         $this->_twitter[$this->_name]['service'] = $this->_service;
         Zend_Registry::set('Zkernel_Twitter', $this->_twitter);
     }
 }
Example #3
0
 public function makeAccessToken()
 {
     $token = new Zend_Oauth_Token_Access();
     $token->setToken($this->token[0]);
     $token->setTokenSecret($this->token[1]);
     return $token;
 }
Example #4
0
	private function _getClient($uri)
	{
		$client = new Zend_Http_Client('http://api.dropbox.com/0/token');
		$client->setParameterPost(array(
			'oauth_consumer_key' => self::DB_CONSUMER_KEY,
			'oauth_consumer_secret' => self::DB_CONSUMER_SECRET,
			'email' => self::DB_USER,
			'password' => self::DB_PASSWORD,
		));

		$response = $client->request('POST');
		$data = json_decode($response->getBody());
		$token = $data->token;
		$secret = $data->secret;

		$tokenObject = new Zend_Oauth_Token_Access();
		$tokenObject->setToken($token);
		$tokenObject->setTokenSecret($secret);
		
		$options = array(
			'consumerKey'    => self::DB_CONSUMER_KEY,
			'consumerSecret' => self::DB_CONSUMER_SECRET,
		);
		return $tokenObject->getHttpClient($options, $uri);
	}
Example #5
0
 /**
  * Make a call using Oauth client
  * @param String
  */
 protected function request($url, $method = Zend_Http_Client::GET)
 {
     $http = $this->token->getHttpClient($this->oauthOptions);
     $http->setUri($url);
     $http->setMethod($method);
     switch ($method) {
         case Zend_Http_Client::PUT:
             //$this->client->setParameterPost('access_token',$this->access_token);
             //$this->client->setEncType(self::ENC_FORMDATA);
             break;
         case Zend_Http_Client::POST:
             //$this->client->setParameterPost('access_token', $this->access_token);
             break;
         case Zend_Http_Client::GET:
         case Zend_Http_Client::DELETE:
         default:
             //$this->client->setParameterGet('access_token',$this->access_token);
             break;
     }
     try {
         $response = $http->request();
         $data = $response->getBody();
     } catch (Zend_Http_Client_Exception $e) {
         // Return Exception as JSON
         $data = new stdClass();
         $data->code = $e->getCode();
         $data->error = $e->getMessage();
     }
     return $data;
 }
Example #6
0
/**
 * Authenticate to the Google Docs API using OAuth.
 * 
 * @param  string $consumerKey The OAuth consumer key used to authenticate to Google.
 * @param  string $consumerSecret The OAuth consumer secret used to authenticate to Google.
 *
 * @return Zend_Oauth_Client object
 */
function AuthenticateToGoogle($consumerKey, $consumerSecret)
{
    $oauthOptions = array('requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER, 'version' => '1.0', 'signatureMethod' => 'HMAC-SHA1', 'consumerKey' => $consumerKey, 'consumerSecret' => $consumerSecret);
    //$consumer = new Zend_Oauth_Consumer($oauthOptions);
    $token = new Zend_Oauth_Token_Access();
    $httpClient = $token->getHttpClient($oauthOptions);
    return $httpClient;
}
 public function storeAccessToken(Zend_Oauth_Token_Access $accessToken)
 {
     $query = "INSERT INTO group_provider_user_oauth (provider_id, user_id, oauth_token, oauth_secret)\n        VALUES(?, ?, ?, ?)\n        ON DUPLICATE KEY UPDATE oauth_token=VALUES(oauth_token), oauth_secret=VALUES(oauth_secret)";
     $params = array($this->_providerId, $this->_userId, $accessToken->getToken(), $accessToken->getTokenSecret());
     $statement = $this->_connection->prepare($query);
     $statement->execute($params);
     return true;
 }
Example #8
0
 public function __construct()
 {
     // Config path
     $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
     $twitterOauth = $config->service->twitter->oauth;
     $accessToken = new Zend_Oauth_Token_Access();
     $accessToken->setToken($twitterOauth->oauthToken)->setTokenSecret($twitterOauth->oauthTokenSecret);
     $this->options = array('username' => $twitterOauth->username, 'accessToken' => $accessToken, 'oauthOptions' => array('consumerKey' => $twitterOauth->consumerKey, 'consumerSecret' => $twitterOauth->consumerSecret));
 }
Example #9
0
 /**
  * Store a new user. This creates a new AuthVimeo record, but also
  * a new user record.
  * @param String $vimeoId Vimeo user id
  * @param Zend_Oauth_Token_Access $accessToken oAuth access token
  * @param Array $props Properties received from Vimeo
  * @return Garp_Db_Table_Row The new user data
  */
 public function createNew($vimeoId, Zend_Oauth_Token_Access $accessToken, array $props)
 {
     // first save the new user
     $userModel = new Model_User();
     $userId = $userModel->insert($props);
     $userData = $userModel->find($userId)->current();
     $this->insert(array('vimeo_id' => $vimeoId, 'access_token' => $accessToken->getToken(), 'access_token_secret' => $accessToken->getTokenSecret(), 'user_id' => $userId));
     $this->getObserver('Authenticatable')->updateLoginStats($userId);
     return $userData;
 }
Example #10
0
 /**
  * Get the twitter client
  *
  * @return Zend_Service_Twitter
  */
 protected function _getClient()
 {
     if (null == $this->_client) {
         $access = new Zend_Oauth_Token_Access();
         $access->setToken($this->_getConfig()->getTwitterAuthToken())->setTokenSecret($this->_getConfig()->getTwitterTokenSecret());
         $params = array('accessToken' => $access, 'consumerKey' => $this->_getConfig()->getTwitterConsumerKey(), 'consumerSecret' => $this->_getConfig()->getTwitterConsumerSecret());
         $this->_client = new Zend_Service_Twitter($params);
     }
     return $this->_client;
 }
Example #11
0
 private function __construct()
 {
     $frontendOptions = ['lifetime' => 60, 'automatic_serialization' => true];
     $backendOptions = ['cache_dir' => substr(APPLICATION_PATH, 0, strrpos(APPLICATION_PATH, '/')) . '/data/cache/'];
     $this->_cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
     $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
     $options = $bootstrap->getOptions();
     $accessToken = new Zend_Oauth_Token_Access();
     $accessToken->setToken($options['twitter']['accessToken']);
     $accessToken->setTokenSecret($options['twitter']['accessTokenSecret']);
     $this->_twitter = new Zend_Service_Twitter(['username' => 'radaspona', 'accessToken' => $accessToken, 'oauthOptions' => ['consumerKey' => $options['twitter']['consumerKey'], 'consumerSecret' => $options['twitter']['consumerKeySecret']]]);
 }
Example #12
0
 /**
  * Gets the Twitter service object for a token
  *
  * @param string|Zend_Oauth_Token_Access $token Access token object or access token string
  * @param null|string $secret Access token secret if token is provided as string
  *
  * @return Zend_Service_Twitter
  */
 public static function getService($token, $secret, $username = '')
 {
     $options = XenForo_Application::getOptions();
     if ($token instanceof Zend_Oauth_Token_Access) {
         $accessToken = $token;
     } else {
         $accessToken = new Zend_Oauth_Token_Access();
         $accessToken->setToken($token);
         $accessToken->setTokenSecret($secret);
     }
     return new DigitalPointSocialBar_Service_Twitter(array('username' => $username, 'accessToken' => $accessToken, 'oauthOptions' => array('consumerKey' => trim($options->dpTwitterAppKey), 'consumerSecret' => trim($options->twitterAppSecret))));
 }
Example #13
0
 /**
  * Gets the Twitter service object for a token
  *
  * @param string|Zend_Oauth_Token_Access $token Access token object or access token string
  * @param null|string $secret Access token secret if token is provided as string
  *
  * @return Zend_Service_Twitter
  */
 public static function getService($token, $secret = null)
 {
     $options = XenForo_Application::getOptions();
     Zend_Oauth::setHttpClient(XenForo_Helper_Http::getClient('https://api.twitter.com/oauth'));
     if ($token instanceof Zend_Oauth_Token_Access) {
         $accessToken = $token;
     } else {
         $accessToken = new Zend_Oauth_Token_Access();
         $accessToken->setToken($token);
         $accessToken->setTokenSecret($secret);
     }
     return new Zend_Service_Twitter(array('accessToken' => $accessToken, 'oauthOptions' => array('consumerKey' => trim($options->twitterAppKey), 'consumerSecret' => trim($options->twitterAppSecret)), 'httpClientOptions' => XenForo_Helper_Http::getExtraHttpClientOptions('https://api.twitter.com/oauth')));
 }
Example #14
0
 /**
  * Convenience method to run the command
  *
  * @param string $name
  * @param mixed $args
  * @return boolean
  */
 public function onCommand($name, $args)
 {
     if (strcasecmp($name, $this->_commandName) !== 0) {
         return FALSE;
     }
     //Do the command
     if (!empty($args['text'])) {
         $token = new Zend_Oauth_Token_Access();
         $token->setToken(App_DI_Container::get('ConfigObject')->twitter->access_token);
         $token->setTokenSecret(App_DI_Container::get('ConfigObject')->twitter->access_token_secret);
         $twitter = new Zend_Service_Twitter(array('username' => App_DI_Container::get('ConfigObject')->twitter->username, 'accessToken' => $token));
         $response = $twitter->status->update($args['text']);
         return $response->isSuccess();
     }
     return FALSE;
 }
Example #15
0
 public function revoke()
 {
     if ($this->_accessToken && $this->_accessToken instanceof Zend_Oauth_Token_Access) {
         $client = $this->_accessToken->getHttpClient($this->_options);
         // Set LinkedIn URI
         $client->setUri($this->_options['invalidateTokenUrl']);
         $client->setMethod(Zend_Http_Client::GET);
         $response = $client->request();
         return $response->getMessage() == 'OK' ? true : false;
     }
 }
 /**
  * Show my tweets 
  */
 public function myfeedAction()
 {
     $params = $this->getRequest()->getParams();
     $this->_helper->layout->disableLayout();
     // Get the Twitter params from config
     $userToken = $this->config->api->access_token;
     $userSecret = $this->config->api->token_secret;
     $appConsumerKey = $this->config->api->consumer_key;
     $appConsumerSecret = $this->config->api->consumer_secret;
     // Create the Oauth Token
     $token = new Zend_Oauth_Token_Access();
     $token->setToken($userToken)->setTokenSecret($userSecret);
     // Create the Twitter Service object
     $options = array('accessToken' => $token, 'consumerKey' => $appConsumerKey, 'consumerSecret' => $appConsumerSecret);
     $twitter = new Zend_Service_Twitter($options);
     // Get my tweets
     $tweets = $twitter->statusFriendsTimeline();
     var_dump($tweets);
     die;
     // Send JSON to browser
     $this->getResponse()->setHeader(Zend_Http_Client::CONTENT_TYPE, 'application/json')->appendBody(json_encode($tweets));
 }
Example #17
0
 /**
  * @method oAuth
  * @static
  * @param {string} $provider Currently only supports the value "facebook".
  * @return {Zend_Oauth_Client}
  * @throws {Users_Exception_NotLoggedIn} If user is not logged in
  */
 static function oAuth($provider)
 {
     $nativeuser = self::loggedInUser();
     if (!$nativeuser) {
         throw new Users_Exception_NotLoggedIn();
     }
     #Set up oauth options
     $oauthOptions = Q_Config::expect('Users', 'oAuthProviders', $provider, 'oAuth');
     $customOptions = Q_Config::get('Users', 'oAuthProviders', $provider, 'custom', null);
     #If the user already has a token in our DB:
     $appuser = new Users_AppUser();
     $appuser->userId = $nativeuser->id;
     $appuser->provider = $provider;
     $appuser->appId = Q_Config::expect('Users', 'oAuthProviders', $provider, 'appId');
     if ($appuser->retrieve('*', true)) {
         $zt = new Zend_Oauth_Token_Access();
         $zt->setToken($appuser->access_token);
         $zt->setTokenSecret($appuser->session_secret);
         return $zt->getHttpClient($oauthOptions);
     }
     #Otherwise, obtain a token from provider:
     $consumer = new Zend_Oauth_Consumer($oauthOptions);
     if (isset($_GET['oauth_token']) && isset($_SESSION[$provider . '_request_token'])) {
         $token = $consumer->getAccessToken($_GET, unserialize($_SESSION[$provider . '_request_token']));
         $_SESSION[$provider . '_access_token'] = serialize($token);
         $_SESSION[$provider . '_request_token'] = null;
         #Save tokens to database
         $appuser->access_token = $token->getToken();
         $appuser->session_secret = $token->getTokenSecret();
         $appuser->save();
         return $token->getHttpClient($oauthOptions);
     } else {
         $token = $consumer->getRequestToken($customOptions);
         $_SESSION[$provider . '_request_token'] = serialize($token);
         $consumer->redirect();
         return null;
     }
 }
Example #18
0
 /**
  * Returns either a cached list of twitter accounts for a user, or
  * the accounts out of the database which will immediately be validated
  * against the twitter service (network access)
  *
  * @param array $options An associative array with the following
  * key value/pairs:
  *   - userId: the id of the user to fetch al twitter accounts for
  * @param Conjoon_BeanContext_Decoratable $model
  *
  * @return Array anr array with instances of
  * Conjoon_Modules_Service_Twitter_Account_Model_Account
  */
 protected function _build(array $options, Conjoon_BeanContext_Decoratable $model)
 {
     $userId = $options['userId'];
     /**
      * @see Conjoon_BeanContext_Decorator
      */
     require_once 'Conjoon/BeanContext/Decorator.php';
     $decoratedModel = new Conjoon_BeanContext_Decorator($model);
     $accounts = $decoratedModel->getAccountsForUserAsDto($userId);
     /**
      * @see Conjoon_Service_Twitter
      */
     require_once 'Conjoon/Service/Twitter.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', $userId);
     for ($i = 0, $len = count($accounts); $i < $len; $i++) {
         $dto =& $accounts[$i];
         try {
             /**
              * @todo move to separate model
              */
             /**
              * @see Zend_Oauth_Token_Access
              */
             require_once 'Zend/Oauth/Token/Access.php';
             $accessToken = new Zend_Oauth_Token_Access();
             $accessToken->setParams(array('oauth_token' => $dto->oauthToken, 'oauth_token_secret' => $dto->oauthTokenSecret, 'user_id' => $dto->twitterId, 'screen_name' => $dto->name));
             $twitter = new Conjoon_Service_Twitter(array('username' => $dto->name, 'accessToken' => $accessToken));
             $response = $twitter->userShow($dto->name);
             $dto->twitterId = $response->id_str;
             $dto->twitterName = $response->name;
             $dto->twitterScreenName = $response->screen_name;
             $dto->twitterLocation = $response->location;
             $dto->twitterProfileImageUrl = $protocolContext === 'https' ? $response->profile_image_url_https : $response->profile_image_url;
             $dto->twitterUrl = $response->url;
             $dto->twitterProtected = $response->protected;
             $dto->twitterDescription = $response->description;
             $dto->twitterFollowersCount = $response->followers_count;
         } catch (Exception $e) {
             Conjoon_Log::log("Could not retrieve account information for twitter " . "account: \"" . $e->getMessage() . "\"", Zend_Log::INFO);
             // ignore
         }
         $dto->oauthTokenSecret = str_pad("", strlen($dto->oauthTokenSecret), '*');
     }
     return $accounts;
 }
Example #19
0
    /**
     * Fetches a secured oauth url and returns the response body.
     *
     * @param string $uri
     * @param mixed $arguments
     * @param string $method
     * @param array $httpHeaders
     * @return string
     */
    public function fetch($uri, $arguments = array(), $method = 'GET', $httpHeaders = array())
    {
        $token = $this->OAuth->getToken();
        if (!is_a($token, "Zend_Oauth_Token")) {
            if (is_a($this->zend_oauth_token, "Zend_Oauth_Token_Access")) {
                $token = $this->zend_oauth_token;
            } else {
                $token = new Zend_Oauth_Token_Access();
                $token->setToken($this->oauth_token);
                $token->setTokenSecret($this->oauth_token_secret);
            }
        }
        /* @var $token Zend_Oauth_Token_Access */
        $oauthOptions = array('consumerKey' => $this->consumerKey, 'signatureMethod' => "HMAC-SHA1", 'consumerSecret' => $this->OAuth->getConsumerSecret());
        $config = array("timeout" => 15);
        /* @var $consumerRequest Zend_Oauth_Client */
        $consumerRequest = $token->getHttpClient($oauthOptions);
        $consumerRequest->setMethod($method);
        if (is_array($arguments)) {
            $consumerRequest->setUri($uri);
            if ($method == "GET") {
                foreach ($arguments as $param => $value) {
                    $consumerRequest->setParameterGet($param, $value);
                }
            } else {
                foreach ($arguments as $param => $value) {
                    $consumerRequest->setParameterPost($param, $value);
                }
            }
        } elseif (is_string($arguments)) {
            preg_match("/\\?file=(.*)\$/i", $uri, $matches);
            if (isset($matches[1])) {
                $uri = str_replace($matches[0], "", $uri);
                $filename = $matches[1];
                $uri = Zend_Uri::factory($uri);
                $uri->addReplaceQueryParameters(array("file" => $filename));
                $consumerRequest->setParameterGet("file", $filename);
            }
            $consumerRequest->setUri($uri);
            $consumerRequest->setRawData($arguments);
        } elseif (is_resource($arguments)) {
            $consumerRequest->setUri($uri);
            /** Placeholder for Oauth streaming support. */
        }
        if (count($httpHeaders)) {
            foreach ($httpHeaders as $k => $v) {
                $consumerRequest->setHeaders($k, $v);
            }
        }
        $response = $consumerRequest->request();
        $body = Zend_Json::decode($response->getBody());
        switch ($response->getStatus()) {
            // Not modified
            case 304:
                return array('httpStatus' => 304, 'body' => null);
                break;
            case 403:
                throw new Dropbox_Exception_Forbidden('Forbidden.

                    This could mean a bad OAuth request, or a file or folder already existing at the target location.

                    ' . $body["error"] . "\n");
            case 404:
                throw new Dropbox_Exception_NotFound('Resource at uri: ' . $uri . ' could not be found. ' . $body["error"] . "\n");
            case 507:
                throw new Dropbox_Exception_OverQuota('This dropbox is full. ' . $body["error"] . "\n");
        }
        return array('httpStatus' => $response->getStatus(), 'body' => $response->getBody());
    }
Example #20
0
    // This is the *ACCESS* Token and Secret.  You should store these in your
    // database with the user's record.  We're putting them in the session only
    // so the demo will work.
    $prev_token = $_SESSION['token'];
    $_SESSION['token'] = $access_token->getToken();
    $_SESSION['token_secret'] = $access_token->getTokenSecret();
    if (strlen($_SESSION['token']) && strlen($_SESSION['token_secret']) && $_SESSION['token'] != $prev_token) {
        echo "Step 8: Success!  Your final access token is {$_SESSION['token']}.  ";
        echo "We can now proceed to step nine.  ";
        echo '<a href="', $_SERVER['PHP_SELF'], '">Clicky.</a>';
        $_SESSION['oauth_state'] = 2;
    } else {
        echo "Something went wrong.  Didn't get the right tokens.  You should probably see an error message above.<br>";
        echo "Be aware that these tokens are one-use only.  You <i>might</i> need to reset your session.";
    }
    exit;
} elseif ($_SESSION['oauth_state'] == 2) {
    echo "Step 9: You should have access with key {$_SESSION['token']}!<br>";
    // Once again, this is why they have you serialize it in their example code...
    $access_token = new Zend_Oauth_Token_Access();
    $access_token->setToken($_SESSION['token']);
    $access_token->setTokenSecret($_SESSION['token_secret']);
    // setOAuth wants to work only with the result of this call, which will be
    // a Zend_Oauth_Client, a subclass of Zend_Http_Client.
    Imgur::setOAuth($access_token->getHttpClient($zend_oauth_config));
    // We'll fall through at this point, so the demo in oauth.php can run.
    echo "Done!  We can make make OAuth requests on your behalf.<br><hr>";
} else {
    echo "Whoa, your OAuth state is totally bogus, dude.";
    exit;
}
Example #21
0
 private function retrieve_token($provider_key)
 {
     $config = $this->get_configuration($provider_key);
     if (!empty($config['accessToken']) && !empty($config['accessTokenSecret'])) {
         $token = new Zend_Oauth_Token_Access();
         $token->setParams(array('oauth_token' => $config['accessToken'], 'oauth_token_secret' => $config['accessTokenSecret']));
         return $token;
     }
     $tikilib = TikiLib::lib('tiki');
     $token = $tikilib->get_preference('oauth_token_' . $provider_key);
     return $token ? unserialize($token) : null;
 }
Example #22
0
 /**
  *
  */
 protected static function request($customernumber, $endpoint)
 {
     static $zendready = false;
     if (!$zendready) {
         $dir = get_config('core', 'dirroot');
         set_include_path(get_include_path() . PATH_SEPARATOR . $dir . '/blocks/mhaairs/lib');
         $zendready = true;
     }
     // @codingStandardsIgnoreStart
     require_once 'Zend/Json.php';
     require_once 'Zend/Oauth/Consumer.php';
     require_once 'Zend/Oauth/Client.php';
     // @codingStandardsIgnoreEnd
     $baseurl = 'http://mhaairs.tegrity.com/v1/Config/';
     $url = $baseurl . $customernumber . '/' . $endpoint;
     $aconfig = array('requestScheme' => Zend_Oauth::REQUEST_SCHEME_QUERYSTRING, 'requestMethod' => Zend_Oauth::GET, 'signatureMethod' => 'HMAC-SHA1', 'consumerKey' => 'SSOConfig', 'consumerSecret' => '3DC9C384');
     $resultdata = false;
     try {
         $tacc = new Zend_Oauth_Token_Access();
         $client = $tacc->getHttpClient($aconfig, $url);
         $client->setMethod(Zend_Oauth_Client::GET);
         $client->setEncType(Zend_Oauth_Client::ENC_URLENCODED);
         $response = $client->request();
         $resultdata = $response->getBody();
         // Get content type.
         $resulttype = $response->getHeader(Zend_Oauth_Client::CONTENT_TYPE);
         // Is this Json encoded data?
         if (stripos($resulttype, 'application/json') !== false) {
             $resultdata = Zend_Json::decode($resultdata);
         }
         // By default set the status to the HTTP response status.
         $status = $response->getStatus();
         $description = $response->getMessage();
         if ($status != 200) {
             $resultdata = false;
         }
     } catch (Exception $e) {
         $status = (string) $e->getCode();
         $description = $e->getMessage();
     }
     $logmsg = $status . ": " . $description;
     // TODO
     // There used to be add_to_log here recording the requested endpoint and log message.
     // This should be replaced with events system as soon as we decide what should be
     // logged.
     return $resultdata;
 }
Example #23
0
 protected function _getTwitterService(Zend_Oauth_Token_Access $accesstoken, $consumerKey, $consumerSecret)
 {
     return new Zend_Service_Twitter(array('accessToken' => $accesstoken, 'oauthOptions' => array('username' => $accesstoken->getParam('screen_name'), 'consumerKey' => $consumerKey, 'consumerSecret' => $consumerSecret)));
 }
Example #24
0
 public function getToken()
 {
     $token = new Zend_Oauth_Token_Access();
     $token->setToken('abcde');
     return $token;
 }
Example #25
0
 /**
  * Constructor
  *
  * @param  null|array|Zend_Config $options
  * @param  null|Zend_Oauth_Consumer $consumer
  * @param  null|Zend_Http_Client $httpClient
  */
 public function __construct($options = null, Zend_Oauth_Consumer $consumer = null, Zend_Http_Client $httpClient = null)
 {
     if ($options instanceof Zend_Config) {
         $options = $options->toArray();
     }
     if (!is_array($options)) {
         $options = array();
     }
     $this->options = $options;
     if (isset($options['username'])) {
         $this->setUsername($options['username']);
     }
     $accessToken = false;
     if (isset($options['accessToken'])) {
         $accessToken = $options['accessToken'];
     } elseif (isset($options['access_token'])) {
         $accessToken = $options['access_token'];
     }
     $oauthOptions = array();
     if (isset($options['oauthOptions'])) {
         $oauthOptions = $options['oauthOptions'];
     } elseif (isset($options['oauth_options'])) {
         $oauthOptions = $options['oauth_options'];
     }
     $oauthOptions['siteUrl'] = self::OAUTH_BASE_URI;
     $httpClientOptions = array();
     if (isset($options['httpClientOptions'])) {
         $httpClientOptions = $options['httpClientOptions'];
     } elseif (isset($options['http_client_options'])) {
         $httpClientOptions = $options['http_client_options'];
     }
     // If we have an OAuth access token, use the HTTP client it provides
     if ($accessToken && is_array($accessToken) && (isset($accessToken['token']) && isset($accessToken['secret']))) {
         $token = new Zend_Oauth_Token_Access();
         $token->setToken($accessToken['token']);
         $token->setTokenSecret($accessToken['secret']);
         $accessToken = $token;
     }
     if ($accessToken && $accessToken instanceof Zend_Oauth_Token_Access) {
         $oauthOptions['token'] = $accessToken;
         $this->setHttpClient($accessToken->getHttpClient($oauthOptions, self::OAUTH_BASE_URI, $httpClientOptions));
         return;
     }
     // See if we were passed an http client
     if (isset($options['httpClient']) && null === $httpClient) {
         $httpClient = $options['httpClient'];
     } elseif (isset($options['http_client']) && null === $httpClient) {
         $httpClient = $options['http_client'];
     }
     if ($httpClient instanceof Zend_Http_Client) {
         $this->httpClient = $httpClient;
     } else {
         $this->setHttpClient(new Zend_Http_Client(null, $httpClientOptions));
     }
     // Set the OAuth consumer
     if ($consumer === null) {
         $consumer = new Zend_Oauth_Consumer($oauthOptions);
     }
     $this->oauthConsumer = $consumer;
 }
Example #26
0
 protected function _initTwitter()
 {
     $oauthConfig = $this->getConfigFile();
     $accessToken = new Zend_Oauth_Token_Access();
     $accessToken->setToken($oauthConfig->oauth->token);
     $accessToken->setTokenSecret($oauthConfig->oauth->tokenSecret);
     $config = array('siteUrl' => 'http://twitter.com/oauth', 'consumerKey' => $oauthConfig->oauth->consumerKey, 'consumerSecret' => $oauthConfig->oauth->consumerSecret, 'accessToken' => $accessToken);
     return new Zend_Service_Twitter($config);
 }
Example #27
0
 public function __construct($username, $config, Zend_Oauth_Token_Access $token)
 {
     $this->_authInitialized = true;
     $this->_client = $token->getHttpClient($config);
     self::setHttpClient($this->_client);
     parent::__construct($username, null);
 }
Example #28
0
 public function getAccessToken($reset_session = false)
 {
     if (!($accessToken = $this->_getData('access_token'))) {
         $session = $this->_getSession();
         if ($reset_session) {
             $session->unsAccessToken();
         } else {
             $accessToken = $session->getAccessToken();
         }
         if (empty($accessToken)) {
             $oauth_token = $this->getConfigValue(self::OAUTH_ACCESS_TOKEN);
             $oauth_token_secret = $this->getConfigValue(self::OAUTH_ACCESS_TOKEN_SECRET);
             if (!$oauth_token || !$oauth_token_secret) {
                 return null;
             }
             $accessToken = new Zend_Oauth_Token_Access();
             $accessToken->setToken($oauth_token);
             $accessToken->setTokenSecret($oauth_token_secret);
             $session->setAccessToken($accessToken);
         }
         $this->setAccessToken($accessToken);
     }
     return $accessToken;
 }