Skip to content

3.3/develop #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 48 commits into
base: 3.1/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c78351f
Added base controller for demos and description file
shadowhand Apr 4, 2011
fa65fe1
Merge branch '3.0/develop' into 3.1/develop
shadowhand Apr 4, 2011
d7336a6
Renamed OAuth_Demo to Demo_OAuth
shadowhand Apr 13, 2011
41c0d0d
Fixed permissions on OAuth files
shadowhand Apr 13, 2011
56d62a8
Implemented OAuth v2
biakaveron Apr 5, 2011
68d5904
Rename all v2 class files from oauth/v2 to oauth2
shadowhand Apr 13, 2011
65550f6
Redeclare all OAuth_v2 classes as OAuth2
shadowhand Apr 13, 2011
15d4f97
Remove verify_credentials from OAuth2 provider abstract and providers…
shadowhand Apr 13, 2011
bb7b905
Cleaning up OAuth2 classes, fixing formatting and line endings
shadowhand Apr 13, 2011
48d3060
Added OAuth2 example to config/oauth
shadowhand Apr 13, 2011
06cfa23
Modify OAuth_Token to have a configured set of required options
shadowhand Apr 13, 2011
ddbc97a
OAuth2 refers to "clients" instead of "consumers", uses "id" instead …
shadowhand Apr 13, 2011
22ee92d
Added OAuth2 demo controller
shadowhand Apr 13, 2011
ba36ccf
Merge branch 'feature/oauth2' into 3.1/develop
shadowhand Apr 13, 2011
93b5bd3
3.1 compatibility fix
shadowhand Apr 13, 2011
766637c
Added required params to OAuth v1 Request_Credentials class
biakaveron Apr 20, 2011
f7e384e
Merge pull request #5 from biakaveron/3.1/develop
May 20, 2011
7bb49d7
OAuth2 Access_Request must sent redirect_uri if set
biakaveron May 30, 2011
f635fbb
Added OAuth v2 Facebook driver
biakaveron May 30, 2011
253111a
Fixing: Request::uri() is a function, closing <h2> tag
rafi Jun 14, 2011
1bf8c31
Merge pull request #6 from rafi/3.1/develop
Jun 14, 2011
fc6ceb6
Adding a Linkedin provider
rafi Jun 15, 2011
7bf140e
Merge pull request #7 from rafi/3.1/linkedin_provider
Jun 15, 2011
59331b6
Fixing typo
rafi Jun 16, 2011
9eea5af
Merge pull request #8 from rafi/3.1/linkedin_provider
Jun 16, 2011
1679917
Merge pull request #9 from biakaveron/7bb49d724f4c065acb520c65e1ed737…
Jun 21, 2011
4eb2734
Adding Flickr as a Service Provider.
daveWid Jul 14, 2011
25ff09c
Merge pull request #11 from daveWid/3.1/develop
Jul 17, 2011
0df6247
Merge pull request #10 from biakaveron/f635fbb2ea1c7605cb38bc846d2a45…
Jul 17, 2011
90560c8
Add Tumblr to providers.
Jul 22, 2011
ced46b9
Merge pull request #12 from creatoro/3.1/develop
Jul 23, 2011
9e482a0
Added optional header realm="". See http://dev.kohanaframework.org/i…
Austinb Aug 2, 2011
22d633b
Added missing realm to Provider::access_token(). Changed to insert r…
Austinb Aug 3, 2011
0f145b0
Replaced Kohana::config() calls for 3.2 compatibility
Nov 6, 2011
2feb3ae
Upgraded OAuth for Kohana 3.2 compatibility
Nov 6, 2011
966ae0b
OAuth(2) Response can be in a JSON format.
biakaveron Jul 29, 2011
ba64c70
Merge branch '3.1/develop' into 3.2/develop
Nov 16, 2011
19ef2a9
Merge pull request #14 from Austinb/3.1/develop
Nov 16, 2011
158dd85
Merge branch '3.1/develop' into 3.2/develop
Nov 16, 2011
7073ded
Added OAuth2_Provider::__get(), same as OAuth_Provider::__get()
Nov 17, 2011
0e9e162
Added OAuth2_Request_Resouce
Nov 17, 2011
85267a6
renaming classes with v3.3 conventions
biakaveron Jan 6, 2013
6818ab1
Add vk (vkontakte) to providers
biakaveron Jan 6, 2013
69cad64
Add Google OAuth2 to providers
biakaveron Jan 6, 2013
22259d5
Add Yandex (ya.ru) to providers
biakaveron Jan 6, 2013
a0fff63
Именование под ko3.3
aktuba Jan 7, 2013
f86d54a
Переименование класса для ВКонтакте
aktuba Jan 7, 2013
cd22d88
Переименование классов
aktuba Jan 8, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions classes/Controller/Demo/Oauth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Base demo class for OAuth provider modules.
*
* Depends on the [demo module](https://github.com/shadowhand/demo).
*
* @package Kohana/OAuth
* @category Demo
* @author Kohana Team
* @copyright (c) 2011 Kohana Team
* @license http://kohanaframework.org/license
* @since 3.1.3
*/
abstract class Controller_Demo_OAuth extends Controller_Demo {

/**
* @var object OAuth_Provider
*/
protected $provider;

/**
* @var object OAuth_Consumer
*/
protected $consumer;

/**
* @var object OAuth_Token
*/
protected $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 provider configuration
$config = Kohana::$config->load('oauth')->$provider;

// Load the consumer for this provider
$this->consumer = OAuth_Consumer::factory($config);

if ($token = $this->session->get($this->key('access')))
{
// Make the access token available
$this->token = $token;
}
}

public function key($name)
{
return "demo_{$this->provider->name}_{$name}";
}

public function demo_login()
{
// Attempt to complete signin
if ($verifier = Arr::get($_REQUEST, 'oauth_verifier'))
{
if ( ! $token = $this->session->get($this->key('request')) OR $token->token !== Arr::get($_REQUEST, 'oauth_token'))
{
// Token is invalid
$this->session->delete($this->key('request'));

// Restart the login process
$this->request->redirect($this->request->uri());
}

// Store the verifier in the token
$token->verifier($verifier);

// Exchange the request token for an access token
$token = $this->provider->access_token($this->consumer, $token);

// Store the access token
$this->session->set($this->key('access'), $token);

// Request token is no longer needed
$this->session->delete($this->key('request'));

// Refresh the page to prevent errors
$this->request->redirect($this->request->uri());
}

if ($this->token)
{
// Login succesful
$this->content = Debug::vars('Access token granted:', $this->token);
}
else
{
// We will need a callback URL for the user to return to
$callback = $this->request->url(NULL, TRUE);

// Add the callback URL to the consumer
$this->consumer->callback($callback);

// Get a request token for the consumer
$token = $this->provider->request_token($this->consumer);

// Get the login URL from the provider
$url = $this->provider->authorize_url($token);

// Store the token
$this->session->set($this->key('request'), $token);

// Redirect to the twitter login page
$this->content = HTML::anchor($url, "Login to {$this->api}");
}
}

public function demo_logout()
{
if (Arr::get($_GET, 'confirm'))
{
// Delete the access token
$this->session->delete($this->key('request'), $this->key('access'));

// Redirect to the demo list
$this->request->redirect($this->request->uri(array('action' => FALSE, 'id' => FALSE)));
}

$this->content = HTML::anchor("{$this->request->uri()}?confirm=yes", "Logout of {$this->api}");
}

} // End Demo
112 changes: 112 additions & 0 deletions classes/Controller/Demo/Oauth2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Base demo class for OAuth provider modules.
*
* Depends on the [demo module](https://github.com/shadowhand/demo).
*
* @package Kohana/OAuth2
* @category Demo
* @author Kohana Team
* @copyright (c) 2011 Kohana Team
* @license http://kohanaframework.org/license
* @since 3.1.3
*/
abstract class Controller_Demo_OAuth2 extends Controller_Demo {

/**
* @var object OAuth2_Provider
*/
protected $provider;

/**
* @var object OAuth2_Client
*/
protected $client;

/**
* @var object OAuth2_Token
*/
protected $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 = OAuth2_Provider::factory($provider);

// Load provider configuration
$config = Kohana::$config->load('oauth')->$provider;

// Load the client for this provider
$this->client = OAuth2_Client::factory($config);

if ($token = $this->session->get($this->key('access')))
{
// Make the access token available
$this->token = $token;
}
}

public function key($name)
{
return "demo_{$this->provider->name}_{$name}";
}

public function demo_login()
{
// Attempt to complete signin
if ($code = Arr::get($_REQUEST, 'code'))
{
// Exchange the authorization code for an access token
$token = $this->provider->access_token($this->client, $code);

// Store the access token
$this->session->set($this->key('access'), $token);

// Refresh the page to prevent errors
$this->request->redirect($this->request->uri());
}

if ($this->token)
{
// Login succesful
$this->content = Debug::vars('Access token granted:', $this->token);
}
else
{
// We will need a callback URL for the user to return to
$callback = $this->request->url(NULL, TRUE);

// Add the callback URL to the consumer
$this->client->callback($callback);

// Get the login URL from the provider
$url = $this->provider->authorize_url($this->client);

// Redirect to the twitter login page
$this->content = HTML::anchor($url, "Login to {$this->api}");
}
}

public function demo_logout()
{
if (Arr::get($_GET, 'confirm'))
{
// Delete the access token
$this->session->delete($this->key('access'));

// Redirect to the demo list
$this->request->redirect($this->request->uri(array('action' => FALSE, 'id' => FALSE)));
}

$this->content = HTML::anchor($this->request->uri().'?confirm=yes', "Logout of {$this->api}");
}

} // End Demo
File renamed without changes.
10 changes: 10 additions & 0 deletions classes/kohana/oauth/consumer.php → classes/Kohana/Oauth/Consumer.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public static function factory(array $options = NULL)
*/
protected $callback;

