Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Preliminary commit to share the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Krämer committed Jan 11, 2012
1 parent 607598d commit 3c06619
Show file tree
Hide file tree
Showing 11 changed files with 749 additions and 0 deletions.
68 changes: 68 additions & 0 deletions Config/Migration/001_initialize_oauth_schema.php
@@ -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;
}


}
3 changes: 3 additions & 0 deletions Config/Migration/map.php
@@ -0,0 +1,3 @@
<?php
$map = array (1 => array('001_initialize_oauth_schema' => 'OauthMigration001'));
?>
25 changes: 25 additions & 0 deletions Config/Schema/oauth.sql
@@ -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;
44 changes: 44 additions & 0 deletions Controller/ServerController.php
@@ -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());
}

}

0 comments on commit 3c06619

Please sign in to comment.