/** * This method is used to process the first part of authentication workflow, before redirect * * @return array Array with status and redirect URI */ public function getRedirectUri() { $ngConnectINI = eZINI::instance('ngconnect.ini'); $http = eZHTTPTool::instance(); $consumerKey = trim($ngConnectINI->variable('LoginMethod_tumblr', 'AppConsumerKey')); $consumerSecret = trim($ngConnectINI->variable('LoginMethod_tumblr', 'AppConsumerSecret')); if (empty($consumerKey) || empty($consumerSecret)) { return array('status' => 'error', 'message' => 'Consumer key or consumer secret undefined.'); } $callbackUri = self::CALLBACK_URI_PART; $loginWindowType = trim($ngConnectINI->variable('ngconnect', 'LoginWindowType')); if ($loginWindowType == 'popup') { $callbackUri = '/layout/set/ngconnect' . self::CALLBACK_URI_PART; } $state = md5(session_id() . (string) time()); $http->setSessionVariable('NGConnectOAuthState', $state); $callbackUri .= '?state=' . $state; eZURI::transformURI($callbackUri, false, 'full'); $connection = new TumblrOAuth($consumerKey, $consumerSecret); $tempCredentials = $connection->getRequestToken($callbackUri); $redirectUri = $connection->getAuthorizeURL($tempCredentials); if (!$redirectUri) { return array('status' => 'error', 'message' => 'Invalid redirection URI.'); } $http->setSessionVariable('NGConnectOAuthToken', $tempCredentials['oauth_token']); $http->setSessionVariable('NGConnectOAuthTokenSecret', $tempCredentials['oauth_token_secret']); return array('status' => 'success', 'redirect_uri' => $redirectUri); }
public function loginAction() { if ($this->getSession()->isLoggedIn()) { return $this->_redirectUrl(); } $connection = new TumblrOAuth(Mage::getStoreConfig('gomage_social/tumblr/id'), Mage::getStoreConfig('gomage_social/tumblr/secret')); $callback_params = array('_secure' => true); if ($this->getRequest()->getParam('gs_url', '')) { $callback_params['gs_url'] = $this->getRequest()->getParam('gs_url'); } $callback_url = Mage::getUrl('gomage_social/tumblr/callback', $callback_params); $request_token = $connection->getRequestToken($callback_url); switch ($connection->http_code) { case 200: Mage::getSingleton('core/session')->setData('oauth_token', $request_token['oauth_token']); Mage::getSingleton('core/session')->setData('oauth_token_secret', $request_token['oauth_token_secret']); $url = $connection->getAuthorizeURL($request_token['oauth_token']); return $this->_redirectUrl($url); break; default: $this->getSession()->addError($this->__('Could not connect to Tumblr. Refresh the page or try again later.')); } return $this->_redirectUrl(); }
//Tumblr API urls $req_url = 'http://www.tumblr.com/oauth/request_token'; $authurl = 'http://www.tumblr.com/oauth/authorize'; $acc_url = 'http://www.tumblr.com/oauth/access_token'; //Your Application key and secret $consumer_key = 'vliXIm52B9BG2L1hfRAy6SvPbekkOk5JEsRITW5MeOH1Xnknl2'; $consumer_secret = '3Pqe75MjkrvqdrHAyKuZ9Z3nWMlCuLKjfMnT5E1H0rrz8WXVay'; $callback_url = 'callback.php'; $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret); $request_token = $tum_oauth->getRequestToken($callback_url); $_SESSION['request_token'] = $token = $request_token['oauth_token']; $_SESSION['request_token_secret'] = $request_token['oauth_token_secret']; switch ($tum_oauth->http_code) { case 200: // Ask Tumblr to give us a special address to their login page $url = $tum_oauth->getAuthorizeURL($token); // Redirect the user to the login URL given to us by Tumblr header('Location: ' . $url); // That's it for our side. The user is sent to a Tumblr Login page and // asked to authroize our app. After that, Tumblr sends the user back to // our Callback URL (callback.php) along with some information we need to get // an access token. break; default: // Give an error message echo 'Could not connect to Tumblr. Refresh the page or try again later.'; } exit; /* //$client = new Tumblr\API\Client($consumerKey, $consumerSecret); //$client->setToken($token, $tokenSecret);
function tumblr_connect($a) { // Start a session. This is necessary to hold on to a few keys the callback script will also need session_start(); // Include the TumblrOAuth library //require_once('addon/tumblr/tumblroauth/tumblroauth.php'); // Define the needed keys $consumer_key = get_config('tumblr', 'consumer_key'); $consumer_secret = get_config('tumblr', 'consumer_secret'); // The callback URL is the script that gets called after the user authenticates with tumblr // In this example, it would be the included callback.php $callback_url = $a->get_baseurl() . "/tumblr/callback"; // Let's begin. First we need a Request Token. The request token is required to send the user // to Tumblr's login page. // Create a new instance of the TumblrOAuth library. For this step, all we need to give the library is our // Consumer Key and Consumer Secret $tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret); // Ask Tumblr for a Request Token. Specify the Callback URL here too (although this should be optional) $request_token = $tum_oauth->getRequestToken($callback_url); // Store the request token and Request Token Secret as out callback.php script will need this $_SESSION['request_token'] = $token = $request_token['oauth_token']; $_SESSION['request_token_secret'] = $request_token['oauth_token_secret']; // Check the HTTP Code. It should be a 200 (OK), if it's anything else then something didn't work. switch ($tum_oauth->http_code) { case 200: // Ask Tumblr to give us a special address to their login page $url = $tum_oauth->getAuthorizeURL($token); // Redirect the user to the login URL given to us by Tumblr header('Location: ' . $url); // That's it for our side. The user is sent to a Tumblr Login page and // asked to authroize our app. After that, Tumblr sends the user back to // our Callback URL (callback.php) along with some information we need to get // an access token. break; default: // Give an error message $o = 'Could not connect to Tumblr. Refresh the page or try again later.'; } return $o; }
<?php // Include the TumblrOAuth library include_once '../tumblr/config.php'; include_once '../tumblr/API/tumblroauth.php'; // Let's begin. First we need a Request Token. The request token is required to send the user to Tumblr's login page. // Create a new instance of the TumblrOAuth library. $ObjTumAuth = new TumblrOAuth(CONSUMER_KEY, CONSUMER_SECRET); // Ask Tumblr for a Request Token. Specify the Callback URL here too (although this should be optional) $objArrRequest = $ObjTumAuth->getRequestToken(CALLBACK); // Store the request token and Request Token Secret as out callback.php script will need this $_SESSION['request_token'] = $strToken = $objArrRequest['oauth_token']; $_SESSION['request_token_secret'] = $objArrRequest['oauth_token_secret']; // Check the HTTP Code. It should be a 200 (OK), if it's anything else then something didn't work. switch ($ObjTumAuth->http_code) { case 200: // Ask Tumblr to give us a special address to their login page $strUrl = $ObjTumAuth->getAuthorizeURL($strToken); // Redirect the user to the login URL given to us by Tumblr header('Location: ' . $strUrl); // That's it for our side. The user is sent to a Tumblr Login page and asked to authroize our app. After that, Tumblr sends the user back to our // Callback URL (callback.php) along with some information we need to get an access token. break; default: // Give an error message echo 'Could not connect to Tumblr. Refresh the page or try again later.'; exit; } $arrMessage = array('type' => 'regular', 'title' => 'Testing ', 'body' => 'Details', 'format' => 'html'); //API Call For Posting Blog update $arrPost = $this->objTumblrOauth->post($strPostUrl, $arrMessage);
<?php /* Start session and load library. */ session_start(); require_once 'tumblroauth/tumblroauth.php'; require_once 'config.php'; /* Build TumblrOAuth object with client credentials. */ $connection = new TumblrOAuth(CONSUMER_KEY, CONSUMER_SECRET); /* Get temporary credentials. */ $request_token = $connection->getRequestToken(OAUTH_CALLBACK); /* Save temporary credentials to session. */ $_SESSION['oauth_token'] = $token = $request_token['oauth_token']; $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; /* If last connection failed don't display authorization link. */ switch ($connection->http_code) { case 200: /* Build authorize URL and redirect user to Tumblr. */ $url = $connection->getAuthorizeURL($token); header('Location: ' . $url); break; default: /* Show notification if something went wrong. */ echo 'Could not connect to Tumblr. Refresh the page or try again later.'; }