Example #1
0
 /**
  * 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);
 }
Example #2
0
	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);
		}
	}
Example #3
0
 public function request_token(OAuth_Consumer $consumer, array $params = NULL)
 {
     if (!isset($params['scope'])) {
         // All request tokens must specify the data scope to access
         // http://code.google.com/apis/accounts/docs/OAuth.html#prepScope
         throw new Kohana_OAuth_Exception('Required parameter to not passed: :param', array(':param' => 'scope'));
     }
     return parent::request_token($consumer, $params);
 }
Example #4
0
 public function request_token(OAuth_Consumer $consumer, array $params = NULL)
 {
     if (empty($params)) {
         $params = array();
     }
     $config = Kohana::$config->load('oauth.' . $this->name);
     if ($scope = Arr::get($config, 'scope')) {
         $params['scope'] = $scope;
     }
     return parent::request_token($consumer, $params);
 }
Example #5
0
File: oauth.php Project: rafi/oauth
 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;
     }
 }
Example #6
0
 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);
     }
 }
Example #7
0
 public function __construct(array $options = array())
 {
     // Now make sure we have the default scope to get user data
     $options['scope'] = \Arr::merge(array('https://www.google.com/m8/feeds'), (array) \Arr::get($options, 'scope', array()));
     parent::__construct($options);
 }