First functional OAuth2 implementation, but we're still working on it (adding missing files)

This commit is contained in:
Erik Amaru Ortiz
2013-10-01 09:15:28 -04:00
parent bc618fe1db
commit 333b27176f
11 changed files with 208 additions and 60 deletions

1
.gitignore vendored
View File

@@ -22,3 +22,4 @@ workflow/public_html/index.html
composer.phar composer.phar
composer.lock composer.lock
vendor/ vendor/
workflow/engine/config/schema-transformed.xml

View File

@@ -69,7 +69,7 @@ class OauthAccessTokensMapBuilder
$tMap->addColumn('CLIENT_ID', 'ClientId', 'string', CreoleTypes::VARCHAR, true, 80); $tMap->addColumn('CLIENT_ID', 'ClientId', 'string', CreoleTypes::VARCHAR, true, 80);
$tMap->addColumn('USER_ID', 'UserId', 'string', CreoleTypes::VARCHAR, true, 32); $tMap->addColumn('USER_ID', 'UserId', 'string', CreoleTypes::VARCHAR, false, 32);
$tMap->addColumn('EXPIRES', 'Expires', 'int', CreoleTypes::TIMESTAMP, true, null); $tMap->addColumn('EXPIRES', 'Expires', 'int', CreoleTypes::TIMESTAMP, true, null);

View File

@@ -65,7 +65,7 @@ class OauthRefreshTokensMapBuilder
$tMap->setUseIdGenerator(false); $tMap->setUseIdGenerator(false);
$tMap->addPrimaryKey('REFRESH_TOKES', 'RefreshTokes', 'string', CreoleTypes::VARCHAR, true, 40); $tMap->addPrimaryKey('REFRESH_TOKEN', 'RefreshToken', 'string', CreoleTypes::VARCHAR, true, 40);
$tMap->addColumn('CLIENT_ID', 'ClientId', 'string', CreoleTypes::VARCHAR, true, 80); $tMap->addColumn('CLIENT_ID', 'ClientId', 'string', CreoleTypes::VARCHAR, true, 80);

View File

@@ -69,7 +69,7 @@ class OauthScopesMapBuilder
$tMap->addColumn('SCOPE', 'Scope', 'string', CreoleTypes::VARCHAR, false, 2000); $tMap->addColumn('SCOPE', 'Scope', 'string', CreoleTypes::VARCHAR, false, 2000);
$tMap->addColumn('CLIENT_ID', 'ClientId', 'string', CreoleTypes::VARCHAR, true, 80); $tMap->addColumn('CLIENT_ID', 'ClientId', 'string', CreoleTypes::VARCHAR, false, 80);
} // doBuild() } // doBuild()

View File

