Exemple #1
0
 /**
  * Create request token object for current token
  * @return Zend_Oauth_Token_Request
  */
 public function makeRequestToken()
 {
     $token = new Zend_Oauth_Token_Request();
     $token->setToken($this->token[0]);
     $token->setTokenSecret($this->token[1]);
     return $token;
 }
Exemple #2
0
 /** Create the token for yahoo access and save to database.
  * 
  */
 public function access()
 {
     $config = array('siteUrl' => self::YAHOOTOKENGET, 'callbackUrl' => 'http://beta.finds.org.uk/admin/oauth/', 'consumerKey' => $this->_consumerKey, 'consumerSecret' => $this->_consumerSecret);
     $session = new Zend_Session_Namespace('yahoo_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();
     $expires = $date->add('1', Zend_Date::HOUR)->toString('YYYY-MM-dd HH:mm:ss');
     $consumer = new Zend_Oauth_Consumer($config);
     $token = $consumer->getAccessToken($_GET, $request);
     $oauth_guid = $token->xoauth_yahoo_guid;
     $oauth_session = $token->oauth_session_handle;
     $oauth_token = $token->getToken();
     $oauth_token_secret = $token->getTokenSecret();
     $tokenRow = $this->createRow();
     $tokenRow->service = 'yahooAccess';
     $tokenRow->accessToken = serialize($oauth_token);
     $tokenRow->tokenSecret = serialize($oauth_token_secret);
     $tokenRow->guid = serialize($oauth_guid);
     $tokenRow->sessionHandle = serialize($oauth_session);
     $tokenRow->created = $now;
     $tokenRow->expires = $expires;
     $tokenRow->save();
 }
 public function testIsValidDetectsGoodResponse()
 {
     $body = 'oauth_token=jZaee4GF52O3lUb9&oauth_token_secret=J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri';
     $response = new Zend_Http_Response(200, array(), $body);
     $token = new Zend_Oauth_Token_Request($response);
     $this->assertTrue($token->isValid());
 }
Exemple #4
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();
 }
Exemple #5
0
 /**
  * Retrieve an Access Token in exchange for a previously received/authorized
  * Request Token.
  *
  * @param  array $queryData GET data returned in user's redirect from Provider
  * @param  Zend_Oauth_Token_Request Request Token information
  * @param  string $httpMethod
  * @param  Zend_Oauth_Http_AccessToken $request
  * @return Zend_Oauth_Token_Access
  * @throws Zend_Oauth_Exception on invalid authorization token, non-matching response authorization token, or unprovided authorization token
  */
 public function getAccessToken($queryData, Zend_Oauth_Token_Request $token, $httpMethod = null, Zend_Oauth_Http_AccessToken $request = null)
 {
     $authorizedToken = new Zend_Oauth_Token_AuthorizedRequest($queryData);
     if (!$authorizedToken->isValid()) {
         require_once 'Zend/Oauth/Exception.php';
         throw new Zend_Oauth_Exception('Response from Service Provider is not a valid authorized request token');
     }
     if ($request === null) {
         $request = new Zend_Oauth_Http_AccessToken($this);
     }
     // OAuth 1.0a Verifier
     if ($authorizedToken->getParam('oauth_verifier') !== null) {
         $params = array_merge($request->getParameters(), array('oauth_verifier' => $authorizedToken->getParam('oauth_verifier')));
         $request->setParameters($params);
     }
     if ($httpMethod !== null) {
         $request->setMethod($httpMethod);
     } else {
         $request->setMethod($this->getRequestMethod());
     }
     if (isset($token)) {
         if ($authorizedToken->getToken() !== $token->getToken()) {
             require_once 'Zend/Oauth/Exception.php';
             throw new Zend_Oauth_Exception('Authorized token from Service Provider does not match' . ' supplied Request Token details');
         }
     } else {
         require_once 'Zend/Oauth/Exception.php';
         throw new Zend_Oauth_Exception('Request token must be passed to method');
     }
     $this->_requestToken = $token;
     $this->_accessToken = $request->execute();
     return $this->_accessToken;
 }
