Advertisement
cgchamila

Untitled

Oct 4th, 2011
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.18 KB | None | 0 0
  1.  
  2. <?php
  3. session_start();
  4. if(!isset($_SESSION['REQUEST_TOKENS'])) {
  5. $_SESSION['REQUEST_TOKENS'] = array();
  6. }
  7.  
  8. define('CALL_BACK_URL', 'http://localhost:3000/');
  9.  
  10. class logme
  11. {
  12. public static function say($msg)
  13. {
  14. openlog("OAUTH-P", 0, LOG_LOCAL0);
  15. syslog(LOG_DEBUG, $msg);
  16. }
  17. }
  18.  
  19. class consumerDS
  20. {
  21. private static $consumers = array(
  22. 'viraj' => array('secret'=>'asjh^&556GHJG', 'status'=>0)
  23. );
  24.  
  25. public static function getConsumer($consumerKey) {
  26. logme::say('looking up.. ' . $consumerKey);
  27. if(array_key_exists($consumerKey, self::$consumers)) {
  28. return (object)self::$consumers[$consumerKey];
  29. }
  30. return null;
  31. }
  32. }
  33. //echo '<pre>';
  34. //echo $_SERVER['HTTP_HOST'] . ' ' . $_SERVER['REQUEST_URI'] . "\n";
  35. //print_r($_SERVER);
  36. //echo '</pre>';
  37.  
  38. $__m = $__o = $__a = null;
  39. extract(array_combine(array('__m','__o','__a'), array_pad(explode(DIRECTORY_SEPARATOR, trim($_SERVER['REQUEST_URI'],DIRECTORY_SEPARATOR), 3),3,null)),EXTR_IF_EXISTS);
  40. //echo 'm->' . $__m . '  o->' . $__o . '  a->' . $__a . "\n";
  41.  
  42. //echo serialize($_GET);
  43. //echo serialize($_POST);
  44.  
  45. class oAuthServer {
  46. public function __construct()
  47. {
  48. $this->op = new OAuthProvider();
  49. $this->op->consumerHandler(array($this, 'lookupConsumer'));
  50.   $this->op->timestampNonceHandler(array($this, 'timestampNonceChecker'));
  51.     $this->op->tokenHandler(array($this, 'tokenHandler'));
  52.  
  53.     logme::say(__METHOD__);
  54.  
  55. $this->op->setRequestTokenPath('/request_token');
  56. $this->op->checkOAuthRequest();
  57. logme::say('---> ' . $this->op->consumer_secret);
  58. }
  59.  
  60. public function lookupConsumer($op)
  61. {
  62. logme::say(__METHOD__);
  63.  
  64. $foundConsumer = consumerDS::getConsumer($op->consumer_key);
  65. if(is_null($foundConsumer)) {
  66. logme::say('unknown ' . $op->consumer_key);
  67. return OAUTH_CONSUMER_KEY_UNKNOWN;
  68. }
  69. else if ($foundConsumer->status != 0){
  70. logme::say('refused ' . $op->consumer_key);
  71. return OAUTH_CONSUMER_KEY_REFUSED;
  72. }
  73.  
  74. $op->consumer_secret = $foundConsumer->secret;
  75. logme::say('found and ok ' . $op->consumer_key . ' scrt:' . $foundConsumer->secret);
  76. return OAUTH_OK;
  77. }
  78.  
  79. public function timestampNonceChecker($op)
  80. {
  81. logme::say(__METHOD__);
  82. return OAUTH_OK;
  83. }
  84.  
  85. public function tokenHandler($op)
  86. {
  87. logme::say(__METHOD__);
  88. return OAUTH_OK;
  89. }
  90.  
  91. public function assignRequestToken($consumerKey)
  92. {
  93. logme::say('a');
  94. $request_token = bin2hex($this->op->generateToken(4));
  95.     $request_token_secret = bin2hex($this->op->generateToken(12));
  96.  
  97.     logme::say('b');
  98. array_push($_SESSION['REQUEST_TOKENS'], array($this->op->consumer_key => array(
  99. 'consumer_key' => $this->op->consumer_key,
  100. 'request_token' => $request_token,
  101. 'request_token_secret' => $request_token_secret,
  102. 'callback' => CALL_BACK_URL,
  103. )));
  104.  
  105. logme::say('c');
  106.  
  107. return true;
  108. }
  109. }
  110.  
  111.  
  112.  
  113. /*echo "\n";
  114. echo "\n" . 'request token end point';
  115. echo "\n" . '-----------------------' . "\n";*/
  116.  
  117. if($__m == 'request_token') {
  118. //echo "\n" . 'inside request token end point' . "\n";
  119. try {
  120. $provider = new oAuthServer();
  121. logme::say('a0');
  122. $provider->assignRequestToken();
  123. logme::say('a1');
  124. logme::say(serialize($_SESSION));
  125. logme::say('a2');
  126.    }
  127.    catch (OAuthException $E) {
  128. echo OAuthProvider::reportProblem($E);
  129. $oauth_error = true;
  130.    }
  131. }
  132.  
  133. //echo '</pre>';
  134. ?>
  135.  
  136.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement