Beispiel #1
0
function douban_callback()
{
    OAuthRequester::requestAccessToken(DOUBAN_KEY, $_SESSION['oauth_token'], 0, 'POST', $options = array('oauth_verifier' => $_SESSION['oauth_token']));
    $req = new OAuthRequester('http://api.douban.com/people/' . urlencode('@me'), 'get');
    $res = $req->doRequest();
    $user_data = new SimpleXMLElement($res['body']);
    $uid = array_pop(explode('/', $user_data->id));
    $auth_type = 'douban';
    $auth = R::findOne('oauth', "uid=? AND type=?", array($uid, $auth_type));
    if (!$auth) {
        $auth = R::dispense('oauth');
        $auth->uid = $uid;
        $auth->type = $auth_type;
        $encrypt_key = rand(100000, 999999);
        $auth->secret = $encrypt_key;
    } else {
        $encrypt_key = $auth->secret;
    }
    $cookie_str = sha1(implode('', array($uid, $auth_type, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], $encrypt_key)));
    $expire = time() + 3600 * 24 * 365;
    setcookie('s', $cookie_str, $expire);
    setcookie('auth_type', $auth_type, $expire);
    setcookie('uid', $uid, $expire);
    $auth->setMeta('buildcommand.unique', array(array('uid', 'type')));
    $auth->setMeta('buildcommand.indexes', array('uid' => 'uid'));
    R::store($auth);
}
function getResponseAPI($userIdZyncro, $sessionid, $serviceAPI)
{
    // Init the OAuthStore
    $options = array('consumer_key' => CONSUMER_KEY, 'consumer_secret' => CONSUMER_SECRET, 'server_uri' => OAUTH_HOST, 'request_token_uri' => REQUEST_TOKEN_URL, 'signature_methods' => array('HMAC-SHA1'), 'authorize_uri' => AUTHORIZE_URL, 'access_token_uri' => ACCESS_TOKEN_URL);
    // Note: do not use "Session" storage in production. Prefer a database
    // storage, such as MySQL.
    OAuthStore::instance("Session", $options);
    try {
        // get a request token
        $getRequestTokenParams = array();
        $tokenResultParams = OAuthRequester::requestRequestToken(CONSUMER_KEY, 0, $getRequestTokenParams, 'GET');
        // get an access token
        $oauthToken = $tokenResultParams['token'];
        $getAccessTokenParams = array('oauth_verifier' => $sessionid);
        OAuthRequester::requestAccessToken(CONSUMER_KEY, $oauthToken, 0, 'POST', $getAccessTokenParams);
        // make the request.
        $urlRequest = OAUTH_HOST . $serviceAPI;
        $request = new OAuthRequester($urlRequest, 'GET');
        $result = $request->doRequest(0);
        if ($result['code'] == 200) {
            return $result['body'];
        }
    } catch (OAuthException2 $e) {
    }
}
 public static function authorize($consumer_key, $consumer_secret, $oauth_token, $verifier, $store = "MySQL", $user_id = 1, $extra_options = array())
 {
     //Obtain an access token. This token can be reused until it expires.
     OAuthClient::storeInstance(OAuthClient::merge_options($consumer_key, $consumer_secret, $extra_options), $store);
     try {
         OAuthRequester::requestAccessToken($consumer_key, $oauth_token, $user_id, 'POST', array('oauth_token' => $oauth_token, 'oauth_verifier' => $verifier));
     } catch (OAuthException2 $e) {
         var_dump($e);
         return;
     }
 }
Beispiel #4
0
 public function exchangeapitokenAction()
 {
     $service = new Ml_Model_Service();
     $this->_helper->loadOauthstore->setinstance();
     $userId = $service->getInput("User ID");
     $consumerKey = $service->getInput("Consumer key");
     $oauthToken = $service->getInput("Oauth token");
     require EXTERNAL_LIBRARY_PATH . '/oauth-php/library/OAuthRequester.php';
     try {
         OAuthRequester::requestAccessToken($consumerKey, $oauthToken, $userId);
         echo "Request token exchanged for access token.\n";
     } catch (OAuthException $e) {
         // Something wrong with the oauth_token.
         // Could be:
         // 1. Was already ok
         // 2. We were not authorized
         throw $e;
     }
 }