/**
* @var string optional realm for the OAuth request
*/
protected $realm;

/**
* Sets the consumer key and secret.
*
Expand Down Expand Up @@ -67,6 +72,11 @@ public function __construct(array $options = NULL)
{
$this->callback = $options['callback'];
}

if (isset($options['realm']))
{
$this->realm = $options['realm'];
}
}

/**
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
abstract class Kohana_OAuth_Provider {

protected $signature = 'PLAINTEXT';

/**
* Create a new provider.
*
Expand All @@ -23,7 +25,7 @@ abstract class Kohana_OAuth_Provider {
*/
public static function factory($name, array $options = NULL)
{
$class = 'OAuth_Provider_'.$name;
$class = 'OAuth_Provider_'.UTF8::ucfirst($name);

return new $class($options);
}
Expand Down Expand Up @@ -126,6 +128,7 @@ public function request_token(OAuth_Consumer $consumer, array $params = NULL)
{
// Create a new GET request for a request token with the required parameters
$request = OAuth_Request::factory('token', 'GET', $this->url_request_token(), array(
'realm' => $consumer->realm,
'oauth_consumer_key' => $consumer->key,
'oauth_callback' => $consumer->callback,
));
Expand Down Expand Up @@ -188,6 +191,7 @@ public function access_token(OAuth_Consumer $consumer, OAuth_Token_Request $toke
{
// Create a new GET request for a request token with the required parameters
$request = OAuth_Request::factory('access', 'GET', $this->url_access_token(), array(
'realm' => $consumer->realm,
'oauth_consumer_key' => $consumer->key,
'oauth_token' => $token->token,
'oauth_verifier' => $token->verifier,
Expand Down
39 changes: 39 additions & 0 deletions classes/Kohana/Oauth/Provider/Flickr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php defined('SYSPATH') or die('No direct script access.');
/**
* OAuth Flickr Provider
*
* Documents for implementing Flickr OAuth can be found at
* <http://www.flickr.com/services/api/auth.oauth.html>.
*
* [!!] This class does not implement the Flickr API. It is only an
* implementation of standard OAuth with Flickr as the service provider.
*
* @package Kohana/OAuth
* @category Provider
* @author Kohana Team
* @copyright (c) 2011 Kohana Team
* @license http://kohanaframework.org/license
* @since 3.1.0
*/
class Kohana_OAuth_Provider_Flickr extends OAuth_Provider {

public $name = 'flickr';

protected $signature = 'HMAC-SHA1';

public function url_request_token()
{
return 'http://www.flickr.com/services/oauth/request_token';
}

public function url_authorize()
{
return 'http://www.flickr.com/services/oauth/authorize';
}

public function url_access_token()
{
return 'http://www.flickr.com/services/oauth/access_token';
}

} // End OAuth_Provider_Flickr
Loading