Example #1
0
 /**
  * Login to facebook and get the associated contrexx user.
  */
 public function login()
 {
     // fixing timestamp issue with twitter
     // it is necessary that the twitter server has the same time as our system
     date_default_timezone_set('UTC');
     $tmhOAuth = new \tmhOAuth(array('consumer_key' => $this->applicationData[0], 'consumer_secret' => $this->applicationData[1]));
     // set the timestamp
     $tmhOAuth->config['force_timestamp'] = true;
     $tmhOAuth->config['timestamp'] = time();
     if (isset($_GET['oauth_verifier'])) {
         $tmhOAuth->config['user_token'] = $_SESSION['oauth']['oauth_token'];
         $tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];
         $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array('oauth_verifier' => $_GET['oauth_verifier'], 'x_auth_access_type' => 'read'));
         $access_token = $tmhOAuth->extract_params($tmhOAuth->response['response']);
         $tmhOAuth->config['user_token'] = $access_token['oauth_token'];
         $tmhOAuth->config['user_secret'] = $access_token['oauth_token_secret'];
         $tmhOAuth->request('GET', $tmhOAuth->url('1.1/account/verify_credentials'));
         $resp = json_decode($tmhOAuth->response['response']);
         unset($_SESSION['oauth']);
         $name = explode(' ', $resp->name);
         self::$userdata = array('first_name' => $name[0], 'last_name' => $name[1], 'email' => $resp->screen_name . '@twitter.com');
         $this->getContrexxUser($resp->id);
     } else {
         $tmhOAuth->request('POST', $tmhOAuth->url('oauth/request_token', ""), array('oauth_callback' => \Cx\Lib\SocialLogin::getLoginUrl(self::OAUTH_PROVIDER)));
         $_SESSION['oauth'] = $tmhOAuth->extract_params($tmhOAuth->response['response']);
         $url = 'https://api.twitter.com/oauth/authenticate?oauth_token=' . $_SESSION['oauth']['oauth_token'];
         \Cx\Core\Csrf\Controller\Csrf::header("Location: " . $url);
         exit;
     }
 }
Example #2
0
function nextend_api_auth_flow()
{
    $api_key = NextendRequest::getVar('api_key');
    $api_secret = NextendRequest::getVar('api_secret');
    $redirect_uri = NextendRequest::getVar('redirect_uri');
    if (session_id() == "") {
        @session_start();
    }
    if (!$api_key || !$api_secret || !$redirect_uri) {
        $api_key = isset($_SESSION['api_key']) ? $_SESSION['api_key'] : null;
        $api_secret = isset($_SESSION['api_secret']) ? $_SESSION['api_secret'] : null;
        $redirect_uri = isset($_SESSION['redirect_uri']) ? $_SESSION['redirect_uri'] : null;
    } else {
        $_SESSION['api_key'] = $api_key;
        $_SESSION['api_secret'] = $api_secret;
        $_SESSION['redirect_uri'] = $redirect_uri;
    }
    if ($api_key && $api_secret) {
        require_once dirname(__FILE__) . "/api/tmhOAuth.php";
        $tmhOAuth = new tmhOAuth(array('consumer_key' => $api_key, 'consumer_secret' => $api_secret));
        if (isset($_REQUEST['oauth_verifier'])) {
            $tmhOAuth->config['user_token'] = $_SESSION['t_oauth']['oauth_token'];
            $tmhOAuth->config['user_secret'] = $_SESSION['t_oauth']['oauth_token_secret'];
            $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array('oauth_verifier' => $_REQUEST['oauth_verifier']));
            if ($code == 200) {
                $access_token = $tmhOAuth->extract_params($tmhOAuth->response['response']);
                unset($_SESSION['api_key']);
                unset($_SESSION['api_secret']);
                unset($_SESSION['redirect_uri']);
                unset($_SESSION['t_oauth']);
                echo '<script type="text/javascript">';
                echo 'window.opener.setToken("' . $access_token['oauth_token'] . '", "' . $access_token['oauth_token_secret'] . '");';
                echo '</script>';
            } else {
                echo '<h3>Error</h3><br />';
                echo $tmhOAuth->response['response'];
                exit;
            }
        } else {
            $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/request_token', ''), array('oauth_callback' => $redirect_uri));
            if ($code == 200) {
                $oauth = $tmhOAuth->extract_params($tmhOAuth->response['response']);
                $_SESSION['t_oauth'] = $oauth;
                $authurl = $tmhOAuth->url("oauth/authenticate", '') . "?oauth_token=" . $oauth['oauth_token'] . "&force_login=1";
                header('Location: ' . $authurl);
                exit;
            } else {
                echo '<h3>Error</h3><br />';
                echo $tmhOAuth->response['response'];
                exit;
            }
        }
    }
}
Example #3
0
 /**
  * Call API
  * 
  * @param  string $method
  * @param  string $uri
  * @param  array $params
  * @param  string $fmt
  * @return array
  * @throws \FuelException
  */
 protected function call($method, $uri, $params, $fmt)
 {
     $code = $this->tmhoauth->request($method, $this->tmhoauth->url($uri, $fmt), $params);
     if ($code != 200) {
         throw new \FuelException('Code:' . $code . ' Response:' . $this->tmhoauth->response['response']);
     }
     switch ($fmt) {
         case 'json':
             return json_decode($this->tmhoauth->response['response']);
         default:
             return $this->tmhoauth->extract_params($this->tmhoauth->response['response']);
     }
 }
 /**
  * Returns an array with the permanent access token and access secret
  *
  * @param  string $userSessionToken  the current users session token
  * @param  string $userSessionSecret the current users session secret
  * @param  string $oauthVerifier     verifier that was sent to the callback url
  * @return array                     the keys of the returned array are accessToken and accessTokenSecret
  */
 public function getAccessToken($userSessionToken, $userSessionSecret, $oauthVerifier)
 {
     // set the request token and secret we have stored
     $this->api->config['user_token'] = $userSessionToken;
     $this->api->config['user_secret'] = $userSessionSecret;
     // send request for an access token
     $status = $this->api->request('POST', $this->api->url('oauth/access_token', ''), array('oauth_verifier' => $oauthVerifier));
     if ($status == 200) {
         // get the access token and store it in a cookie
         $response = $this->api->extract_params($this->api->response['response']);
         $return = array('accessToken' => $response['oauth_token'], 'accessTokenSecret' => $response['oauth_token_secret']);
         return $return;
     }
     throw new ApiException('Obtaining the acecss token did not work! Status code: ' . $status . '. Last error message was: ' . $this->api->response['error']);
 }
 public function api($method, $url, $params = null)
 {
     $config = Configure::read('Opauth.Strategy.Twitter');
     $tmhOAuth = new tmhOAuth(array('consumer_key' => $config['key'], 'consumer_secret' => $config['secret'], 'user_token' => $this->Session->read('Auth.Twitter.access_token'), 'user_secret' => $this->Session->read('Auth.Twitter.secret'), 'curl_ssl_verifypeer' => false));
     $url = $tmhOAuth->url($url);
     $status = $tmhOAuth->request($method, $url, $params);
     if ($status != 200) {
         return false;
     }
     if (strpos($url, '.json') !== false) {
         $response = json_decode($tmhOAuth->response['response']);
     } else {
         $response = $tmhOAuth->extract_params($this->tmhOAuth->response['response']);
     }
     return $response;
 }