@@ -28,10 +28,10 @@ abstract class BaseOauthRefreshTokens extends BaseObject implements Persistent
protected static $peer; protected static $peer;
/** /**
* The value for the refresh_tokes field. * The value for the refresh_token field.
* @var string * @var string
*/ */
protected $refresh_tokes; protected $refresh_token;
/** /**
* The value for the client_id field. * The value for the client_id field.
@@ -72,14 +72,14 @@ abstract class BaseOauthRefreshTokens extends BaseObject implements Persistent
protected $alreadyInValidation = false; protected $alreadyInValidation = false;
/** /**
* Get the [refresh_tokes] column value. * Get the [refresh_token] column value.
* *
* @return string * @return string
*/ */
public function getRefreshTokes() public function getRefreshToken()
{ {
return $this->refresh_tokes; return $this->refresh_token;
} }
/** /**
@@ -148,12 +148,12 @@ abstract class BaseOauthRefreshTokens extends BaseObject implements Persistent
} }
/** /**
* Set the value of [refresh_tokes] column. * Set the value of [refresh_token] column.
* *
* @param string $v new value * @param string $v new value
* @return void * @return void
*/ */
public function setRefreshTokes($v) public function setRefreshToken($v)
{ {
// Since the native PHP type for this column is string, // Since the native PHP type for this column is string,
@@ -162,12 +162,12 @@ abstract class BaseOauthRefreshTokens extends BaseObject implements Persistent
$v = (string) $v; $v = (string) $v;
} }
if ($this->refresh_tokes !== $v) { if ($this->refresh_token !== $v) {
$this->refresh_tokes = $v; $this->refresh_token = $v;
$this->modifiedColumns[] = OauthRefreshTokensPeer::REFRESH_TOKES; $this->modifiedColumns[] = OauthRefreshTokensPeer::REFRESH_TOKEN;
} }
} // setRefreshTokes() } // setRefreshToken()
/** /**
* Set the value of [client_id] column. * Set the value of [client_id] column.
@@ -277,7 +277,7 @@ abstract class BaseOauthRefreshTokens extends BaseObject implements Persistent
{ {
try { try {
$this->refresh_tokes = $rs->getString($startcol + 0); $this->refresh_token = $rs->getString($startcol + 0);
$this->client_id = $rs->getString($startcol + 1); $this->client_id = $rs->getString($startcol + 1);
@@ -497,7 +497,7 @@ abstract class BaseOauthRefreshTokens extends BaseObject implements Persistent
{ {
switch($pos) { switch($pos) {
case 0: case 0:
return $this->getRefreshTokes(); return $this->getRefreshToken();
break; break;
case 1: case 1:
return $this->getClientId(); return $this->getClientId();
@@ -531,7 +531,7 @@ abstract class BaseOauthRefreshTokens extends BaseObject implements Persistent
{ {
$keys = OauthRefreshTokensPeer::getFieldNames($keyType); $keys = OauthRefreshTokensPeer::getFieldNames($keyType);
$result = array( $result = array(
$keys[0] => $this->getRefreshTokes(), $keys[0] => $this->getRefreshToken(),
$keys[1] => $this->getClientId(), $keys[1] => $this->getClientId(),
$keys[2] => $this->getUserId(), $keys[2] => $this->getUserId(),
$keys[3] => $this->getExpires(), $keys[3] => $this->getExpires(),
@@ -568,7 +568,7 @@ abstract class BaseOauthRefreshTokens extends BaseObject implements Persistent
{ {
switch($pos) { switch($pos) {
case 0: case 0:
$this->setRefreshTokes($value); $this->setRefreshToken($value);
break; break;
case 1: case 1:
$this->setClientId($value); $this->setClientId($value);
@@ -606,7 +606,7 @@ abstract class BaseOauthRefreshTokens extends BaseObject implements Persistent
$keys = OauthRefreshTokensPeer::getFieldNames($keyType); $keys = OauthRefreshTokensPeer::getFieldNames($keyType);
if (array_key_exists($keys[0], $arr)) { if (array_key_exists($keys[0], $arr)) {
$this->setRefreshTokes($arr[$keys[0]]); $this->setRefreshToken($arr[$keys[0]]);
} }
if (array_key_exists($keys[1], $arr)) { if (array_key_exists($keys[1], $arr)) {
@@ -636,8 +636,8 @@ abstract class BaseOauthRefreshTokens extends BaseObject implements Persistent
{ {
$criteria = new Criteria(OauthRefreshTokensPeer::DATABASE_NAME); $criteria = new Criteria(OauthRefreshTokensPeer::DATABASE_NAME);
if ($this->isColumnModified(OauthRefreshTokensPeer::REFRESH_TOKES)) { if ($this->isColumnModified(OauthRefreshTokensPeer::REFRESH_TOKEN)) {
$criteria->add(OauthRefreshTokensPeer::REFRESH_TOKES, $this->refresh_tokes); $criteria->add(OauthRefreshTokensPeer::REFRESH_TOKEN, $this->refresh_token);
} }
if ($this->isColumnModified(OauthRefreshTokensPeer::CLIENT_ID)) { if ($this->isColumnModified(OauthRefreshTokensPeer::CLIENT_ID)) {
@@ -672,7 +672,7 @@ abstract class BaseOauthRefreshTokens extends BaseObject implements Persistent
{ {
$criteria = new Criteria(OauthRefreshTokensPeer::DATABASE_NAME); $criteria = new Criteria(OauthRefreshTokensPeer::DATABASE_NAME);
$criteria->add(OauthRefreshTokensPeer::REFRESH_TOKES, $this->refresh_tokes); $criteria->add(OauthRefreshTokensPeer::REFRESH_TOKEN, $this->refresh_token);
return $criteria; return $criteria;
} }
@@ -683,18 +683,18 @@ abstract class BaseOauthRefreshTokens extends BaseObject implements Persistent
*/ */
public function getPrimaryKey() public function getPrimaryKey()
{ {
return $this->getRefreshTokes(); return $this->getRefreshToken();
} }
/** /**
* Generic method to set the primary key (refresh_tokes column). * Generic method to set the primary key (refresh_token column).
* *
* @param string $key Primary key. * @param string $key Primary key.
* @return void * @return void
*/ */
public function setPrimaryKey($key) public function setPrimaryKey($key)
{ {
$this->setRefreshTokes($key); $this->setRefreshToken($key);
} }
/** /**
@@ -721,7 +721,7 @@ abstract class BaseOauthRefreshTokens extends BaseObject implements Persistent
$copyObj->setNew(true); $copyObj->setNew(true);
$copyObj->setRefreshTokes(NULL); // this is a pkey column, so set to default value $copyObj->setRefreshToken(NULL); // this is a pkey column, so set to default value
} }

View File

@@ -31,8 +31,8 @@ abstract class BaseOauthRefreshTokensPeer
const NUM_LAZY_LOAD_COLUMNS = 0; const NUM_LAZY_LOAD_COLUMNS = 0;
/** the column name for the REFRESH_TOKES field */ /** the column name for the REFRESH_TOKEN field */
const REFRESH_TOKES = 'OAUTH_REFRESH_TOKENS.REFRESH_TOKES'; const REFRESH_TOKEN = 'OAUTH_REFRESH_TOKENS.REFRESH_TOKEN';
/** the column name for the CLIENT_ID field */ /** the column name for the CLIENT_ID field */
const CLIENT_ID = 'OAUTH_REFRESH_TOKENS.CLIENT_ID'; const CLIENT_ID = 'OAUTH_REFRESH_TOKENS.CLIENT_ID';
@@ -57,9 +57,9 @@ abstract class BaseOauthRefreshTokensPeer
* e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id'
*/ */
private static $fieldNames = array ( private static $fieldNames = array (
BasePeer::TYPE_PHPNAME => array ('RefreshTokes', 'ClientId', 'UserId', 'Expires', 'Scope', ), BasePeer::TYPE_PHPNAME => array ('RefreshToken', 'ClientId', 'UserId', 'Expires', 'Scope', ),
BasePeer::TYPE_COLNAME => array (OauthRefreshTokensPeer::REFRESH_TOKES, OauthRefreshTokensPeer::CLIENT_ID, OauthRefreshTokensPeer::USER_ID, OauthRefreshTokensPeer::EXPIRES, OauthRefreshTokensPeer::SCOPE, ), BasePeer::TYPE_COLNAME => array (OauthRefreshTokensPeer::REFRESH_TOKEN, OauthRefreshTokensPeer::CLIENT_ID, OauthRefreshTokensPeer::USER_ID, OauthRefreshTokensPeer::EXPIRES, OauthRefreshTokensPeer::SCOPE, ),
BasePeer::TYPE_FIELDNAME => array ('REFRESH_TOKES', 'CLIENT_ID', 'USER_ID', 'EXPIRES', 'SCOPE', ), BasePeer::TYPE_FIELDNAME => array ('REFRESH_TOKEN', 'CLIENT_ID', 'USER_ID', 'EXPIRES', 'SCOPE', ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, ) BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, )
); );
@@ -70,9 +70,9 @@ abstract class BaseOauthRefreshTokensPeer
* e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0 * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
*/ */
private static $fieldKeys = array ( private static $fieldKeys = array (
BasePeer::TYPE_PHPNAME => array ('RefreshTokes' => 0, 'ClientId' => 1, 'UserId' => 2, 'Expires' => 3, 'Scope' => 4, ), BasePeer::TYPE_PHPNAME => array ('RefreshToken' => 0, 'ClientId' => 1, 'UserId' => 2, 'Expires' => 3, 'Scope' => 4, ),
BasePeer::TYPE_COLNAME => array (OauthRefreshTokensPeer::REFRESH_TOKES => 0, OauthRefreshTokensPeer::CLIENT_ID => 1, OauthRefreshTokensPeer::USER_ID => 2, OauthRefreshTokensPeer::EXPIRES => 3, OauthRefreshTokensPeer::SCOPE => 4, ), BasePeer::TYPE_COLNAME => array (OauthRefreshTokensPeer::REFRESH_TOKEN => 0, OauthRefreshTokensPeer::CLIENT_ID => 1, OauthRefreshTokensPeer::USER_ID => 2, OauthRefreshTokensPeer::EXPIRES => 3, OauthRefreshTokensPeer::SCOPE => 4, ),
BasePeer::TYPE_FIELDNAME => array ('REFRESH_TOKES' => 0, 'CLIENT_ID' => 1, 'USER_ID' => 2, 'EXPIRES' => 3, 'SCOPE' => 4, ), BasePeer::TYPE_FIELDNAME => array ('REFRESH_TOKEN' => 0, 'CLIENT_ID' => 1, 'USER_ID' => 2, 'EXPIRES' => 3, 'SCOPE' => 4, ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, ) BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, )
); );
@@ -174,7 +174,7 @@ abstract class BaseOauthRefreshTokensPeer
public static function addSelectColumns(Criteria $criteria) public static function addSelectColumns(Criteria $criteria)
{ {
$criteria->addSelectColumn(OauthRefreshTokensPeer::REFRESH_TOKES); $criteria->addSelectColumn(OauthRefreshTokensPeer::REFRESH_TOKEN);
$criteria->addSelectColumn(OauthRefreshTokensPeer::CLIENT_ID); $criteria->addSelectColumn(OauthRefreshTokensPeer::CLIENT_ID);
@@ -186,8 +186,8 @@ abstract class BaseOauthRefreshTokensPeer
} }
const COUNT = 'COUNT(OAUTH_REFRESH_TOKENS.REFRESH_TOKES)'; const COUNT = 'COUNT(OAUTH_REFRESH_TOKENS.REFRESH_TOKEN)';
const COUNT_DISTINCT = 'COUNT(DISTINCT OAUTH_REFRESH_TOKENS.REFRESH_TOKES)'; const COUNT_DISTINCT = 'COUNT(DISTINCT OAUTH_REFRESH_TOKENS.REFRESH_TOKEN)';
/** /**
* Returns the number of rows matching criteria. * Returns the number of rows matching criteria.
@@ -396,8 +396,8 @@ abstract class BaseOauthRefreshTokensPeer
if ($values instanceof Criteria) { if ($values instanceof Criteria) {
$criteria = clone $values; // rename for clarity $criteria = clone $values; // rename for clarity
$comparison = $criteria->getComparison(OauthRefreshTokensPeer::REFRESH_TOKES); $comparison = $criteria->getComparison(OauthRefreshTokensPeer::REFRESH_TOKEN);
$selectCriteria->add(OauthRefreshTokensPeer::REFRESH_TOKES, $criteria->remove(OauthRefreshTokensPeer::REFRESH_TOKES), $comparison); $selectCriteria->add(OauthRefreshTokensPeer::REFRESH_TOKEN, $criteria->remove(OauthRefreshTokensPeer::REFRESH_TOKEN), $comparison);
} else { } else {
$criteria = $values->buildCriteria(); // gets full criteria $criteria = $values->buildCriteria(); // gets full criteria
@@ -460,7 +460,7 @@ abstract class BaseOauthRefreshTokensPeer
} else { } else {
// it must be the primary key // it must be the primary key
$criteria = new Criteria(self::DATABASE_NAME); $criteria = new Criteria(self::DATABASE_NAME);
$criteria->add(OauthRefreshTokensPeer::REFRESH_TOKES, (array) $values, Criteria::IN); $criteria->add(OauthRefreshTokensPeer::REFRESH_TOKEN, (array) $values, Criteria::IN);
} }
// Set the correct dbName // Set the correct dbName
@@ -534,7 +534,7 @@ abstract class BaseOauthRefreshTokensPeer
$criteria = new Criteria(OauthRefreshTokensPeer::DATABASE_NAME); $criteria = new Criteria(OauthRefreshTokensPeer::DATABASE_NAME);
$criteria->add(OauthRefreshTokensPeer::REFRESH_TOKES, $pk); $criteria->add(OauthRefreshTokensPeer::REFRESH_TOKEN, $pk);
$v = OauthRefreshTokensPeer::doSelect($criteria, $con); $v = OauthRefreshTokensPeer::doSelect($criteria, $con);
@@ -561,7 +561,7 @@ abstract class BaseOauthRefreshTokensPeer
$objs = array(); $objs = array();
} else { } else {
$criteria = new Criteria(); $criteria = new Criteria();
$criteria->add(OauthRefreshTokensPeer::REFRESH_TOKES, $pks, Criteria::IN); $criteria->add(OauthRefreshTokensPeer::REFRESH_TOKEN, $pks, Criteria::IN);
$objs = OauthRefreshTokensPeer::doSelect($criteria, $con); $objs = OauthRefreshTokensPeer::doSelect($criteria, $con);
} }
return $objs; return $objs;

View File

@@ -3013,7 +3013,7 @@
<table name="OAUTH_ACCESS_TOKENS"> <table name="OAUTH_ACCESS_TOKENS">
<column name="ACCESS_TOKEN" type="VARCHAR" size="40" required="true" primaryKey="true" /> <column name="ACCESS_TOKEN" type="VARCHAR" size="40" required="true" primaryKey="true" />
<column name="CLIENT_ID" type="VARCHAR" size="80" required="true" /> <column name="CLIENT_ID" type="VARCHAR" size="80" required="true" />
<column name="USER_ID" type="VARCHAR" size="32" required="true" /> <column name="USER_ID" type="VARCHAR" size="32" required="false" />
<column name="EXPIRES" type="TIMESTAMP" required="true" /> <column name="EXPIRES" type="TIMESTAMP" required="true" />
<column name="SCOPE" type="VARCHAR" size="2000" required="false" /> <column name="SCOPE" type="VARCHAR" size="2000" required="false" />
</table> </table>
@@ -3031,7 +3031,7 @@
<column name="REDIRECT_URI" type="VARCHAR" size="2000" required="true" /> <column name="REDIRECT_URI" type="VARCHAR" size="2000" required="true" />
</table> </table>
<table name="OAUTH_REFRESH_TOKENS"> <table name="OAUTH_REFRESH_TOKENS">
<column name="REFRESH_TOKES" type="VARCHAR" size="40" required="true" primaryKey="true" /> <column name="REFRESH_TOKEN" type="VARCHAR" size="40" required="true" primaryKey="true" />
<column name="CLIENT_ID" type="VARCHAR" size="80" required="true" /> <column name="CLIENT_ID" type="VARCHAR" size="80" required="true" />
<column name="USER_ID" type="VARCHAR" size="32" required="false" /> <column name="USER_ID" type="VARCHAR" size="32" required="false" />
<column name="EXPIRES" type="TIMESTAMP" required="true" /> <column name="EXPIRES" type="TIMESTAMP" required="true" />
@@ -3040,6 +3040,6 @@
<table name="OAUTH_SCOPES"> <table name="OAUTH_SCOPES">
<column name="TYPE" type="VARCHAR" size="40" required="true" /> <column name="TYPE" type="VARCHAR" size="40" required="true" />
<column name="SCOPE" type="VARCHAR" size="2000" required="false" /> <column name="SCOPE" type="VARCHAR" size="2000" required="false" />
<column name="CLIENT_ID" type="VARCHAR" size="80" required="true" /> <column name="CLIENT_ID" type="VARCHAR" size="80" required="false" />
</table> </table>
</database> </database>

View File

@@ -1472,5 +1472,81 @@ CREATE TABLE `SESSION_STORAGE`
PRIMARY KEY (`ID`), PRIMARY KEY (`ID`),
KEY `indexSessionStorage`(`ID`) KEY `indexSessionStorage`(`ID`)
)ENGINE=InnoDB ; )ENGINE=InnoDB ;
#-----------------------------------------------------------------------------
#-- OAUTH_ACCESS_TOKENS
#-----------------------------------------------------------------------------
DROP TABLE IF EXISTS `OAUTH_ACCESS_TOKENS`;
CREATE TABLE `OAUTH_ACCESS_TOKENS`
(
`ACCESS_TOKEN` VARCHAR(40) NOT NULL,
`CLIENT_ID` VARCHAR(80) NOT NULL,
`USER_ID` VARCHAR(32),
`EXPIRES` DATETIME NOT NULL,
`SCOPE` VARCHAR(2000),
PRIMARY KEY (`ACCESS_TOKEN`)
)ENGINE=InnoDB ;
#-----------------------------------------------------------------------------
#-- OAUTH_AUTHORIZATION_CODES
#-----------------------------------------------------------------------------
DROP TABLE IF EXISTS `OAUTH_AUTHORIZATION_CODES`;
CREATE TABLE `OAUTH_AUTHORIZATION_CODES`
(
`AUTHORIZATION_CODE` VARCHAR(40) NOT NULL,
`CLIENT_ID` VARCHAR(80) NOT NULL,
`USER_ID` VARCHAR(32),
`REDIRECT_URI` VARCHAR(2000),
`EXPIRES` DATETIME NOT NULL,
`SCOPE` VARCHAR(2000),
PRIMARY KEY (`AUTHORIZATION_CODE`)
)ENGINE=InnoDB ;
#-----------------------------------------------------------------------------
#-- OAUTH_CLIENTS
#-----------------------------------------------------------------------------
DROP TABLE IF EXISTS `OAUTH_CLIENTS`;
CREATE TABLE `OAUTH_CLIENTS`
(
`CLIENT_ID` VARCHAR(80) NOT NULL,
`CLIENT_SECRET` VARCHAR(80) NOT NULL,
`REDIRECT_URI` VARCHAR(2000) NOT NULL,
PRIMARY KEY (`CLIENT_ID`)
)ENGINE=InnoDB ;
#-----------------------------------------------------------------------------
#-- OAUTH_REFRESH_TOKENS
#-----------------------------------------------------------------------------
DROP TABLE IF EXISTS `OAUTH_REFRESH_TOKENS`;
CREATE TABLE `OAUTH_REFRESH_TOKENS`
(
`REFRESH_TOKEN` VARCHAR(40) NOT NULL,
`CLIENT_ID` VARCHAR(80) NOT NULL,
`USER_ID` VARCHAR(32),
`EXPIRES` DATETIME NOT NULL,
`SCOPE` VARCHAR(2000),
PRIMARY KEY (`REFRESH_TOKEN`)
)ENGINE=InnoDB ;
#-----------------------------------------------------------------------------
#-- OAUTH_SCOPES
#-----------------------------------------------------------------------------
DROP TABLE IF EXISTS `OAUTH_SCOPES`;
CREATE TABLE `OAUTH_SCOPES`
(
`TYPE` VARCHAR(40) NOT NULL,
`SCOPE` VARCHAR(2000),
`CLIENT_ID` VARCHAR(80)
)ENGINE=InnoDB ;
# This restores the fkey checks, after having unset them earlier # This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 1;

View File

@@ -44,7 +44,8 @@ if (isset($_SESSION["G_MESSAGE_TYPE"])) {
} }
//Initialize session //Initialize session
session_destroy();
@session_destroy();
session_start(); session_start();
session_regenerate_id(); session_regenerate_id();

View File

@@ -20,18 +20,21 @@ class Server implements iAuthenticate
/** /**
* @var OAuth2_Server * @var OAuth2_Server
*/ */
protected static $server; //protected static $server;
protected $server;
protected $storage;
/** /**
* @var OAuth2_Storage_Pdo * @var OAuth2_Storage_Pdo
*/ */
protected static $storage; //protected static $storage;
/** /**
* @var OAuth2_Request * @var OAuth2_Request
*/ */
protected static $request; protected static $request;
public function __construct() public function __construct()
{ {
$dir = __DIR__ . '/db/'; /*$dir = __DIR__ . '/db/';
$file = 'oauth.sqlite'; $file = 'oauth.sqlite';
if (!file_exists($dir . $file)) { if (!file_exists($dir . $file)) {
include_once $dir . 'rebuild_db.php'; include_once $dir . 'rebuild_db.php';
@@ -43,19 +46,59 @@ class Server implements iAuthenticate
static::$server = new \OAuth2\Server(static::$storage); static::$server = new \OAuth2\Server(static::$storage);
static::$server->addGrantType( static::$server->addGrantType(
new \OAuth2\GrantType\AuthorizationCode(static::$storage) new \OAuth2\GrantType\AuthorizationCode(static::$storage)
); );*/
static::$request = \OAuth2\Request::createFromGlobals();
require_once 'PmPdo.php';
$dsn = 'mysql:dbname=wf_workflow;host=localhost';
$username = 'root';
$password = 'sample';
// error reporting (this is a demo, after all!)
//ini_set('display_errors',1);error_reporting(E_ALL);
// Autoloading (composer is preferred, but for this example let's just do this)
//require_once('oauth2-server-php/src/OAuth2/Autoloader.php');
//\OAuth2\Autoloader::register();
// $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost"
$storage = new PmPdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));
// Pass a storage object or array of storage objects to the OAuth2 server class
$this->server = new \OAuth2\Server($storage);
// Add the "Client Credentials" grant type (it is the simplest of the grant types)
$this->server->addGrantType(new \OAuth2\GrantType\ClientCredentials($storage));
// Add the "Authorization Code" grant type (this is where the oauth magic happens)
$this->server->addGrantType(new \OAuth2\GrantType\AuthorizationCode($storage));
} }
/**
* @view oauth2/server/register.php
* @format HtmlFormat
*/
public function register()
{
static::$server->getResponse(static::$request);
return array('queryString' => $_SERVER['QUERY_STRING']);
}
/** /**
* Stage 1: Client sends the user to this page * Stage 1: Client sends the user to this page
* *
* User responds by accepting or denying * User responds by accepting or denying
* *
* @view oauth2/server/authorize.twig * @view oauth2/server/authorize.php
* @format HtmlFormat * @format HtmlFormat
*/ */
public function authorize() public function authorize()
{ {
static::$server->getResponse(static::$request); $this->server->getResponse(static::$request);
return array('queryString' => $_SERVER['QUERY_STRING']); return array('queryString' => $_SERVER['QUERY_STRING']);
} }
/** /**
@@ -73,12 +116,25 @@ class Server implements iAuthenticate
*/ */
public function postAuthorize($authorize = false) public function postAuthorize($authorize = false)
{ {
$response = static::$server->handleAuthorizeRequest( $request = \OAuth2\Request::createFromGlobals();
static::$request, $response = new \OAuth2\Response();
$response = $this->server->handleAuthorizeRequest(
$request,
$response,
(bool)$authorize (bool)$authorize
); );
if ($authorize) {
// this is only here so that you get to see your code in the cURL request. Otherwise, we'd redirect back to the client
$code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40);
//exit("SUCCESS! Authorization Code: $code");
}
die($response->send()); die($response->send());
} }
/** /**
* Stage 3: Client directly calls this api to exchange access token * Stage 3: Client directly calls this api to exchange access token
* *
@@ -100,7 +156,7 @@ class Server implements iAuthenticate
* *
* @access protected * @access protected
*/ */
public function access() public function postAccess()
{ {
return array( return array(
'friends' => array('john', 'matt', 'jane') 'friends' => array('john', 'matt', 'jane')
@@ -115,7 +171,21 @@ class Server implements iAuthenticate
*/ */
public function __isAllowed() public function __isAllowed()
{ {
return self::$server->verifyResourceRequest(static::$request); return $this->server->verifyResourceRequest(\OAuth2\Request::createFromGlobals());
//return self::$server->verifyAccessRequest(static::$request); }
/****************************************/
/**
* Stage 3: Client directly calls this api to exchange access token
*
* It can then use this access token to make calls to protected api
*/
public function postToken()
{
// Handle a request for an OAuth2.0 Access Token and send the response to the client
return $this->server->handleTokenRequest(\OAuth2\Request::createFromGlobals())->send();
} }
} }

View File

@@ -679,9 +679,9 @@ try {
//require_once ("propel/Propel.php"); //require_once ("propel/Propel.php");
//require_once ("creole/Creole.php"); //require_once ("creole/Creole.php");
list($host, $port) = explode(':', DB_HOST); list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, '');
$port = empty($port) ? '3306' : $port; $port = empty($port) ? '' : ";port=$port";
$handler = new PmSessionHandler(DB_USER, DB_PASS, DB_ADAPTER.":host=$host;dbname=".DB_NAME.";port=$port"); $handler = new PmSessionHandler(DB_USER, DB_PASS, DB_ADAPTER.":host=$host;dbname=".DB_NAME.$port);
session_start(); session_start();