예제 #1
0
 public function getRequestToken()
 {
     session_start();
     $consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'));
     var_dump(constant('BASE_URL'));
     $consumer->getRequestToken(constant('REQUEST_TOKEN'), constant('BASE_URL'));
     $_SESSION['token'] = $consumer->getToken();
     $_SESSION['tokenSecret'] = $consumer->getTokenSecret();
     $url = $consumer->getAuthorizeUrl(constant('AUTHORIZE_TOKEN'));
     header('Location:' . $url);
 }
예제 #2
0
 /**
  * Start authorization process for Flickr
  *
  * Note: This will reset the access tokens!
  *
  * @param string $callback_url Callback URL
  * @return bool|string Returns the URL where to authorize the user (redirect to), or false on error
  */
 public function getAuthorizeUrl($callback_url = 'oob')
 {
     try {
         $consumer = new \HTTP_OAuth_Consumer($this->key, $this->secret);
         $consumer->getRequestToken(static::FLICKR_TOKEN_URL, $callback_url);
     } catch (\Exception $e) {
         return false;
     }
     $tokens = array('token_type' => 'request', 'token' => $consumer->getToken(), 'token_secret' => $consumer->getTokenSecret());
     $this->owner->options->flickr_api = $tokens;
     $auth_url = $consumer->getAuthorizeUrl(static::FLICKR_AUTH_URL, array('perms' => 'read'));
     // Read Only
     unset($consumer);
     // Clear
     return $auth_url;
 }
예제 #3
0
 public function twitterAction()
 {
     // Get form
     $form = $this->view->form = new User_Form_Admin_Twitter();
     $form->populate((array) Engine_Api::_()->getApi('settings', 'core')->core_twitter);
     // Get classes
     include_once 'Services/Twitter.php';
     include_once 'HTTP/OAuth/Consumer.php';
     if (!class_exists('Services_Twitter', false) || !class_exists('HTTP_OAuth_Consumer', false)) {
         return $form->addError('Unable to load twitter API classes');
     }
     // Check data
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return;
     }
     $values = $form->getValues();
     if (empty($values['key']) || empty($values['secret'])) {
         $values['key'] = '';
         $values['secret'] = '';
         $values['enable'] = 'none';
     } else {
         // Try to check credentials
         try {
             $twitter = new Services_Twitter();
             $oauth = new HTTP_OAuth_Consumer($values['key'], $values['secret']);
             //$twitter->setOAuth($oauth);
             $oauth->getRequestToken('https://twitter.com/oauth/request_token');
             $oauth->getAuthorizeUrl('http://twitter.com/oauth/authorize');
         } catch (Exception $e) {
             return $form->addError($e->getMessage());
         }
     }
     // Okay
     Engine_Api::_()->getApi('settings', 'core')->core_twitter = $form->getValues();
     $form->addNotice('Your changes have been saved.');
     $form->populate($values);
 }
예제 #4
0
<?php

require_once 'common.php';
$consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'));
$consumer->getRequestToken(constant('REQUEST_TOKEN'), constant('BASE_URL') . '/getAccessToken.php');
$_SESSION['token'] = $consumer->getToken();
$_SESSION['tokenSecret'] = $consumer->getTokenSecret();
$url = $consumer->getAuthorizeUrl(constant('AUTHORIZE_TOKEN'));
header('Location:' . $url);
예제 #5
0
	<script src="jquery-1.7.1.min.js"></script>
	<script src="main.js"></script>
	-->
</head>
<body>
	<section>
		<h1>俺のホーム画面を見よ!</h1>
		<p>iPhoneのホーム画面をアップして自慢したり、おすすめアプリを紹介したりするサイトです。</p>
		<?php 
session_start();
$consumerKey = '4TtaSWDBXEIael6yEkwt2A';
$consumerSecret = '9W4dZUftwpAYGjwpAwO39i6jpeFQOLQNdqBD1cKEN0';
include 'HTTP/OAuth/Consumer.php';
$consumer = new HTTP_OAuth_Consumer($consumerKey, $consumerSecret);
$callback = 'http://www.kenmaz.net/homescreen/twitter_auth.php';
$consumer->getRequestToken('http://twitter.com/oauth/request_token', $callback);
$_SESSION['request_token'] = $consumer->getToken();
$_SESSION['request_token_secret'] = $consumer->getTokenSecret();
$auth_url = $consumer->getAuthorizeUrl('http://twitter.com/oauth/authorize');
?>
		<!--
		<a href="<?php 
echo $auth_url;
?>
">Twitterでログイン</a>
		-->
		<img src="upload/home.png" width="20%"><br>
		<?php 