Example #6
0
 /**
  * @param array $params
  * @return string
  * @throws Exception
  */
 public function authenticate(array $params)
 {
     if (!isset($params['oauth_token']) || empty($params['oauth_token']) || !isset($params['oauth_verifier']) || empty($params['oauth_verifier'])) {
         throw new Exception('Authentication failed');
     }
     $oauth = Session::set('oauth');
     if ($params['oauth_token'] !== $oauth['oauth_token']) {
         throw new Exception('Invalid login session');
     }
     $twitterOAuthConf = Config::$a['oauth']['providers']['twitter'];
     $tmhOAuth = new \tmhOAuth(array('consumer_key' => $twitterOAuthConf['clientId'], 'consumer_secret' => $twitterOAuthConf['clientSecret'], 'token' => $oauth['oauth_token'], 'secret' => $oauth['oauth_token_secret'], 'curl_connecttimeout' => Config::$a['curl']['connecttimeout'], 'curl_timeout' => Config::$a['curl']['timeout'], 'curl_ssl_verifypeer' => Config::$a['curl']['verifypeer']));
     /** @noinspection PhpVoidFunctionResultUsedInspection */
     $code = $tmhOAuth->user_request(array('method' => 'POST', 'url' => $tmhOAuth->url('oauth/access_token', ''), 'params' => array('oauth_verifier' => trim($params['oauth_verifier']))));
     if ($code != 200) {
         throw new Exception('Failed to retrieve user data');
     }
     $data = $tmhOAuth->extract_params($tmhOAuth->response['response']);
     $authCreds = $this->getAuthCredentials($oauth['oauth_token'], $data);
     $authCredHandler = new AuthenticationRedirectionFilter();
     return $authCredHandler->execute($authCreds);
 }
 public function getAccessToken()
 {
     $pin = $_GET['pin'];
     session_start();
     $request_token = $_SESSION["authtoken"];
     $request_token_secret = $_SESSION["authsecret"];
     $tmhOAuth = new tmhOAuth(array('consumer_key' => CONSUMER_KEY, 'consumer_secret' => CONSUMER_SECRET));
     $tmhOAuth->config['user_token'] = $request_token;
     $tmhOAuth->config['user_secret'] = $request_token_secret;
     $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array('oauth_verifier' => trim($pin)));
     if ($code == 200) {
         $oauth_creds = $tmhOAuth->extract_params($tmhOAuth->response['response']);
         $_SESSION['USER_TOKEN'] = $oauth_creds['oauth_token'];
         $_SESSION['USER_SECRET'] = $oauth_creds['oauth_token_secret'];
         define("USER_TOKEN", $_SESSION['USER_TOKEN']);
         define("USER_SECRET", $_SESSION['USER_SECRET']);
         $_SESSION["account"] = $oauth_creds['screen_name'];
         return $_SESSION["account"];
     } else {
         echo "There was an error communicating with Twitter. {$tmhOAuth->response['response']}" . PHP_EOL;
     }
 }
