This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preliminary commit to share the code
- Loading branch information
Florian Krämer
committed
Jan 11, 2012
1 parent
607598d
commit 3c06619
Showing
11 changed files
with
749 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
class OauthMigration001 extends CakeMigration { | ||
/** | ||
* Dependency array. Define what minimum version required for other part of db schema | ||
* | ||
* Migration defined like 'app.31' or 'plugin.PluginName.12' | ||
* | ||
* @var array $dependendOf | ||
* @access public | ||
*/ | ||
public $dependendOf = array(); | ||
/** | ||
* Migration array | ||
* | ||
* @var array $migration | ||
* @access public | ||
*/ | ||
var $migration = array( | ||
'up' => array( | ||
'create_table' => array( | ||
'auth_codes' => array( | ||
'code' => array('type'=>'string', 'null' => false, 'default' => NULL, 'lenght' => 40), | ||
'client_id' => array('type'=>'string', 'null' => false, 'default' => NULL, 'lenght' => 20), | ||
'redirect_uri' => array('type'=>'string', 'null' => false, 'default' => NULL, 'lenght' => 200), | ||
'expires' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 11), | ||
'scope' => array('type'=>'string', 'null' => true, 'default' => NULL, 'lenght' => 200), | ||
'indexes' => array('PRIMARY' => array('column' => 'code', 'unique' => 1)), | ||
), | ||
'oauth_clients' => array( | ||
'id' => array('type'=>'string', 'null' => false, 'default' => NULL, 'lenght' => 20), | ||
'secret' => array('type'=>'string', 'null' => false, 'default' => NULL, 'lenght' => 20), | ||
'redirect_uri' => array('type'=>'string', 'null' => false, 'default' => NULL, 'lenght' => 200), | ||
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)), | ||
), | ||
'oauth_tokens' => array( | ||
'oauth_token' => array('type'=>'string', 'null' => false, 'default' => NULL, 'lenght' => 40), | ||
'client_id' => array('type'=>'string', 'null' => false, 'default' => NULL, 'lenght' => 20), | ||
'expires' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 11), | ||
'scope' => array('type'=>'string', 'null' => true, 'default' => NULL, 'lenght' => 200), | ||
'indexes' => array('PRIMARY' => array('column' => 'oauth_token', 'unique' => 1)), | ||
), | ||
) | ||
), | ||
'down' => array( | ||
'drop_table' => array('auth_codes', 'oauth_clients', 'oauth_tokens') | ||
) | ||
); | ||
/** | ||
* before migration callback | ||
* | ||
* @param string $direction, up or down direction of migration process | ||
* @access public | ||
*/ | ||
function before($direction) { | ||
return true; | ||
} | ||
/** | ||
* after migration callback | ||
* | ||
* @param string $direction, up or down direction of migration process | ||
* @access public | ||
*/ | ||
function after($direction) { | ||
return true; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
$map = array (1 => array('001_initialize_oauth_schema' => 'OauthMigration001')); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; | ||
|
||
CREATE TABLE `auth_codes` ( | ||
`code` varchar(40) NOT NULL, | ||
`client_id` varchar(20) NOT NULL, | ||
`redirect_uri` varchar(200) NOT NULL, | ||
`expires` int(11) NOT NULL, | ||
`scope` varchar(250) DEFAULT NULL, | ||
PRIMARY KEY (`code`) | ||
) ENGINE=MyISAM DEFAULT CHARSET=utf8; | ||
|
||
CREATE TABLE `clients` ( | ||
`client_id` varchar(20) NOT NULL, | ||
`client_secret` varchar(20) NOT NULL, | ||
`redirect_uri` varchar(200) NOT NULL, | ||
PRIMARY KEY (`client_id`) | ||
) ENGINE=MyISAM DEFAULT CHARSET=utf8; | ||
|
||
CREATE TABLE `tokens` ( | ||
`oauth_token` varchar(40) NOT NULL, | ||
`client_id` varchar(20) NOT NULL, | ||
`expires` int(11) NOT NULL, | ||
`scope` varchar(200) DEFAULT NULL, | ||
PRIMARY KEY (`oauth_token`) | ||
) ENGINE=MyISAM DEFAULT CHARSET=utf8; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
require_once(CakePlugin::path('Oauth2') . 'Vendor' . DS . 'oauth2-php' . DS . 'lib' . DS . 'OAuth2.php'); | ||
|
||
class ServerController extends AppController { | ||
/** | ||
* Name | ||
* | ||
* @var string | ||
*/ | ||
public $name = 'Server'; | ||
|
||
/** | ||
* beforeFilter callback | ||
* | ||
* @return void | ||
*/ | ||
public function beforeFilter() { | ||
parent::beforeFilter(); | ||
if (isset($this->Auth)) { | ||
$this->Auth->allow('*'); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function authorize() { | ||
$oauth = new OAuth2(); | ||
if ($this->request->is('post') && $this->request->data['Server']['grant'] == 1) { | ||
unset($this->request->data['Server']['grant']); | ||
$oauth->finishClientAuthorization(true, $this->request->data); | ||
} | ||
$this->set($authParams = $oauth->getAuthorizeParams()); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function token() { | ||
$oauth = new OAuth2(); | ||
$this->set('response', $oauth->grantAccessToken()); | ||
} | ||
|
||
} |
Oops, something went wrong.