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); }
/** * 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; }
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); }
public function testGetAuthorizeUrl() { $con = new HTTP_OAuth_Consumer('key', 'secret', 'token'); $this->assertEquals('http://example.com/?oauth_token=token', $con->getAuthorizeUrl('http://example.com/')); }
<?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);
</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"; ?> <img src="<?php
<?php /** * HTTP_OAuth * * Implementation of the OAuth specification * * PHP version 5.2.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 */ include_once 'HTTP/OAuth/Consumer.php'; $consumer = new HTTP_OAuth_Consumer($config->consumer_key, $config->consumer_secret, $config->token, $config->token_secret); try { echo $consumer->getAuthorizeUrl($config->authorize_url); } catch (Exception $e) { echo $e->getBody(); }
<?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}"); ?>
// 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 // request manually.) $response = $consumer->sendRequest("http://".$domain."/oauth/access_token", array("oauth_verifier" => $oauth_verifier), "GET");
/** * 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()); } }