Example #8
0
/**
 * 此函数,供Callback处调用,如果返回false,认证失败,否则返回以下哈希表:
 *   last_key  ->  callback得到的last_key
 *   oauth_token ->  上述lastkey中的oauth_token
 *   oauth_token_secret -> 上述lastkey中的oauth_token_secret
 *   user_id -> 用户ID
 *   user_name ->  用户昵称
 *   user_email -> 暂不提供
 */
function AuthCallback_twitter()
{
    $tmhOAuth = new tmhOAuth(array('consumer_key' => TW_AKEY, 'consumer_secret' => TW_SKEY));
    $tmhOAuth->config['user_token'] = $_SESSION['tw_user_token'];
    $tmhOAuth->config['user_secret'] = $_SESSION['tw_user_secret'];
    unset($_SESSION['tw_user_token']);
    unset($_SESSION['tw_user_secret']);
    $pin = JRequest::getCmd('oobpin');
    $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array('oauth_verifier' => trim($pin)));
    if ($code == 200) {
        $oauth_creds = $tmhOAuth->extract_params($tmhOAuth->response['response']);
        $tmhOAuth->config['user_token'] = $oauth_creds['oauth_token'];
        $tmhOAuth->config['user_secret'] = $oauth_creds['oauth_token_secret'];
        $rtn = array();
        $rtn['last_key'] = $oauth_creds;
        $rtn['oauth_token'] = $oauth_creds['oauth_token'];
        $rtn['oauth_token_secret'] = $oauth_creds['oauth_token_secret'];
        $rtn['user_id'] = $oauth_creds['screen_name'];
        $rtn['user_name'] = $oauth_creds['screen_name'];
        return $rtn;
    } else {
        return false;
    }
}
Example #9
0
public function oauth_get_user_token($request_token, $request_token_secret) {

	$tmhOAuth->config['user_token'] = $request_token;
  	$tmhOAuth->config['user_secret'] = $request_token_secret;

  	$tmhOAuth = new tmhOAuth(array(
		'consumer_key' => $this->consumer_key,
		'consumer_secret' => $this->consumer_secret,
	));

  	$tmhOAuth->request("POST", $tmhOAuth->url("oauth/access_token", ""), array( 
        'oauth_verifier' => $_GET["oauth_verifier"]  
    ));

    echo 'Resp: <pre>'; print_r($tmhOAuth->response); echo '</pre>';

  	if ($tmhOAuth->response["code"] == 200) {
  		$response = $tmhOAuth->extract_params($tmhOAuth->response['response']);
    	$_SESSION["authstate"] = 2;
    	$user_token = array(
    		"access_token" => $response["oauth_token"],
    		"access_token_secret" => $response["oauth_token_secret"]
    	);
		return $user_token;
  	}

}
 public function twitter_upload()
 {
     $this->autoRender = false;
     App::import('Vendor', 'tmhOAuth-master/tmhOAuth');
     App::import('Vendor', 'tmhOAuth-master/tmhUtilities');
     $token = $_COOKIE['Temp_Token'];
     $secret = $_COOKIE['Temp_Secret'];
     $Img_name = $_COOKIE['Img_name'];
     $img = $_COOKIE['Img_Url'];
     $redirect_Url = $_COOKIE['redirect_Url'];
     $price = $_COOKIE['price'];
     $pageLink = $_COOKIE['pageLink'];
     $name = basename($img);
     $txt = $Img_name . ' $' . $price . ' link:' . $pageLink;
     $tmhOAuth = new tmhOAuth(array('consumer_key' => 'wFSwIc9Mx5XJjDbAJN7iNHmGo', 'consumer_secret' => '0XcpY5qXZyOy6MU7AQ34Cj72aYVdp9uV2cg4tunbl6GqrUzMtQ', 'user_token' => $token, 'user_secret' => $secret, 'curl_ssl_verifypeer' => false));
     $tmhOAuth->request("POST", $tmhOAuth->url("oauth/access_token", ""), array('oauth_verifier' => $_GET["oauth_verifier"]));
     $response = $tmhOAuth->extract_params($tmhOAuth->response["response"]);
     $tmhOAuth->config["user_token"] = $response['oauth_token'];
     $tmhOAuth->config["user_secret"] = $response['oauth_token_secret'];
     $code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json', array('media[]' => file_get_contents($img), 'status' => "{$txt}"), true, true);
     if ($code == 200) {
         $this->Session->setFlash('Your image tweet has been sent successfully', 'default', array('class' => 'alert alert-success'));
         $this->redirect($redirect_Url);
         die;
     } else {
         tmhUtilities::pr($tmhOAuth->response['response']);
     }
 }
Example #11
0
<?php

