Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if(!isset($_SESSION['REQUEST_TOKENS'])) {
- $_SESSION['REQUEST_TOKENS'] = array();
- }
- define('CALL_BACK_URL', 'http://localhost:3000/');
- class logme
- {
- public static function say($msg)
- {
- openlog("OAUTH-P", 0, LOG_LOCAL0);
- syslog(LOG_DEBUG, $msg);
- }
- }
- class consumerDS
- {
- private static $consumers = array(
- 'viraj' => array('secret'=>'asjh^&556GHJG', 'status'=>0)
- );
- public static function getConsumer($consumerKey) {
- logme::say('looking up.. ' . $consumerKey);
- if(array_key_exists($consumerKey, self::$consumers)) {
- return (object)self::$consumers[$consumerKey];
- }
- return null;
- }
- }
- //echo '<pre>';
- //echo $_SERVER['HTTP_HOST'] . ' ' . $_SERVER['REQUEST_URI'] . "\n";
- //print_r($_SERVER);
- //echo '</pre>';
- $__m = $__o = $__a = null;
- extract(array_combine(array('__m','__o','__a'), array_pad(explode(DIRECTORY_SEPARATOR, trim($_SERVER['REQUEST_URI'],DIRECTORY_SEPARATOR), 3),3,null)),EXTR_IF_EXISTS);
- //echo 'm->' . $__m . ' o->' . $__o . ' a->' . $__a . "\n";
- //echo serialize($_GET);
- //echo serialize($_POST);
- class oAuthServer {
- public function __construct()
- {
- $this->op = new OAuthProvider();
- $this->op->consumerHandler(array($this, 'lookupConsumer'));
- $this->op->timestampNonceHandler(array($this, 'timestampNonceChecker'));
- $this->op->tokenHandler(array($this, 'tokenHandler'));
- logme::say(__METHOD__);
- $this->op->setRequestTokenPath('/request_token');
- $this->op->checkOAuthRequest();
- logme::say('---> ' . $this->op->consumer_secret);
- }
- public function lookupConsumer($op)
- {
- logme::say(__METHOD__);
- $foundConsumer = consumerDS::getConsumer($op->consumer_key);
- if(is_null($foundConsumer)) {
- logme::say('unknown ' . $op->consumer_key);
- return OAUTH_CONSUMER_KEY_UNKNOWN;
- }
- else if ($foundConsumer->status != 0){
- logme::say('refused ' . $op->consumer_key);
- return OAUTH_CONSUMER_KEY_REFUSED;
- }
- $op->consumer_secret = $foundConsumer->secret;
- logme::say('found and ok ' . $op->consumer_key . ' scrt:' . $foundConsumer->secret);
- return OAUTH_OK;
- }
- public function timestampNonceChecker($op)
- {
- logme::say(__METHOD__);
- return OAUTH_OK;
- }
- public function tokenHandler($op)
- {
- logme::say(__METHOD__);
- return OAUTH_OK;
- }
- public function assignRequestToken($consumerKey)
- {
- logme::say('a');
- $request_token = bin2hex($this->op->generateToken(4));
- $request_token_secret = bin2hex($this->op->generateToken(12));
- logme::say('b');
- array_push($_SESSION['REQUEST_TOKENS'], array($this->op->consumer_key => array(
- 'consumer_key' => $this->op->consumer_key,
- 'request_token' => $request_token,
- 'request_token_secret' => $request_token_secret,
- 'callback' => CALL_BACK_URL,
- )));
- logme::say('c');
- return true;
- }
- }
- /*echo "\n";
- echo "\n" . 'request token end point';
- echo "\n" . '-----------------------' . "\n";*/
- if($__m == 'request_token') {
- //echo "\n" . 'inside request token end point' . "\n";
- try {
- $provider = new oAuthServer();
- logme::say('a0');
- $provider->assignRequestToken();
- logme::say('a1');
- logme::say(serialize($_SESSION));
- logme::say('a2');
- }
- catch (OAuthException $E) {
- echo OAuthProvider::reportProblem($E);
- $oauth_error = true;
- }
- }
- //echo '</pre>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement