/** * 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; }
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()); }
/** * 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(); }
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>'; $_SESSION['oauth_state'] = 2;
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; }