Exemple #6
0
 /** Refresh access using old details
  * @access public
  * @param string $old_access_token
  * @param string $old_token_secret
  * @param string $oauth_session_handle
  * @return \build_token
  */
 public function refreshAccess($old_access_token, $old_token_secret, $oauth_session_handle)
 {
     $config = array('siteUrl' => self::YAHOOTOKENGET, 'callbackUrl' => 'http://beta.finds.org.uk/admin/oauth/', 'consumerKey' => $this->_consumerKey, 'consumerSecret' => $this->_consumerSecret);
     $session = new Zend_Session_Namespace('yahoo_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);
     $consumer = new Zend_Oauth_Consumer($config);
     $token = $consumer->getAccessToken($_GET, $request);
     return $this->buildToken($token);
 }
Exemple #7
0
 public function testGetAccessTokenReturnsInstanceOfOauthTokenAccess()
 {
     $config = array('consumerKey' => '12345', 'consumerSecret' => '54321');
     $consumer = new Zend_Oauth_Consumer($config);
     $rtoken = new Zend_Oauth_Token_Request();
     $rtoken->setToken('token');
     $token = $consumer->getAccessToken(array('oauth_token' => 'token'), $rtoken, null, new Test_Http_AccessToken_48231());
     $this->assertType('Zend_Oauth_Token_Access', $token);
 }
Exemple #8
0
 /**
  * Requests the OAuth access tokens.
  *
  * This method requires the 'unauthorized' request tokens
  * and, if successful will set the authorized request tokens.
  *
  * @return void
  */
 public function getAccessToken()
 {
     if (is_a($this->zend_oauth_token, "Zend_Oauth_Token_Request")) {
         $requestToken = $this->zend_oauth_token;
     } else {
         $requestToken = new Zend_Oauth_Token_Request();
         $requestToken->setToken($this->oauth_token);
         $requestToken->setTokenSecret($this->oauth_token_secret);
     }
     $token = $this->OAuth->getAccessToken($_GET, $requestToken);
     $this->setToken($token);
     return $this->getToken();
 }
    $_SESSION['token'] = $request_token->getToken();
    $_SESSION['token_secret'] = $request_token->getTokenSecret();
    if (strlen($_SESSION['token']) && strlen($_SESSION['token_secret'])) {
        echo "Step 4: Your token is {$_SESSION['token']}.  Click the following link to pop over to Imgur and authorize the demo: ";
        echo '<a href="', Imgur::$oauth1a_authorize_url, '?oauth_token=', urlencode($_SESSION['token']), '">Clicky.</a>';
        $_SESSION['oauth_state'] = 1;
    } else {
        echo "Something went wrong.  You should probably see an error message above.<br>";
    }
    exit;
} elseif ($_SESSION['oauth_state'] == 1) {
    echo "Step 5: You just authorized this demo for access.  Thanks!<br>";
    echo "Step 6: You've been sent back here with token ", htmlspecialchars($_REQUEST['oauth_token']), " and verifier ", htmlspecialchars($_REQUEST['oauth_verifier']), "<br>";
    echo "Step 7: Now I'll ask the Provider for access using the various tokens.<br>";
    // And this is why they have you serialize it in their example code:
    $request_token = new Zend_Oauth_Token_Request();
    $request_token->setToken($_SESSION['token']);
    $request_token->setTokenSecret($_SESSION['token_secret']);
    // Zend's impl will read the oauth_token and verifier straight out of $_GET
    /** @var Zend_Oauth_Token_Access */
    $access_token = $oauth_zend->getAccessToken($_GET, $request_token);
    // Replace the user's request token with their access token.
    // 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.  ";
Exemple #10
0
 /**
  * Retrieve an Access Token in exchange for a previously received/authorised
  * Request Token.
  *
  * @param array $queryData GET data returned in user's redirect from Provider
  * @param Zend_Oauth_Token_Request Request Token information
  * @param string $httpMethod
  * @param Zend_Oauth_Http_AccessToken $request
  * @return Zend_Oauth_Token_Access
  */
 public function getAccessToken($queryData, Zend_Oauth_Token_Request $token, $httpMethod = null, Zend_Oauth_Http_AccessToken $request = null)
 {
     $authorisedToken = new Zend_Oauth_Token_AuthorisedRequest($queryData);
     if (!$authorisedToken->isValid()) {
         require_once 'Zend/Oauth/Exception.php';
         throw new Zend_Oauth_Exception('Response from Service Provider is not a valid authorised request token');
     }
     if (is_null($request)) {
         $request = new Zend_Oauth_Http_AccessToken($this);
     }
     if (!is_null($httpMethod)) {
         $request->setMethod($httpMethod);
     } else {
         $request->setMethod($this->getRequestMethod());
     }
     if (isset($token)) {
         if ($authorisedToken->getToken() !== $token->getToken()) {
             require_once 'Zend/Oauth/Exception.php';
             throw new Zend_Oauth_Exception('Authorised token from Service Provider does not match
                 supplied Request Token details');
         }
     } else {
         require_once 'Zend/Oauth/Exception.php';
         throw new Zend_Oauth_Exception('Request token must be passed to method');
     }
     $this->_requestToken = $token;
     $this->_accessToken = $request->execute();
     return $this->_accessToken;
 }
Exemple #11
0
 /** Create the access token and save to database
  * @access public
  * @return void
  */
 public function access()
 {
     $config = array('requestTokenUrl' => 'https://www.google.com/accounts/OAuthGetRequestToken', 'accessTokenUrl' => 'https://www.google.com/accounts/OAuthGetAccessToken', 'userAuthorisationUrl' => 'https://www.google.com/accounts/OAuthAuthorizeToken', 'localUrl' => Zend_Registry::get('siteurl') . '/admin/oauth', 'callbackUrl' => $this->getCallback(), 'consumerKey' => $this->getConsumerKey(), 'consumerSecret' => $this->getConsumerSecret(), '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);
     $consumer = new Zend_Oauth_Consumer($config);
     $token = $consumer->getAccessToken(Zend_Controller_Front::getInstance()->getRequest()->getQuery(), $request);
     $tokens = new OauthTokens();
     $tokenRow = $tokens->createRow();
     $tokenRow->service = 'googleAccess';
     $tokenRow->accessToken = serialize($token);
     $tokenRow->created = Zend_Date::now()->toString('YYYY-MM-dd HH:mm:ss');
     $tokenRow->save();
 }
 /**
  * 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;
 }
Exemple #13
0
 public function getOauthInfo()
 {
     $oauth_token_secret = $oauth_token = null;
     $config = $this->_getConsumerConfig();
     $consumer = $this->getConsumer($config);
     $session = $this->_getSession();
     /* @var $session Mageplace_Backup_Model_Session */
     if ($session->checkCloud($config)) {
         $oauth_token = $session->getOauthToken();
         $oauth_token_secret = $session->getOauthTokenSecret();
     }
     if ($oauth_token && $oauth_token_secret) {
         $requestToken = new Zend_Oauth_Token_Request();
         $requestToken->setToken($oauth_token);
         $requestToken->setTokenSecret($oauth_token_secret);
         $accessToken = $consumer->getAccessToken($_GET, $requestToken);
         if (!($token_key = $accessToken->getToken()) || !($token_secret = $accessToken->getTokenSecret())) {
             return false;
         }
         $this->saveConfigValue(self::OAUTH_ACCESS_TOKEN, $token_key);
         $this->saveConfigValue(self::OAUTH_ACCESS_TOKEN_SECRET, $token_secret);
         $session->setAccessToken($accessToken);
         return true;
     }
     try {
         $token_request = $consumer->getRequestToken();
     } catch (Exception $e) {
         Mage::logException($e);
         return null;
     }
     $response = $token_request->getResponse();
     parse_str($response->getBody());
     if (!$oauth_token || !$oauth_token_secret) {
         try {
             $body = Zend_Json::decode($response->getBody());
             switch ($response->getStatus()) {
                 case 304:
                     $error = 'Empty response body.';
                     break;
                 case 403:
                     $error = 'Forbidden. This could mean a bad OAuth request.' . @$body["error"];
                     break;
                 case 404:
                     $error = 'Resource at uri: ' . self::URI_REQUEST_TOKEN . ' could not be found. ' . @$body["error"];
                     break;
                 case 507:
                     $error = 'This dropbox is full. ' . @$body["error"];
                     break;
             }
             if (isset($error)) {
                 $e = new Mage_Exception($error, null);
                 Mage::logException($e);
                 Mage::getSingleton('adminhtml/session')->addError($error);
                 return null;
             }
         } catch (Exception $e) {
             Mage::logException($e);
             return null;
         }
     }
     $this->setData('consumer', $consumer);
     $this->setData('oauth_token', $oauth_token);
     $this->setData('oauth_token_secret', $oauth_token_secret);
     $session->setCloudId($config)->setOauthToken($oauth_token)->setOauthTokenSecret($oauth_token_secret);
     return true;
 }