/**
  * Create a new instance of the adapter by wrapping an existing object.
  * @param HTTP_OAuth_Consumer $object
  * @return Imgur_HTTPAdapter_OAuth_HTTPOAuthConsumer
  **/
 public static function createByWrapping($object)
 {
     $foo = new Imgur_HTTPAdapter_OAuth_HTTPOAuthConsumer();
     $consumer_request = clone $object->getOAuthConsumerRequest();
     // Oh, what a mess.
     $consumer_request->setSecrets($object->getSecrets());
     $consumer_request->setParameters(array('oauth_consumer_key' => $object->getKey(), 'oauth_signature_method' => $object->getSignatureMethod(), 'oauth_token' => $object->getToken()));
     $foo->wrap($consumer_request);
     return $foo;
 }
示例#2
0
 public function getAccessToken()
 {
     $consumer = new HTTP_OAuth_Consumer(constant('PUBLIC_KEY'), constant('PRIVATE_KEY'), $_SESSION['token'], $_SESSION['tokenSecret']);
     try {
         $consumer->getAccessToken(constant('ACCESS_TOKEN'));
         $_SESSION['accessToken'] = $consumer->getToken();
         $_SESSION['accessTokenSecret'] = $consumer->getTokenSecret();
         //header('Location: ' .'http://'.$_SERVER["PHP_SELF"]);
         header('Location: ../index.php');
     } catch (Exception $e) {
         throw new \Exception("login::getAccessToken. Error Accessing");
     }
 }
示例#3
0
<?php

ob_start();
session_start();
require_once 'lib/base.inc.php';
require_once 'HTTP/OAuth/Consumer.php';
$consumer = new HTTP_OAuth_Consumer($userTelldusConf['public_key'], $userTelldusConf['private_key'], $_SESSION['token'], $_SESSION['tokenSecret']);
try {
    $consumer->getAccessToken(constant('ACCESS_TOKEN'));
    $_SESSION['accessToken'] = $consumer->getToken();
    $_SESSION['accessTokenSecret'] = $consumer->getTokenSecret();
    header('Location:index.php');
} catch (Exception $e) {
    ?>
		<p>Authorization failed!</p>
		<p><a href="index.php">Go back</a></p>
	<?php 
}
示例#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="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;
        $filename = "app_icon.{$appIdx}.png";
示例#6
0
文件: OAuth.php 项目: shupp/openid
 /**
  * Fetch an OAuth access token
  *
  * Requires an request_token to be present in self::$values
  *
  * @param string $consumerKey    OAuth consumer application key
  * @param string $consumerSecret OAuth consumer secret key
  * @param string $url            Access token url
  * @param array  $params         Paramters to include in the request
  *                               for the access token
  * @param string $method         HTTP Method to use
  *
  * @return array Key => Value array of token and token secret
  *
  * @throws OpenID_Exception     On no request_token in response message
  * @throws HTTP_OAuth_Exception On issue with getting the request token
  *
  * @see http://step2.googlecode.com/svn/spec/openid_oauth_extension/latest/openid_oauth_extension.html
  */
 public function getAccessToken($consumerKey, $consumerSecret, $url, array $params = array(), $method = 'GET')
 {
     $requestToken = $this->get('request_token');
     if ($requestToken === null) {
         throw new OpenID_Exception('No oauth request token in OpenID message');
     }
     $consumer = new HTTP_OAuth_Consumer($consumerKey, $consumerSecret);
     $consumer->setToken($requestToken);
     // Token secret is blank per spec
     $consumer->setTokenSecret('');
     // Blank verifier
     $consumer->getAccessToken($url, '', $params, $method);
     return array('oauth_token' => $consumer->getToken(), 'oauth_token_secret' => $consumer->getTokenSecret());
 }