require './config.php';
require './tmhOAuth.php';
/////// upload the photo
$img = $_FILES["img"]["name"];
move_uploaded_file($_FILES["img"]["tmp_name"], $img);
////////// generate *temp* access token and save it in cookie for callback page
$tmhOAuth = new tmhOAuth(array('consumer_key' => API_KEY, 'consumer_secret' => API_SEC, 'curl_ssl_verifypeer' => false));
$tmhOAuth->request('POST', $tmhOAuth->url('oauth/request_token', ''));
$response = $tmhOAuth->extract_params($tmhOAuth->response["response"]);
$txt = $_POST['txt'];
$temp_token = $response['oauth_token'];
$temp_secret = $response['oauth_token_secret'];
$time = $_SERVER['REQUEST_TIME'];
setcookie("Temp_Token", $temp_token, $time + 3600 * 30, 'twitter_test');
// '/twitter_test/' is the cookie path on your server
setcookie("Temp_Secret", $temp_secret, $time + 3600 * 30, 'twitter_test');
setcookie("Img_Url", $img, $time + 3600 * 30, 'twitter_test');
setcookie("Tweet_Txt", $txt, $time + 3600 * 30, 'twitter_test');
///////// redirect to twitter page for user authincation
$url = $tmhOAuth->url("oauth/authorize", "") . '?oauth_token=' . $temp_token;
header("Location:" . $url);
// after user give the required authrization he will be redirect to callback.php on your server
exit;
Example #12
0
function twitter() {
  require '../lib/tmhOAuth.php';

  $tmhOAuth = new tmhOAuth(array(
    'consumer_key'    => Config::$t_consumer_key,
    'consumer_secret' => Config::$t_consumer_secret,
  ));
 
  $myurl = Config::$site_url . "auth/?a=login&m=twitter";
  session_start();
 
  if(isset($_REQUEST['oauth_verifier'])) {
    $tmhOAuth->config['user_token']  = $_SESSION['oauth']['oauth_token'];
    $tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];

    $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array(
      'oauth_verifier' => $_REQUEST['oauth_verifier']
    ));

    $resp = $tmhOAuth->extract_params($tmhOAuth->response['response']);
    unset($_SESSION['oauth']);
    setcookie('PHPSESSID', '', time()-3600, '/');

    // Get stuff
    $tmhOAuth->config['user_token']  = $resp['oauth_token'];
    $tmhOAuth->config['user_secret'] = $resp['oauth_token_secret'];
    $tmhOAuth->request('GET', $tmh->url('1/account/verify_credentials'));
    $stuff = json_decode($tmhOAuth->response['response']);

    $uniqid = $stuff->id;
    $ident = $stuff->screen_name;

    auth_routine('t', $uniqid, $ident);

  } else {
    $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/request_token', ''), 
array('oauth_callback' => $myurl));

    if($code == 200) {
      $_SESSION['oauth'] = $tmhOAuth->extract_params($tmhOAuth->response['response']);
      $method = isset($_REQUEST['signin']) ? 'authenticate' : 'authorize';
      header("Location: " . $tmhOAuth->url("oauth/{$method}", '')
        . "?oauth_token={$_SESSION['oauth']['oauth_token']}");

    } else {
      // error
      $tmhOAuth->pr(htmlentities($tmhOAuth->response['response']));
    }
  }
}
Example #13
0
    exit;
}
$callback_url = get_self_url_prefix() . "/twitter.php?op=callback";
$tmhOAuth = new tmhOAuth(array('consumer_key' => CONSUMER_KEY, 'consumer_secret' => CONSUMER_SECRET));
if ($op == 'clear') {
    unset($_SESSION['oauth']);
    header("Location: twitter.php");
    return;
}
if (isset($_REQUEST['oauth_verifier'])) {
    $op = 'callback';
    $tmhOAuth->config['user_token'] = $_SESSION['oauth']['oauth_token'];
    $tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];
    $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array('oauth_verifier' => $_REQUEST['oauth_verifier']));
    if ($code == 200) {
        $access_token = json_encode($tmhOAuth->extract_params($tmhOAuth->response['response']));
        unset($_SESSION['oauth']);
        db_query($link, "UPDATE ttrss_users SET twitter_oauth = '{$access_token}'\n\t\t\t\tWHERE id = " . $_SESSION['uid']);
    } else {
        header('Location: twitter.php?op=clear');
        return;
    }
}
if ($op == 'register') {
    $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/request_token', ''), array('oauth_callback' => $callback));
    if ($code == 200) {
        $_SESSION['oauth'] = $tmhOAuth->extract_params($tmhOAuth->response['response']);
        $method = isset($_REQUEST['signin']) ? 'authenticate' : 'authorize';
        $force = isset($_REQUEST['force']) ? '&force_login=1' : '';
        $forcewrite = isset($_REQUEST['force_write']) ? '&oauth_access_type=write' : '';
        $forceread = isset($_REQUEST['force_read']) ? '&oauth_access_type=read' : '';
Example #14
0
 /**
  * Handle dynamic Twitter authorization updates.
  * 
  * @param string $consumer_key Twitter application consumer key.
  * @param string $consumer_secret Twitter application consumer secret.
  * @param string $collection Collection the Twitter credentials belong to.
  */
 public static function ajax_twitter_account($consumer_key, $consumer_secret, $collection)
 {
     if (!class_exists('tmhOAuth')) {
         require_once self::$dir . '-/lib/twitter.php';
     }
     $oauth = new tmhOAuth(array_merge(array('consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret), ($consumer_key and $consumer_secret) ? array('user_token' => self::$config['collections'][$collection]['twitter']['oauth_token'], 'user_secret' => self::$config['collections'][$collection]['twitter']['oauth_secret']) : array()));
     if ($consumer_key and $consumer_secret) {
         self::$config['collections'][$collection]['twitter']['consumer_key'] = $consumer_key;
         self::$config['collections'][$collection]['twitter']['consumer_secret'] = $consumer_secret;
         update_option('webcomic_options', self::$config);
         $code = $oauth->request('GET', $oauth->url('1.1/account/verify_credentials'));
         if (200 === intval($code)) {
             $response = json_decode($oauth->response['response']);
             echo '<a href="http://twitter.com/', $response->screen_name, '" target="_blank"><b>@', $response->screen_name, '</b></a> <a href="http://twitter.com/settings/applications" target="_blank" class="button">', __('Revoke Access', 'webcomic'), '</a>';
         } else {
             $code = $oauth->request('POST', $oauth->url('oauth/request_token', ''), array('oauth_callback' => add_query_arg(array('webcomic_twitter_oauth' => true, 'webcomic_collection' => $collection), get_site_url())));
             if (200 === intval($code)) {
                 $response = $oauth->extract_params($oauth->response['response']);
                 self::$config['collections'][$collection]['twitter']['request_token'] = isset($response['oauth_token']) ? $response['oauth_token'] : '';
                 self::$config['collections'][$collection]['twitter']['request_secret'] = isset($response['oauth_token_secret']) ? $response['oauth_token_secret'] : '';
                 update_option('webcomic_options', self::$config);
                 echo (self::$config['collections'][$collection]['twitter']['oauth_token'] and self::$config['collections'][$collection]['twitter']['oauth_secret']) ? __('<p class="description">Your credentials could not be verified.</p>', 'webcomic') : '', '<a href="', add_query_arg(array('oauth_token' => $response['oauth_token']), $oauth->url('oauth/authorize', '')), '"><img src="', self::$url, '-/img/twitter.png" alt="', __('Sign in with Twitter', 'webcomic'), '"></a>';
             } else {
                 _e('Validation error. Please ensure your <a href="http://dev.twitter.com/apps/new" target="_blank">Twitter Application</a> <b>consumer key</b> and <b>consumer secret</b> are entered correctly.', 'webcomic');
             }
         }
     } else {
         echo '<span class="description">', __('Please enter your <a href="http://dev.twitter.com/apps/new" target="_blank">Twitter Application</a> <b>consumer key</b> and <b>consumer secret</b> below.', 'webcomic'), '</span>';
     }
 }
Example #15
0
            echo $this->run('user/login/newuser');
            return;
        }
    } else {
        // error
        @error_log('3. ' . $twauth->response['response']);
        $this->redirect($_GET['redirect']);
    }
} elseif (isset($_REQUEST['oauth_verifier'])) {
    // we're being called back by Twitter
    $twauth->config['user_token'] = $_SESSION['oauth']['oauth_token'];
    $twauth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];
    $params = array('oauth_verifier' => $_REQUEST['oauth_verifier']);
    $code = $twauth->request('POST', $twauth->url('oauth/access_token', ''), $params);
    if ($code == 200) {
        $_SESSION['access_token'] = $twauth->extract_params($twauth->response['response']);
        unset($_SESSION['oauth']);
        $this->redirect($here);
    } else {
        // error
        @error_log('2. ' . $twauth->response['response']);
        $this->redirect($_GET['redirect']);
    }
} else {
    // start oauth dance
    $params = array('oauth_callback' => $here, 'x_auth_access_type' => 'read');
    $code = $twauth->request('POST', $twauth->url('oauth/request_token', ''), $params);
    if ($code == 200) {
        $_SESSION['oauth'] = $twauth->extract_params($twauth->response['response']);
        $authurl = $twauth->url('oauth/authenticate', '') . '?oauth_token=' . $_SESSION['oauth']['oauth_token'] . '&force_login=1';
        $this->redirect($authurl);
function mm_twitter_connection_get_data($twitter_verifier, $current_url)
{
    if (session_status() == PHP_SESSION_NONE) {
        session_start();
    }
    require_once 'sdk/tmhOAuth.php';
    require_once 'sdk/tmhUtilities.php';
    $client_id = get_option('mm_twitter_connection_client_id');
    $client_secret = get_option('mm_twitter_connection_client_secret');
    $tmhOAuth = new tmhOAuth(array('consumer_key' => $client_id, 'consumer_secret' => $client_secret));
    $tmhOAuth->config['user_token'] = $_SESSION['mm_twitter_connect_oauth']['oauth_token'];
    $tmhOAuth->config['user_secret'] = $_SESSION['mm_twitter_connect_oauth']['oauth_token_secret'];
    $params = array('oauth_verifier' => $twitter_verifier);
    $code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), $params);
    if ($code == 200) {
        $access_token = $tmhOAuth->extract_params($tmhOAuth->response['response']);
        $tmhOAuth->config['user_token'] = $access_token['oauth_token'];
        $tmhOAuth->config['user_secret'] = $access_token['oauth_token_secret'];
        $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/account/verify_credentials'));
        if ($code == 200) {
            $result = json_decode($tmhOAuth->response['response'], ARRAY_A);
            if (is_array($result) && count($result) > 0) {
                $user_data['twitter_internal_id'] = $result['id'];
                $user_data['name'] = $result['name'];
                $user_data['picture'] = $result['profile_image_url'];
                return $user_data;
            }
        }
    }
    return false;
}
Example #17
0
 /**
  * Gets access tokens from a previous oauth request and stores them in the
  * options table
  *
  * @param string $verifier Verifier string, sent by Twitter
  * @return array Tokens
  */
 public function oauthAccessToken($verifier = null)
 {
     $requestTokens = $_SESSION['oauth'];
     $oauth = new tmhOAuth(array('curl_ssl_verifypeer' => false, 'consumer_key' => TWITTER_CONSUMER_KEY, 'consumer_secret' => TWITTER_CONSUMER_SECRET));
     $oauth->config['user_token'] = $requestTokens['oauth_token'];
     $oauth->config['user_secret'] = $requestTokens['oauth_token_secret'];
     $code = $oauth->request('POST', $oauth->url('oauth/access_token', ''), array('oauth_verifier' => $verifier));
     if ($code == 200) {
         $response = $oauth->extract_params($oauth->response['response']);
         $this->theme->options('twitter_oauth_token', $response['oauth_token']);
         $this->theme->options('twitter_oauth_token_secret', $response['oauth_token_secret']);
         unset($_SESSION['oauth']);
         return $response;
     } else {
         return array();
     }
 }
Example #18
0
        require "includes/db.php";
        $link = @mysql_connect(host, user, passdb);
        @mysql_select_db(database, $link);
        $usuario = @mysql_fetch_array(mysql_query("SELECT * FROM `Users` WHERE `ID` = '{$_SESSION["access_token"]["user_id"]}'"));
        if (!isset($usuario["ID"])) {
            mysql_query("INSERT INTO `Users` (`ID`, `screen_name`, `Nombre`, `Usos`) VALUES ('{$_SESSION["access_token"]["user_id"]}', '{$_SESSION["access_token"]["screen_name"]}', '{$credenciales->name}', '1')");
        } else {
            $usos = $usuario["Usos"] + 1;
            #<<<<<<< HEAD
            #         mysql_query("UPDATE `Users` SET `Usos` = '{$usos}', WHERE `Users`.`ID` = '{$_SESSION["access_token"]["user_id"]}'");
            #=======
            mysql_query("UPDATE `Users` SET `Usos` = '{$usos}' WHERE `Users`.`ID` = '{$_SESSION["access_token"]["user_id"]}'");
            #>>>>>>> a24835d789fdb44a73aced0baa6f176d4fd40783
        }
        setcookie("db", 1);
    }
    include "tools.php";
    // Estamos siendo Callbackeados
} elseif (isset($_REQUEST['oauth_verifier'])) {
    $tmhOAuth->config['user_token'] = $_SESSION['oauth']['oauth_token'];
    $tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];
    $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array('oauth_verifier' => $_REQUEST['oauth_verifier']));
    $_SESSION['access_token'] = $tmhOAuth->extract_params($tmhOAuth->response['response']);
    //   unset($_SESSION['oauth']);
    header("Location: {$here}");
    // OAuth
} else {
    //      $callback = isset($_REQUEST['oob']) ? 'oob' : $here;
    $tmhOAuth->request('POST', $tmhOAuth->url('oauth/request_token', ''), array('oauth_callback' => $here));
    include "auth.inc";
}
Example #19
0
<?php

