Пример #1
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");
     }
 }
Пример #2
0
 /**
  * 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());
 }
Пример #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
 /**
  * @expectedException HTTP_OAuth_Exception
  */
 public function testGetAccessTokenWithNoTokens()
 {
     $con = new HTTP_OAuth_Consumer('key', 'secret');
     $con->getAccessToken('http://example.com/access_token');
 }
Пример #5
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');
Пример #6
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;
 }
Пример #7
0
    $_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.
    $oauth_pear->getAccessToken(Imgur::$oauth1a_access_token_url, array_key_exists('oauth_verifier', $_REQUEST) ? $_REQUEST['oauth_verifier'] : null);
    // This is the *ACCESS* Token and Secret.  You should store these in your
    // database with the user's record.  We're putting them in the session only
    // so the demo will work.  It's worth noting again that on subsequent pageviews,
    // the new Access Token & Secret are automatically passed into the OAuth Consumer.
    $prev_token = $_SESSION['token'];
    $_SESSION['token'] = $oauth_pear->getToken();
    $_SESSION['token_secret'] = $oauth_pear->getTokenSecret();
    if (strlen($_SESSION['token']) && strlen($_SESSION['token_secret']) && $_SESSION['token'] != $prev_token) {
        echo "Step 8: Success!  Your final access token is {$_SESSION['token']}.  ";
        echo "We can now proceed to step nine.  ";
        echo '<a href="', $_SERVER['PHP_SELF'], '">Clicky.</a>';
        $_SESSION['oauth_state'] = 2;
    } else {
        echo "Something went wrong.  Didn't get the right tokens.  You should probably see an error message above.<br>";
        echo "Be aware that these tokens are one-use only.  You <i>might</i> need to reset your session.";
Пример #8
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();
}
Пример #9
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());
?>

Пример #10
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());
     }
 }