Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 2
0
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;
}
 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();
 }
Ejemplo n.º 4
0
$method = 'friends/ids';
tumblroauth_row($method, $connection->get($method), $connection->http_code);
/* friends/ids */
$method = 'friends/ids';
tumblroauth_row($method, $connection->get($method), $connection->http_code);
/**
 * Account Methods.
 */
tumblroauth_header('Account Methods');
/* account/verify_credentials */
$method = 'account/verify_credentials';
tumblroauth_row($method, $connection->get($method), $connection->http_code);
/* account/rate_limit_status */
$method = 'account/rate_limit_status';
tumblroauth_row($method, $connection->get($method), $connection->http_code);
/* account/update_profile_colors */
$parameters = array('profile_background_color' => 'fff');
$method = 'account/update_profile_colors';
tumblroauth_row($method, $connection->post($method, $parameters), $connection->http_code, $parameters);
/* account/update_profile */
$parameters = array('location' => 'Teh internets');
$method = 'account/update_profile';
tumblroauth_row($method, $connection->post($method, $parameters), $connection->http_code, $parameters);
/**
 * OAuth Methods.
 */
tumblroauth_header('OAuth Methods');
/* oauth/request_token */
$oauth = new TumblrOAuth(CONSUMER_KEY, CONSUMER_SECRET);
tumblroauth_row('oauth/reqeust_token', $oauth->getRequestToken(), $oauth->http_code);
Ejemplo n.º 5
0
//Enable session.  We will store token information here later
session_start();
//echo 'hello';
//require 'vendor/autoload.php';
require_once 'vendor/tumblroauthnonnative/tumblroauth.php';
//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
Ejemplo n.º 6
0
<?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);
Ejemplo n.º 7
0
<?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.';
}