/**
 * Obtain a users token and secret using xAuth.
 * Twitter must have granted you xAuth access to use this.
 *
 * Instructions:
 * 1) If you don't have one already, create a Twitter application on
 *      https://dev.twitter.com/apps
 * 2) From the application details page copy the consumer key and consumer
 *      secret into the place in this code marked with (YOUR_CONSUMER_KEY
 *      and YOUR_CONSUMER_SECRET)
 * 3) Fill in the username and password of the user you wish to obtain
 *      the user token and secret for.
 * 4) In a terminal or server type:
 *      php /path/to/here/xauth.php
 *
 * @author themattharris
 */
require '../tmhOAuth.php';
require '../tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array('consumer_key' => 'YOUR_CONSUMER_KEY', 'consumer_secret' => 'YOUR_CONSUMER_SECRET'));
$code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array('x_auth_username' => '', 'x_auth_password' => '', 'x_auth_mode' => 'client_auth'));
if ($code == 200) {
    $tokens = $tmhOAuth->extract_params($tmhOAuth->response['response']);
    tmhUtilities::pr($tokens);
} else {
    tmhUtilities::pr(htmlentities($tmhOAuth->response['response']));
}
Example #20
0
 /**
  * Handle Twitter OAuth authentication.
  * 
  * @uses Webcomic::$config
  * @hook init
  */
 public function twitter_oauth()
 {
     if (isset($_GET['webcomic_twitter_oauth'])) {
         if (!class_exists('tmhOAuth')) {
             require_once self::$dir . '-/lib/twitter.php';
         }
         $admin_url = add_query_arg(array('post_type' => $_GET['webcomic_collection'], 'page' => "{$_GET['webcomic_collection']}-options"), admin_url('edit.php'));
         if (isset($_GET['denied'])) {
             wp_die(sprintf(__('Authorization denied. <a href="%1$s">Return to %2$s Settings</a>', 'webcomic'), $admin_url, self::$config['collections'][$_GET['webcomic_collection']]['name']), __('Twitter Authorization Denied | Webcomic', 'webcomic'), array('response' => 200));
         } else {
             $oauth = new tmhOAuth(array('consumer_key' => self::$config['collections'][$_GET['webcomic_collection']]['twitter']['consumer_key'], 'consumer_secret' => self::$config['collections'][$_GET['webcomic_collection']]['twitter']['consumer_secret'], 'user_token' => self::$config['collections'][$_GET['webcomic_collection']]['twitter']['request_token'], 'user_secret' => self::$config['collections'][$_GET['webcomic_collection']]['twitter']['request_secret']));
             $code = $oauth->request('POST', str_replace('.json', '', $oauth->url('oauth/access_token', '')), array('oauth_verifier' => $_GET['oauth_verifier']));
             if (200 === intval($code)) {
                 $response = $oauth->extract_params($oauth->response['response']);
                 self::$config['collections'][$_GET['webcomic_collection']]['twitter']['oauth_token'] = $response['oauth_token'];
                 self::$config['collections'][$_GET['webcomic_collection']]['twitter']['oauth_secret'] = $response['oauth_token_secret'];
                 self::$config['collections'][$_GET['webcomic_collection']]['twitter']['request_token'] = self::$config['collections'][$_GET['webcomic_collection']]['twitter']['request_secret'] = '';
                 update_option('webcomic_options', self::$config);
                 $oauth->config['user_token'] = $response['oauth_token'];
                 $oauth->config['user_secret'] = $response['oauth_token_secret'];
                 $code = $oauth->request('GET', $oauth->url('1.1/account/verify_credentials'));
                 if (200 === intval($code)) {
                     $response = json_decode($oauth->response['response']);
                     wp_die(sprintf(__('Newly published %1$s webcomics will be tweeted to <a href="%2$s">%3$s</a>. <a href="%4$s">Return to %1s Settings</a>', 'webcomic'), self::$config['collections'][$_GET['webcomic_collection']]['name'], "http://twitter.com/{$response->screen_name}", $response->screen_name, $admin_url), __('Twitter Authorization Complete | Webcomic', 'webcomic'), array('response' => 200));
                 } else {
                     wp_die(sprintf(__('Your credentials could not be verified. Please ensure that your <b>consumer key</b> and <b>consumer secret</b> were entered correctly and <a href="%s">try again.</a>', 'webcomic'), $admin_url), __('Twitter Authorization Failed | Webcomic', 'webcomic'), array('response' => 200));
                 }
             } else {
                 wp_die(sprintf(__('Your credentials could not be verified. Please ensure that your <b>consumer key</b> and <b>consumer secret</b> were entered correctly and <a href="%s">try again.</a>', 'webcomic'), $admin_url), __('Twitter Authorization Failed | Webcomic', 'webcomic'), array('response' => 200));
             }
         }
     }
 }