//- Prepare the PHP OAuth for consuming our Oxygen service
$options = array('consumer_key' => ConsumerKey, 'consumer_secret' => ConsumerSecret, 'server_uri' => BaseUrl, 'request_token_uri' => BaseUrl . 'OAuth/RequestToken', 'authorize_uri' => BaseUrl . 'OAuth/Authorize', 'access_token_uri' => BaseUrl . 'OAuth/AccessToken');
OAuthStore::instance('Session', $options);
$fname = realpath(dirname(__FILE__)) . '/token.txt';
$token = unserialize(file_get_contents($fname));
unlink($fname);
//- To disable the SSL check to avoid an exception with invalidate certificate on the server,
//- use the cURL CURLOPT_SSL_VERIFYPEER option and set it to false.
//- 3rd leg: Get the 'access token' and session
$access = '';
try {
    //- The following line is for reference only, the call to OAuthRequester::requestRequestToken() included that step. But you may need
    //- to call that line with the correct parameters in you run that 'leg' in a different PHP session.
    OAuthStore::instance()->addServerToken(ConsumerKey, 'request', $token['oauth_token'], $token['oauth_token_secret'], 0, array());
    //- $access will contain the server response in case you modified the Google library like documented above
    $access = OAuthRequester::requestAccessToken(ConsumerKey, $token['oauth_token'], 0, 'POST', $options, array(CURLOPT_SSL_VERIFYPEER => 0));
    //- If you did not modify OAuthRequester::requestAccessToken() function as documented above, do this instead
    // $access =array (
    // 	'oauth_token' => OAuthStore::instance ()->getSecretsForSignature ('', 0) ['token'],
    // 	'oauth_token_secret' => OAuthStore::instance ()->getSecretsForSignature ('', 0) ['token_secret'],
    // ) ;
    /*
    define ('OAUTH_HOST', 'http://' . $_SERVER ['SERVER_NAME']) ;
    $request =new OAuthRequester (OAUTH_HOST . $_SERVER ['PHP_SELF'], 'POST', $token) ;
        $access =$request->doRequest (0) ;
    */
    //- In this sample, we save the token to a file, and use it in the Refresh example
    $fname = realpath(dirname(__FILE__)) . '/access_token.txt';
    file_put_contents($fname, serialize($access));
} catch (Exception $e) {
    echo "OAuth/AccessToken\n", 'Caught exception: ', $e->getMessage(), "\n";
Beispiel #6
0
         $tokenResultParams = OAuthRequester::requestRequestToken(SFDOCTOR_CONSUMER_KEY, 0, $getAuthTokenParams);
         //  redirect to the 65doctor authorization page, they will redirect back
         header("Location: " . SFDOCTOR_AUTHORIZE_URL . "?oauth_token=" . $tokenResultParams['token'] . $signature);
     } else {
         echo '<pre>';
         print_r('Missing username or password.');
         echo '</pre>';
         exit;
     }
 } else {
     //  STEP 2:  Get an access token
     $oauthToken = $_GET["oauth_token"];
     // echo "oauth_verifier = '" . $oauthVerifier . "'<br/>";
     $tokenResultParams = $_GET;
     try {
         OAuthRequester::requestAccessToken(SFDOCTOR_CONSUMER_KEY, $oauthToken, 0, 'POST', $_GET);
     } catch (OAuthException2 $e) {
         echo '<pre>';
         print_r($e);
         echo '</pre>';
         // Something wrong with the oauth_token.
         // Could be:
         // 1. Was already ok
         // 2. We were not authorized
         return;
     }
     $_SESSION['SFDOCTOR_TOKEN'] = $tokenResultParams;
     // make the resource owner requestrequest.
     //		$request = new OAuthRequester($uriProfile, 'GET', $tokenResultParams);
     //		$result = $request->doRequest(0);
     //		if ($result['code'] == 200) {
Beispiel #7
0
OAuthStore::instance("Session", $options);
try {
    //  STEP 1:  If we do not have an OAuth token yet, go get one
    if (empty($_GET["oauth_token"])) {
        $getAuthTokenParams = array('scope' => 'http://docs.google.com/feeds/', 'xoauth_displayname' => 'Oauth test', 'oauth_callback' => 'XXXXXXXXXXX');
        // get a request token
        $tokenResultParams = OAuthRequester::requestRequestToken(GOOGLE_CONSUMER_KEY, 0, $getAuthTokenParams);
        //  redirect to the google authorization page, they will redirect back
        header("Location: " . GOOGLE_AUTHORIZE_URL . "?btmpl=mobile&oauth_token=" . $tokenResultParams['token']);
    } else {
        //  STEP 2:  Get an access token
        $oauthToken = $_GET["oauth_token"];
        // echo "oauth_verifier = '" . $oauthVerifier . "'<br/>";
        $tokenResultParams = $_GET;
        try {
            OAuthRequester::requestAccessToken(GOOGLE_CONSUMER_KEY, $oauthToken, 0, 'POST', $_GET);
        } catch (OAuthException2 $e) {
            var_dump($e);
            // Something wrong with the oauth_token.
            // Could be:
            // 1. Was already ok
            // 2. We were not authorized
            return;
        }
        // make the docs requestrequest.
        $request = new OAuthRequester("http://docs.google.com/feeds/documents/private/full", 'GET', $tokenResultParams);
        $result = $request->doRequest(0);
        if ($result['code'] == 200) {
            var_dump($result['body']);
        } else {
            echo 'Error';
Beispiel #8
0
 public function getAccessToken($oauth_user_id)
 {
     //  STEP 2:  Get an access token
     $oauthToken = $_GET["oauth_token"];
     // echo "oauth_verifier = '" . $oauthVerifier . "'<br/>";
     $tokenResultParams = $_GET;
     OAuthRequester::requestAccessToken($this->oAuthConsumerKey, $oauthToken, $oauth_user_id, 'POST', $_GET);
 }
Beispiel #9
0
// storage, such as MySQL.
OAuthStore::instance("Session", $options);
try {
    //  STEP 1:  If we do not have an OAuth token yet, go get one
    if (empty($_GET["oauth_verifier"])) {
        $getAuthTokenParams = array('oauth_callback' => 'oob');
        $options = array('oauth_as_header' => false);
        // get a request token
        $tokenResultParams = OAuthRequester::requestRequestToken(OPERA_CONSUMER_KEY, 0, $getAuthTokenParams, 'POST', $options);
        $_SESSION['oauth_token'] = $tokenResultParams['token'];
        //  redirect to the opera authorization page, they will redirect back
        header("Location: " . OPERA_AUTHORIZE_URL . "?oauth_token=" . $tokenResultParams['token']);
    } else {
        //  STEP 2:  Get an access token
        try {
            OAuthRequester::requestAccessToken(OPERA_CONSUMER_KEY, $_SESSION['oauth_token'], 0, 'POST', $options = array('oauth_verifier' => $_GET['oauth_verifier']));
        } catch (OAuthException2 $e) {
            var_dump($e);
            // Something wrong with the oauth_token.
            // Could be:
            // 1. Was already ok
            // 2. We were not authorized
            return;
        }
        // make the docs requestrequest.
        $request = new OAuthRequester("http://my.opera.com/community/api/users/status.pl", 'GET');
        $result = $request->doRequest(0, array(CURLOPT_HTTPHEADER => array('Accept: application/json')));
        if ($result['code'] == 200) {
            var_dump($result['body']);
        } else {
            echo 'Error';
<?php

require_once '../../vendor/autoload.php';
define('OAUTH_HOST', 'http://' . $_SERVER['SERVER_NAME']);
$id = 1;
// Init the OAuthStore
$options = array('consumer_key' => '<MYCONSUMERKEY>', 'consumer_secret' => '<MYCONSUMERSECRET>', 'server_uri' => OAUTH_HOST, 'request_token_uri' => OAUTH_HOST . '/request_token.php', 'authorize_uri' => OAUTH_HOST . '/login.php', 'access_token_uri' => OAUTH_HOST . '/access_token.php');
OAuthStore::instance('Session', $options);
if (empty($_GET['oauth_token'])) {
    // get a request token
    $tokenResultParams = OAuthRequester::requestRequestToken($options['consumer_key'], $id);
    header('Location: ' . $options['authorize_uri'] . '?oauth_token=' . $tokenResultParams['token'] . '&oauth_callback=' . urlencode('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']));
} else {
    // get an access token
    $oauthToken = $_GET['oauth_token'];
    $tokenResultParams = $_GET;
    OAuthRequester::requestAccessToken($options['consumer_key'], $tokenResultParams['oauth_token'], $id, 'POST', $_GET);
    $request = new OAuthRequester(OAUTH_HOST . '/test_request.php', 'GET', $tokenResultParams);
    $result = $request->doRequest(0);
    if ($result['code'] == 200) {
        var_dump($result['body']);
    } else {
        echo 'Error';
    }
}
Beispiel #11
0
 /**
  * Get access token
  *
  * @param	string $verifier OAuth verifier, got after authorization
  * @access	protected
  * @return	array
  */
 protected function _setupAccessToken($verifier)
 {
     ApiDebug::p('requesting access token');
     $accessTokenInfo = array();
     $oauth = $this->_getOAuthInstance();
     \OAuthRequester::requestAccessToken(self::$_apiKey, self::$_requestToken, 0, 'POST', array('oauth_verifier' => $verifier), self::_getCurlOptions());
     $accessTokenInfo['oauth_token'] = $_SESSION['oauth_' . self::$_apiKey]['token'];
     $accessTokenInfo['oauth_token_secret'] = $_SESSION['oauth_' . self::$_apiKey]['token_secret'];
     ApiDebug::p('got access token info', $accessTokenInfo);
     self::$_accessToken = $accessTokenInfo['oauth_token'];
     self::$_accessSecret = $accessTokenInfo['oauth_token_secret'];
     return $accessTokenInfo;
 }
Beispiel #12
0
    $queryParams = $request->getQueryString(false);
    header('Location: ' . $requestTokenUrl . '?' . $queryParams);
} elseif ($_GET['oauth_token']) {
    /*
     * Login callback. After the user logs in, they are redirected back to this
     * page with the oauth_token field specified. We then can use that token (as
     * well as some other request params) to get an access token to use
     *
     * Once the access token is obtained, we immediately redirect to the main
     * logged-in page to allow the user to make requests.
     */
    $oauthToken = $_GET['oauth_token'];
    $oauthTokenSecret = $_GET['oauth_token_secret'];
    $store->addServerToken($consumerKey, 'request', $oauthToken, $oauthTokenSecret, 0);
    $accessTokenParams = array('oauth_verifier' => $_GET['oauth_verifier'], 'oauth_callback' => $loginCallback);
    OAuthRequester::requestAccessToken($consumerKey, $oauthToken, 0, 'POST', $accessTokenParams);
    header('Location: ka_client.php?logged_in=1');
} elseif ($_GET['logged_in']) {
    /*
     * Main logged-in page. Display a form for typing in a query, and execute a
     * query and display its results if one was specified.
     */
    $defaultQuery = $_GET['query'];
    if (!$defaultQuery) {
        $defaultQuery = '/api/v1/user';
    }
    ?>
    Make a GET request:
    <form>
        <input type="hidden" name="logged_in" value=1>
        <input type="text" name="query" value="<?php 
Beispiel #13
0
 /**
  * finishAuthenticate - Should be invoked from callback uri passed to authorize
  *
  * @param string $consumerKey Access key 
  * @param integer $userId A user identificator
  * @param string $oauthToken Token got in call to authorize
  * @return void
  */
 public function finishAuthenticate($consumerKey, $userId, $oauthToken)
 {
     OAuthRequester::requestAccessToken($consumerKey, $oauthToken, $userId);
 }
Beispiel #14
0
 /**
  * 绑定开心网.
  * @param string $username
  * @param string $password
  * @param boolean $follow
  */
 private function kaixin001($username, $password, $follow)
 {
     set_time_limit(120);
     require_once Kohana::find_file('vendor', 'oauth/OAuthRequester');
     $okey = Kohana::config('uap.oauth');
     define("MOMO_CONSUMER_KEY", $okey['kaixin001.com']['WB_AKEY']);
     define("MOMO_CONSUMER_SECRET", $okey['kaixin001.com']['WB_SKEY']);
     define("MOMO_OAUTH_HOST", "http://api.kaixin001.com");
     define("MOMO_REQUEST_TOKEN_URL", MOMO_OAUTH_HOST . "/oauth/request_token");
     define("MOMO_AUTHORIZE_URL", MOMO_OAUTH_HOST . "/oauth/authorize");
     define("MOMO_ACCESS_TOKEN_URL", MOMO_OAUTH_HOST . "/oauth/access_token");
     define('OAUTH_TMP_DIR', function_exists('sys_get_temp_dir') ? sys_get_temp_dir() : realpath($_ENV["TMP"]));
     $store = OAuthStore::instance('MySQL');
     $usr_id = $this->user_id;
     try {
         try {
             $store->getServer(MOMO_CONSUMER_KEY, $usr_id);
         } catch (OAuthException2 $e) {
             //初始化
             $server = array('consumer_key' => MOMO_CONSUMER_KEY, 'consumer_secret' => MOMO_CONSUMER_SECRET, 'server_uri' => MOMO_OAUTH_HOST, 'signature_methods' => array('HMAC-SHA1', 'PLAINTEXT'), 'request_token_uri' => MOMO_REQUEST_TOKEN_URL, 'authorize_uri' => MOMO_AUTHORIZE_URL, 'access_token_uri' => MOMO_ACCESS_TOKEN_URL);
             //$store->deleteServer(MOMO_CONSUMER_KEY, $usr_id);
             $consumer_key = $store->updateServer($server, $usr_id);
         }
         $tokenResultParams = OAuthRequester::requestRequestToken(MOMO_CONSUMER_KEY, $usr_id, array("scope" => "basic create_records"), "GET");
         usleep(5);
         //STEP 1:  If we do not have an OAuth token yet, go get one
         $Params = array("email" => $username, "password" => $password, "callback" => urlencode('http://api.kaixin001.com/oauth/authorize?oauth_token=' . $tokenResultParams['token'] . '&oauth_callback=' . urlencode(url::site("bind/confirm")) . '&from=&oauth_client=1'), "appkey" => MOMO_CONSUMER_KEY, "fromclient" => "", "return" => "", "login" => "登陆");
         $query = '';
         foreach ($Params as $key => $value) {
             $query .= $key . '=' . $value . '&';
         }
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
         if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
             $cip = $_SERVER["HTTP_CLIENT_IP"];
         } else {
             if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
                 $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
             } else {
                 if (!empty($_SERVER["REMOTE_ADDR"])) {
                     $cip = $_SERVER["REMOTE_ADDR"];
                 } else {
                     //找不到默認為momo服務器ip
                     $cip = "58.22.103.199";
                 }
             }
         }
         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', "CLIENT-IP: {$cip}", "X-FORWARDED-FOR: {$cip}"));
         curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.2.23) Gecko/20110921 Ubuntu/10.10 (maverick) Firefox/3');
         curl_setopt($ch, CURLOPT_URL, "http://wap.kaixin001.com/auth/login.php?isoauth=1");
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_HEADER, true);
         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
         //curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); //是否抓取302跳转后的
         $txt = curl_exec($ch);
         curl_close($ch);
         preg_match('@Location:(.*)@i', $txt, $matches);
         if (!isset($matches[1]) || stripos($matches[1], '/oauth/authorize') === FALSE) {
             $this->send_response(407, null, "用户名或密码错误");
             return null;
         }
         $Params = array("loginnewsfeed" => 1, "oauth_token" => $tokenResultParams['token'], "oauth_callback" => "", "appid" => $okey['kaixin001.com']['APP_ID'], "oauth_client" => 1, "accept" => "允许");
         $query = '';
         foreach ($Params as $key => $value) {
             $query .= $key . '=' . $value . '&';
         }
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_POST, true);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', "CLIENT-IP: {$cip}", "X-FORWARDED-FOR: {$cip}"));
         curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.2.23) Gecko/20110921 Ubuntu/10.10 (maverick) Firefox/3');
         curl_setopt($ch, CURLOPT_URL, trim($matches[1]));
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_HEADER, true);
         curl_setopt($ch, CURLOPT_TIMEOUT, 30);
         $txt = curl_exec($ch);
         curl_close($ch);
         preg_match('@你获取到的授权码是:<b>(\\w+)</b>@i', $txt, $matches);
         if (!isset($matches[1])) {
             $this->send_response(500, null, "oauth_verifier未取到");
             return null;
         }
         $oauth_verifier = $matches[1];
         usleep(5);
         //STEP 2:  Get an access token
         try {
             $access_token = OAuthRequester::requestAccessToken(MOMO_CONSUMER_KEY, $tokenResultParams['token'], $usr_id, 'POST', array("oauth_verifier" => $oauth_verifier));
             try {
                 //取得个人信息
                 usleep(5);
                 $request = new OAuthRequester("http://api.kaixin001.com/users/me.json", 'GET');
                 $result = $request->doRequest($this->user_id);
                 if ($result['code'] != 200) {
                     //$this->send_response(500, null, $result['body']);
                 }
                 $result = json_decode($result['body'], true);
                 if ($result) {
                     $access_token = array_merge($access_token, array("name" => $result["name"], "user_id" => $result["uid"], "homepage" => "http://www.kaixin001.com/home/{$result["uid"]}.html" . $domain));
                 }
             } catch (OAuthException2 $e) {
             }
             try {
                 if ($follow) {
                     //关注官网
                     //usleep(5);
                     //$request = new OAuthRequester("", 'POST');
                     //$result = $request->doRequest($this->user_id);
                 }
             } catch (OAuthException2 $e) {
             }
             return $access_token;
         } catch (OAuthException2 $e) {
             $this->send_response(500, null, $e->getMessage());
             //echo "OAuthException:  " . $e->getMessage();
             //var_dump( $e );
             return;
         }
     } catch (OAuthException2 $e) {
         $this->send_response(500, null, $e->getMessage());
         //echo "OAuthException:  " . $e->getMessage();
         //var_dump($e);
     }
 }