for ($y = 0; $y < 4; $y++) {
    for ($x = 0; $x < 4; $x++) {
        $appIdx = $y * 4 + $x;
예제 #6
0
<?php

require 'config.php';
session_start();
$network = $_GET['network'];
$consumer = new HTTP_OAuth_Consumer($KEY, $SECRET);
// $consumer->getRequestToken(REQUEST TOKEN URL, CALLBACK);
$consumer->getRequestToken("http://" . $network . "/oauth/request_token", $CALLBACK);
// Store tokens
$_SESSION['token'] = $consumer->getToken();
$_SESSION['token_secret'] = $consumer->getTokenSecret();
$_SESSION['network'] = $network;
$url = $consumer->getAuthorizeUrl('http://' . $network . '/oauth/authorize');
header("Location: {$url}");
?>

예제 #7
0
    $_SESSION['oauth_state'] = 0;
}
// You must have the PEAR directories in your include_path.  They're present by default.
include_once 'HTTP/OAuth.php';
include_once 'HTTP/OAuth/Consumer.php';
$oauth_pear = new HTTP_OAuth_Consumer(CONSUMER_KEY, CONSUMER_SECRET, isset($_SESSION['token']) ? $_SESSION['token'] : null, isset($_SESSION['token_secret']) ? $_SESSION['token_secret'] : null);
// State = 0: The user has not attempted to request OAuth.
if ($_SESSION['oauth_state'] == 0) {
    echo "Step 1: We've already registered with Imgur.  Our consumer key is: ", CONSUMER_KEY, "<br>";
    echo "Step 2: You have just made a request, and are thus reading this.  Awesome.<br>";
    echo "Step 3: Let's ask the Provider for a token:<br>";
    try {
        // The inclusion of the callback URL in the token request causes the remote
        // service to know where to send the user back.  It should be the same
        // callback URL that you registered with the servicve to get your key.
        $oauth_pear->getRequestToken(Imgur::$oauth1a_request_token_url, CALLBACK_URL);
    } catch (HTTP_OAuth_Consumer_Exception_InvalidResponse $e) {
        echo $e->getMessage();
        exit;
    }
    // We'll stash away the *REQUEST* Token & Secret in the user's session.
    // On the next pageview, they'll be loaded into the OAuth Consumer
    // when it's created, so we don't need to set them manually.
    $_SESSION['token'] = $oauth_pear->getToken();
    $_SESSION['token_secret'] = $oauth_pear->getTokenSecret();
    if (strlen($_SESSION['token']) && strlen($_SESSION['token_secret'])) {
        echo "Step 4: Your token is {$_SESSION['token']}.  Click the following link to pop over to Imgur and authorize the demo: ";
        echo '<a href="', Imgur::$oauth1a_authorize_url, '?oauth_token=', urlencode($_SESSION['token']), '">Clicky.</a>';
        $_SESSION['oauth_state'] = 1;
    } else {
        echo "Something went wrong.  You should probably see an error message above.<br>";
require_once 'HTTP/OAuth.php';
require_once 'HTTP/OAuth/Consumer/Request.php';
require_once 'HTTP/Request2.php';

// Set up HTTP request
$httpRequest = new HTTP_Request2;
$httpRequest->setHeader('Accept-Encoding', '.*');
$request = new HTTP_OAuth_Consumer_Request;
$request->accept($httpRequest);

// Set up OAuth consumer
$consumer = new HTTP_OAuth_Consumer($consumer_key, $consumer_secret);
$consumer->accept($request);

// 1. Get request token
$consumer->getRequestToken("http://".$domain."/oauth/request_token", "oob", array(), "GET");

// 2. Build authorize url and redirect the user
$authorize_url = $consumer->getAuthorizeUrl("http://".$domain."/oauth/authorize");
echo("Please visit the following URL in your browser to authorize your application, then enter the 4 character security code when done:\n\n  " . $authorize_url . "\n\nVerification code: ");

// 3. Get an OAuth verifier (this step is only necessary when a callback url hasn't been specified)
$handle = @fopen("php://stdin", "r");
$oauth_verifier = trim(fgets($handle));
fclose($handle);

// 4. Exchange the request token for an access token
//    (He're we're reading extra data from the access token request to 
//    determine the domain and user_id of the authenticated user. 
//    Unfortunately this PHP OAuth library doesn't return the excess
//    data from the access token request, so we'll need to handle the
예제 #9
0
 /**
  *  the method for adding twitter users
  */
 public function add($credentials = NULL)
 {
     try {
         $oauth = new HTTP_OAuth_Consumer(CONSUMER_KEY, CONSUMER_SECRET);
         $oauth->getRequestToken('http://twitter.com/oauth/request_token', 'http://' . $_SERVER['HTTP_HOST'] . '/twitter/accessToken');
         $this->session->token = $oauth->getToken();
         $this->session->token_secret = $oauth->getTokenSecret();
         $url = $oauth->getAuthorizeUrl('http://twitter.com/oauth/authorize');
         header('Location: ' . $url);
     } catch (Services_Twitter_Exception $e) {
         dumper($e->getMessage());
     }
 }
예제 #10
0
 *
 * LICENSE: This source file is subject to the New BSD license that is
 * available through the world-wide-web at the following URI:
 * http://www.opensource.org/licenses/bsd-license.php. If you did not receive  
 * a copy of the New BSD License and are unable to obtain it through the web, 
 * please send a note to license@php.net so we can mail you a copy immediately.
 *
 * @category  HTTP
 * @package   HTTP_OAuth
 * @author    Jeff Hodsdon <*****@*****.**> 
 * @copyright 2009 Jeff Hodsdon <*****@*****.**> 
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @link      http://pear.php.net/package/HTTP_OAuth_Provider
 * @link      http://github.com/jeffhodsdon/HTTP_OAuth_Provider
 */
require_once 'examples-config.php';
require_once 'HTTP/OAuth/Consumer.php';
$consumer = new HTTP_OAuth_Consumer($config->consumer_key, $config->consumer_secret);
$consumer->accept($request);
$args = array();
if ($config->method == 'POST' && !empty($_GET['args'])) {
    $args = $config->args;
}
try {
    $consumer->getRequestToken($config->request_token_url, $config->callback_url, $args, $config->method);
    echo json_encode(array('token' => $consumer->getToken(), 'token_secret' => $consumer->getTokenSecret()));
} catch (HTTP_OAuth_Consumer_Exception_InvalidResponse $e) {
    echo get_class($e) . "<br>\n" . "<br>\n" . $e->getBody() . "<br>\n";
} catch (Exception $e) {
    echo get_class($e) . ': ' . $e->getMessage() . "\n";
}