Example #21
0
 function authorize_twitter()
 {
     if (!App::import('Lib', 'tmh_oauth')) {
         $this->Session->setFlash(sprintf(__('Failed to load the %s library! Contact your system administrator.', true), 'Twitter OAuth'), 'default', array('class' => 'error'));
         $this->redirect(array('action' => 'preferences'));
     }
     define('__DIR__', ROOT . DS . APP_DIR . DS . 'libs');
     $tmhOAuth = new tmhOAuth(array('consumer_key' => Configure::read('twitter.consumer_key'), 'consumer_secret' => Configure::read('twitter.consumer_secret')));
     if (!empty($this->params['url']['oauth_token'])) {
         $response = $this->Session->read('Twitter.response');
         $this->Session->delete('Twitter.response');
         if ($this->params['url']['oauth_token'] !== $response['oauth_token']) {
             $this->Session->setFlash(__('The oauth token you started with doesn\'t match the one you\'ve been redirected with. Do you have multiple tabs open?', true), 'default', array('class' => 'warning'));
             $this->redirect(array('action' => 'preferences'));
         }
         if (!isset($this->params['url']['oauth_verifier'])) {
             $this->Session->setFlash(__('The oauth verifier is missing so we cannot continue. Did you deny the appliction access?', true), 'default', array('class' => 'warning'));
             $this->redirect(array('action' => 'preferences'));
         }
         // Update with the temporary token and secret
         $tmhOAuth->reconfigure(array_merge($tmhOAuth->config, array('token' => $response['oauth_token'], 'secret' => $response['oauth_token_secret'])));
         $code = $tmhOAuth->user_request(array('method' => 'POST', 'url' => $tmhOAuth->url('oauth/access_token', ''), 'params' => array('oauth_verifier' => trim($this->params['url']['oauth_verifier']))));
         if ($code == 200) {
             $oauth_creds = $tmhOAuth->extract_params($tmhOAuth->response['response']);
             if ($this->Person->updateAll(array('twitter_token' => "'{$oauth_creds['oauth_token']}'", 'twitter_secret' => "'{$oauth_creds['oauth_token_secret']}'"), array('Person.id' => $this->UserCache->currentId()))) {
                 $this->Session->setFlash(sprintf(__('Your Twitter authorization has been completed. You can always revoke this at any time through the preferences page.', true), __('person', true)), 'default', array('class' => 'success'));
             } else {
                 $this->Session->setFlash(sprintf(__('Twitter authorization was received, but the database failed to update.', true), __('person', true)), 'default', array('class' => 'warning'));
             }
         } else {
             $this->Session->setFlash(__('There was an error communicating with Twitter.', true) . ' ' . $tmhOAuth->response['response'], 'default', array('class' => 'warning'));
         }
         $this->redirect(array('action' => 'preferences'));
     } else {
         $code = $tmhOAuth->apponly_request(array('without_bearer' => true, 'method' => 'POST', 'url' => $tmhOAuth->url('oauth/request_token', ''), 'params' => array('oauth_callback' => Router::url(Router::normalize($this->here), true))));
         if ($code != 200) {
             $this->Session->setFlash(__('There was an error communicating with Twitter.', true) . ' ' . $tmhOAuth->response['response'], 'default', array('class' => 'warning'));
             $this->redirect(array('action' => 'preferences'));
         }
         // store the params into the session so they are there when we come back after the redirect
         $response = $tmhOAuth->extract_params($tmhOAuth->response['response']);
         // check the callback has been confirmed
         if ($response['oauth_callback_confirmed'] !== 'true') {
             $this->Session->setFlash(__('The callback was not confirmed by Twitter so we cannot continue.', true) . ' ' . $tmhOAuth->response['response'], 'default', array('class' => 'warning'));
             $this->redirect(array('action' => 'preferences'));
         } else {
             $this->Session->write('Twitter.response', $response);
             $this->redirect($tmhOAuth->url('oauth/authorize', '') . "?oauth_token={$response['oauth_token']}");
         }
     }
 }
Example #22
0
    // store the params into the session so they are there when we come back after the redirect
    $_SESSION['oauth'] = $tmhOAuth->extract_params($tmhOAuth->response['response']);
    // check the callback has been confirmed
    if ($_SESSION['oauth']['oauth_callback_confirmed'] !== 'true') {
        error('The callback was not confirmed by Twitter so we cannot continue.');
    } else {
        $url = $tmhOAuth->url('oauth/authorize', '') . "?oauth_token={$_SESSION['oauth']['oauth_token']}";
        header("Location: " . $url);
        exit;
    }
} else {
    // Step 3: This is the code that runs when Twitter redirects the user to the callback. Exchange the temporary token for a permanent access token
    $tmhOAuth = new tmhOAuth(array('consumer_key' => CONSUMER_KEY, 'consumer_secret' => CONSUMER_SECRET, 'user_token' => $_SESSION['oauth']['oauth_token'], 'user_secret' => $_SESSION['oauth']['oauth_token_secret']));
    $code = $tmhOAuth->user_request(array('method' => 'POST', 'url' => $tmhOAuth->url('oauth/access_token', ''), 'params' => array('oauth_verifier' => trim($_REQUEST['oauth_verifier']))));
    if ($code == 200) {
        $oauth_creds = $tmhOAuth->extract_params($tmhOAuth->response['response']);
        header("refresh:3; url=admin.php");
        echo "Account <b>" . $oauth_creds['screen_name'] . "</b> verified!";
        $oauth_token = $oauth_creds['oauth_token'];
        $oauth_token_secret = $oauth_creds['oauth_token_secret'];
        $id = $_SESSION['id'];
        if (!($upd_token = $mysqli->prepare("UPDATE destination SET oauth_token = ? , oauth_token_secret = ? WHERE id = ?"))) {
            die("Prepare an SQL statement error: (" . $mysqli->errno . ") " . $mysqli->error);
        }
        if (!$upd_token->bind_param("ssi", $oauth_token, $oauth_token_secret, $id)) {
            die("Error binding parameters: (" . $upd_token->errno . ") " . $upd_token->error);
        }
        if (!$upd_token->execute()) {
            echo "Token update error: (" . $upd_token->errno . ") " . $upd_token->error;
        }
        $mysqli->close;