示例#7
0
    header("Location: {$url}");
    exit;
} else {
    if (count($_GET)) {
        $tokens = $store->getRequestToken('twitter', session_id());
        $consumer = new HTTP_OAuth_Consumer($key, $secret, $tokens['token'], $tokens['tokenSecret']);
        // Verifier
        $verifier = null;
        $qsArray = explode('?', $_SERVER['REQUEST_URI']);
        if (isset($qsArray[1])) {
            parse_str($qsArray[1], $parsed);
            if (isset($parsed['oauth_verifier'])) {
                $verifier = $parsed['oauth_verifier'];
            }
        }
        $consumer->getAccessToken('http://twitter.com/oauth/access_token', $verifier);
        $data = new HTTP_OAuth_Store_Data();
        $data->consumerUserID = 'shupp';
        $data->providerUserID = 'shupp';
        $data->providerName = 'twitter';
        $data->accessToken = $consumer->getToken();
        $data->accessTokenSecret = $consumer->getTokenSecret();
        $store->setAccessToken($data);
        $stored = $store->getAccessToken('shupp', 'twitter');
        var_dump($stored);
        exit;
    }
}
echo "<a href='./oauth.php?start=true'>start!</a>";
// $response is an instance of HTTP_OAuth_Consumer_Response
// $response = $consumer->sendRequest('http://example.com/oauth/protected_resource');
示例#8
0
 /**
  * Get access tokens for Flickr
  *
  * @return bool|string Returns the access tokens, or false if autorization process has not been started yet
  */
 public function getAccessTokens()
 {
     $tokens = $this->owner->options->flickr_api;
     // Check for valid tokens
     if (!is_array($tokens) || empty($tokens) || !isset($tokens['token_type'])) {
         return false;
     }
     // Return with tokens if we already have access tokens
     if ($tokens['token_type'] == 'access') {
         return $tokens;
     }
     try {
         $consumer = new \HTTP_OAuth_Consumer($this->key, $this->secret, $tokens['token'], $tokens['token_secret']);
         if (isset($_REQUEST['oauth_verifier'])) {
             $consumer->getAccessToken(static::FLICKR_ACCESS_URL, $_REQUEST['oauth_verifier']);
         } else {
             return false;
         }
     } catch (\Exception $e) {
         return false;
     }
     // Additional data is returned by Flickr, which contains username, etc.
     $data = $consumer->getLastResponse()->getDataFromBody();
     $tokens = array('token_type' => 'access', 'token' => $consumer->getToken(), 'token_secret' => $consumer->getTokenSecret(), 'fullname' => $data['fullname'], 'user_nsid' => $data['user_nsid'], 'username' => $data['username']);
     $this->owner->options->flickr_api = $tokens;
     unset($consumer);
     // Clear
     return $tokens;
 }
示例#9
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>";
    }
    exit;
} elseif ($_SESSION['oauth_state'] == 1) {
    echo "Step 5: You just authorized this demo for access.  Thanks!<br>";
    echo "Step 6: You've been sent back here with token ", htmlspecialchars($_REQUEST['oauth_token']), " and verifier ", htmlspecialchars($_REQUEST['oauth_verifier']), "<br>";
    echo "Step 7: Now I'll ask the Provider for access using the various tokens.<br>";
    // This can probably throw a variety of exceptions as well, but I haven't
    // encountered any of them.  Also note the express passing of oauth_verifier here.

if (empty($data['oauth_token']) || empty($data['oauth_token_secret'])) {
    throw new HTTP_OAuth_Consumer_Exception_InvalidResponse(
       'Failed getting token and token secret from response', $response
    );
}

print_r($data);

$consumer->setToken($data['oauth_token']);
$consumer->setTokenSecret($data['oauth_token_secret']);


// 5. Save credentials to config file
$handle = @fopen("visualplatform.config.php", "w");
$_conf = array(
                'domain'       => $data['domain'],
                'user_id'      => $data['user_id'],
                'key'          => $consumer->getKey(),
                'secret'       => $consumer->getSecret(),
                'token'        => $consumer->getToken(),
                'token_secret' => $consumer->getTokenSecret()
        );
fwrite($handle, '<? $visualplatform_config = unserialize(\'' . serialize($_conf) . '\'); ?>');
fclose($handle);



?>
示例#11
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';
include_once 'HTTP/OAuth/Consumer.php';
$consumer = new HTTP_OAuth_Consumer($config->consumer_key, $config->consumer_secret, $config->token, $config->token_secret);
$consumer->accept($request);
$args = array();
if ($config->method == 'POST' && !empty($_GET['args'])) {
    $args = $config->args;
}
try {
    $consumer->getAccessToken($config->access_token_url, $config->verifier, $args, $config->method);
    echo json_encode(array('token' => $consumer->getToken(), 'token_secret' => $consumer->getTokenSecret()));
} catch (HTTP_OAuth_Consumer_Exception_InvalidResponse $e) {
    echo $e->getBody();
} catch (Exception $e) {
    echo $e->getMessage();
}
示例#12
0
<?php

require 'config.php';
session_start();
$network = $_SESSION['network'];
$consumer = new HTTP_OAuth_Consumer($KEY, $SECRET, $_SESSION['token'], $_SESSION['token_secret']);
$consumer->getAccessToken("http://" . $network . "/oauth/access_token", $_GET['oauth_verifier']);
add_token($consumer->getToken(), $consumer->getTokenSecret(), $_SESSION['network']);
header("Location: http://" . $network . "/oauth_clients/show?token=" . $consumer->getToken());
?>

示例#13
0
 /**
  *  method for receiving the accessToken from Twitter,
  *  so the return-point from twitter should look like:
  *  http://domain.com/twitter/accessToken
  */
 public function accessToken($credentials = NULL)
 {
     try {
         $oauth = new HTTP_OAuth_Consumer(CONSUMER_KEY, CONSUMER_SECRET, $this->session->token, $this->session->token_secret);
         $oauth->getAccessToken('http://twitter.com/oauth/access_token', $_GET['oauth_verifier']);
         // the 'real'/ long-time AccessToken
         $token = array();
         $token['token'] = $oauth->getToken();
         $token['token_secret'] = $oauth->getTokenSecret();
         // save the retrieved token
         $this->saveTokens($token);
     } catch (Services_Twitter_Exception $e) {
         dumper($e->getMessage());
     }
 }