Exemplo n.º 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;
 }
Exemplo n.º 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 testToStringReturnsEncodedResponseBody()
 {
     $body = 'oauth_token=jZaee4GF52O3lUb9&oauth_token_secret=J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri';
     $token = new Zend_Oauth_Token_Request();
     $token->setToken('jZaee4GF52O3lUb9');
     $token->setTokenSecret('J4Ms4n8sxjYc0A8K0KOQFCTL0EwUQTri');
     $this->assertEquals($body, $token->toString());
 }
Exemplo n.º 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();
 }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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();
 }
Exemplo n.º 8
0
    $_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.  ";
        echo '<a href="', $_SERVER['PHP_SELF'], '">Clicky.</a>';
Exemplo n.º 9
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();
 }
Exemplo n.º 10
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;
 }