Working out the routing
This commit is contained in:
parent
75596ed725
commit
8e9c644822
2 changed files with 43 additions and 18 deletions
|
@ -10,7 +10,14 @@ class Resource extends \Pickles\Resource
|
||||||
{
|
{
|
||||||
public function __construct()
|
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':
|
case 'oauth/access_token':
|
||||||
try
|
try
|
||||||
|
@ -22,25 +29,44 @@ class Resource extends \Pickles\Resource
|
||||||
$server->setClientStorage(new ClientStorage);
|
$server->setClientStorage(new ClientStorage);
|
||||||
$server->setScopeStorage(new ScopeStorage);
|
$server->setScopeStorage(new ScopeStorage);
|
||||||
|
|
||||||
$passwordGrant = new PasswordGrant;
|
switch ($_REQUEST['grant_type'])
|
||||||
$passwordGrant->setVerifyCredentialsCallback(function ($username, $password)
|
|
||||||
{
|
{
|
||||||
$user = new User(['email' => $username]);
|
case 'authorization_code':
|
||||||
|
throw new \Exception('Not Implemented', 501);
|
||||||
|
break;
|
||||||
|
|
||||||
return $user->count()
|
case 'client_credentials':
|
||||||
&& password_verify($password, $user->record['password']);
|
throw new \Exception('Not Implemented', 501);
|
||||||
});
|
break;
|
||||||
|
|
||||||
$server->addGrantType($passwordGrant);
|
case 'implicit':
|
||||||
|
throw new \Exception('Not Implemented', 501);
|
||||||
|
break;
|
||||||
|
|
||||||
// @todo Add grant types listed in the config. Password is always added
|
case 'password':
|
||||||
|
$grant = new PasswordGrant;
|
||||||
|
|
||||||
|
$grant->setVerifyCredentialsCallback(function ($username, $password)
|
||||||
|
{
|
||||||
|
$user = new User(['email' => $username]);
|
||||||
|
|
||||||
|
return $user->count()
|
||||||
|
&& password_verify($password, $user->record['password']);
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'refresh_token':
|
||||||
|
throw new \Exception('Not Implemented', 501);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$server->addGrantType($grant);
|
||||||
|
|
||||||
$response = $server->issueAccessToken();
|
$response = $server->issueAccessToken();
|
||||||
}
|
}
|
||||||
catch (\Exception $e)
|
catch (\Exception $e)
|
||||||
{
|
{
|
||||||
// @todo Set error code's accordingly.
|
|
||||||
|
|
||||||
throw new \Exception($e->getMessage(), $e->httpStatusCode);
|
throw new \Exception($e->getMessage(), $e->httpStatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,10 +40,12 @@ class Router extends Object
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Grabs the requested page
|
// Grabs the requested page
|
||||||
$request = $_REQUEST['request'];
|
$request = $_REQUEST['request'];
|
||||||
$components = explode('/', $request);
|
$components = explode('/', $request);
|
||||||
$nouns = [];
|
$nouns = [];
|
||||||
$uids = [];
|
$uids = [];
|
||||||
|
$version = array_shift($components);
|
||||||
|
$_SERVER['__version'] = substr($version, 1);
|
||||||
|
|
||||||
// Checks if we're trying to rock some OAuth
|
// Checks if we're trying to rock some OAuth
|
||||||
if ($components[0] == 'oauth')
|
if ($components[0] == 'oauth')
|
||||||
|
@ -52,9 +54,6 @@ class Router extends Object
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$version = array_shift($components);
|
|
||||||
$_SERVER['__version'] = substr($version, 1);
|
|
||||||
|
|
||||||
// Loops through the components to determine nouns and IDs
|
// Loops through the components to determine nouns and IDs
|
||||||
foreach ($components as $index => $component)
|
foreach ($components as $index => $component)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue