Working out the routing

This commit is contained in:
Josh Sherman 2014-10-13 21:27:19 -04:00
parent 75596ed725
commit 8e9c644822
2 changed files with 43 additions and 18 deletions

View file

@ -10,7 +10,14 @@ class Resource extends \Pickles\Resource
{
public function __construct()
{
switch ($_REQUEST['request'])
parent::__construct();
if (!isset($this->config['oauth'][$_SERVER['__version']]))
{
throw new \Exception('Forbidden.', 403);
}
switch (substr($_REQUEST['request'], strlen($_SERVER['__version']) + 2))
{
case 'oauth/access_token':
try
@ -22,8 +29,24 @@ class Resource extends \Pickles\Resource
$server->setClientStorage(new ClientStorage);
$server->setScopeStorage(new ScopeStorage);
$passwordGrant = new PasswordGrant;
$passwordGrant->setVerifyCredentialsCallback(function ($username, $password)
switch ($_REQUEST['grant_type'])
{
case 'authorization_code':
throw new \Exception('Not Implemented', 501);
break;
case 'client_credentials':
throw new \Exception('Not Implemented', 501);
break;
case 'implicit':
throw new \Exception('Not Implemented', 501);
break;
case 'password':
$grant = new PasswordGrant;
$grant->setVerifyCredentialsCallback(function ($username, $password)
{
$user = new User(['email' => $username]);
@ -31,16 +54,19 @@ class Resource extends \Pickles\Resource
&& password_verify($password, $user->record['password']);
});
$server->addGrantType($passwordGrant);
break;
// @todo Add grant types listed in the config. Password is always added
case 'refresh_token':
throw new \Exception('Not Implemented', 501);
break;
}
$server->addGrantType($grant);
$response = $server->issueAccessToken();
}
catch (\Exception $e)
{
// @todo Set error code's accordingly.
throw new \Exception($e->getMessage(), $e->httpStatusCode);
}

View file

@ -44,6 +44,8 @@ class Router extends Object
$components = explode('/', $request);
$nouns = [];
$uids = [];
$version = array_shift($components);
$_SERVER['__version'] = substr($version, 1);
// Checks if we're trying to rock some OAuth
if ($components[0] == 'oauth')
@ -52,9 +54,6 @@ class Router extends Object
}
else
{
$version = array_shift($components);
$_SERVER['__version'] = substr($version, 1);
// Loops through the components to determine nouns and IDs
foreach ($components as $index => $component)
{