<?php

/*
 * Here we're going to use the token returned from splitwise, and store the access token in the mysql database.
 * 
 */
require "oauth/OAuthStore.php";
require "oauth/OAuthRequester.php";
require "config.php";
$oauth_token = $_GET['oauth_token'];
$oauth_verifyer = $_GET['oauth_verifier'];
try {
    $data = OAuthRequester::requestAccessToken($key, $oauth_token, $user_id, "POST", array('oauth_verifier' => $oauth_verifyer));
    echo "<pre>" . print_r($data, true) . "\n";
    echo "request ok";
} catch (OAuthException2 $e) {
    echo "<pre>";
    print_r($e);
    // Something wrong with the oauth_token.
    // Could be:
    // 1. Was already ok
    // 2. We were not authorized
}
Beispiel #16
0
<?php

// Load: http://code.google.com/p/oauth-php/
require_once 'oauth-php-r50/library/OAuthStore.php';
require_once 'oauth-php-r50/library/OAuthRequester.php';
require_once 'config.inc.php';
// Request parameters are oauth_token, consumer_key and usr_id.
$oauth_token = $_GET['oauth_token'];
try {
    OAuthRequester::requestAccessToken($consumer_key, $oauth_token, $user_id);
} catch (OAuthException $e) {
    // Something wrong with the oauth_token.
    // Could be:
    // 1. Was already ok
    // 2. We were not authorized
    print 'error!';
    print_r($e);
}
header('Location: index.php');
exit;
Beispiel #17
0
 /**
  * Authenticate against the OAuth provider.
  *
  * @param string $oauthToken The autentication code from Google.
  *
  * @return void
  */
 public function authenticate($oauthToken)
 {
     $this->oauthToken = $oauthToken;
     try {
         \OAuthRequester::requestAccessToken($this->key, $oauthToken, 0, 'POST', $_GET);
     } catch (\OAuthException2 $e) {
         echo "authenticate Exception:<pre>";
         print_r($e);
         echo "</pre>";
     }
 }
Beispiel #18
0
<?php

require dirname(__FILE__) . '/fx.php';
try {
    OAuthRequester::requestAccessToken($server['consumer_key'], $_GET['oauth_token'], $user_id);
    // We need to verify that they're who they said they were
    // Obtain a request object for the request we want to make
    $req = new OAuthRequester($server['server_uri'] . '/account/verify_credentials.json', 'GET', array());
    // Sign the request, perform a curl request and return the results, throws OAuthException exception on an error
    try {
        $result = $req->doRequest($user_id);
    } catch (OAuthException $e) {
        echo 'Something went wrong: ' . $e->getMessage();
        //header('Location: /follows/manage/register');
        exit;
    }
    $info = json_decode($result['body']);
    if ($info->screen_name == $user_id) {
        header('Location: /follows/manage/');
        exit;
    }
    $store->deleteServer($server['consumer_key'], $user_id);
    setcookie('username', '', strtotime('2000-01-01 00:00:00'), '/follows', 'twitapps.com');
    echo 'Username mismatch!';
} catch (OAuthException $e) {
    echo 'Something went wrong: ' . $e->getMessage();
}