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); }
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); } }
public function makeAccessToken() { $token = new Zend_Oauth_Token_Access(); $token->setToken($this->token[0]); $token->setTokenSecret($this->token[1]); return $token; }
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)); }
/** * 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; }
/** * 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)))); }
public function loadAccessToken() { $query = "SELECT * FROM group_provider_user_oauth WHERE provider_id=? AND user_id=?"; $params = array($this->_providerId, $this->_userId); $statement = $this->_connection->prepare($query); $statement->execute($params); $row = $statement->fetch(PDO::FETCH_ASSOC); $accessToken = new Zend_Oauth_Token_Access(); $accessToken->setToken($row['oauth_token']); $accessToken->setTokenSecret($row['oauth_secret']); return $accessToken; }
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']]]); }
/** * 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'))); }
/** * 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; }
/** * 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)); }
/** * @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; } }
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; }
/** * 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; }
public function getToken() { $token = new Zend_Oauth_Token_Access(); $token->setToken('abcde'); return $token; }
/** * 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()); }
// 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; }
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); }