/** * Get the URL to redirect to * * @param string Return URL * @param array Extra parameters * @return string */ public function redirect_url($return_url, array $extra = array()) { // Add the callback URL to the consumer $this->consumer->callback(URL::site($return_url, true)); // Get a request token for the consumer $request_token = $this->provider->request_token($this->consumer); Session::instance()->set('oauth_token', $request_token->token); Session::instance()->set('oauth_token_secret', $request_token->secret); // Redirect to the twitter login page return $this->provider->authorize_url($request_token); }
public function before() { parent::before(); // The user is already logged in if (Auth::instance()->logged_in()) { Request::instance()->redirect(''); } // Load the configuration for this provider $config = Kohana::config('oauth.'.$this->provider); // Create a consumer from the config $this->consumer = OAuth_Consumer::factory($config); // Load the provider $this->provider = OAuth_Provider::factory($this->provider); if ($token = Cookie::get($this->cookie)) { // Get the token from storage $this->token = unserialize($token); } }
public function before() { parent::before(); // Load the cookie session $this->session = Session::instance('cookie'); // Get the name of the demo from the class name $provider = strtolower($this->api); // Load the provider $this->provider = OAuth_Provider::factory($provider); // Load the consumer $this->consumer = OAuth_Consumer::factory(Kohana::config("oauth.{$provider}")); if ($token = $this->session->get($this->key('access'))) { // Make the access token available $this->token = $token; } }
public function oauth_init($provider = 'twitter') { $this->provider = $provider; // Load the configuration for this provider $config = Kohana::config('oauth.' . $this->provider); // Create a consumer from the config $this->consumer = OAuth_Consumer::factory($config); // Load the provider $this->provider = OAuth_Provider::factory($this->provider); if ($token = Cookie::get($this->cookie)) { // Get the token from storage $this->token = unserialize($token); } }
if (!$_POST['user_id']) { throw new OAuth1\OAuthException2("Sorry, no post data. :("); } // TODO: IMPROVE SECURITY ON THESE FIELDS!!! //extract($_POST); $user_id = urldecode($_POST['user_id']); $user_name = urldecode(html_entity_decode($_POST['user_name'], ENT_COMPAT, "UTF-8")); $user_email = urldecode($_POST['user_email']); $app_uri = urldecode($_POST['app_uri']); $app_callback = urldecode($_POST['app_callback']); $api_uri = urldecode($_POST['api_uri']); $options = array(); $server_options = array(); $options['new'] = isset($_GET['new']) && $_GET['new'] == 1; $options['update'] = isset($_GET['update']) && $_GET['update'] == 1; $server_options['new'] = isset($_GET['server_new']) && $_GET['server_new'] == 1; $server_options['update'] = isset($_GET['server_update']) && $_GET['server_update'] == 1; $consumer = new OAuth_Consumer($user_id, $user_name, $user_email, $app_uri, $app_callback, $options); $server = new OAuth_Server($consumer->get(), $api_uri, $server_options); echo "oauth_consumer_key=" . $consumer->get()['consumer_key'] . "&"; echo "oauth_consumer_secret=" . $consumer->get()['consumer_secret']; exit; } // Avoid access if not found header("Location: ../index.php"); } catch (Exception $e) { http_response_code(400); if ($e instanceof OAuth1\OAuthException2 || $e instanceof APIexception) { die("error=" . urlencode($e->getMessage()) . "&code=" . urlencode($e->getCode())); } }
function _tweet($str = 'test') { $consumer = new OAuth_Consumer('<consumer key>', '<consumer secret>'); $r = $consumer->post('<token>', '<secret>', 'http://twitter.com/statuses/update.json', array('status' => $str)); $this->log($r, LOG_DEBUG); }