Worked through basic authentication

This commit is contained in:
Josh Sherman 2014-09-27 16:40:41 -04:00
parent 718f8d64bb
commit 8a1ac4fb47
3 changed files with 49 additions and 2 deletions

17
src/classes/Auth.php Normal file
View file

@ -0,0 +1,17 @@
<?php
namespace Pickles;
abstract class Auth extends \Object
{
public function basic()
{
}
public function oauth2()
{
}
}

View file

@ -77,6 +77,8 @@ class Resource extends Object
*/
public function __construct($uids = false)
{
parent::__construct();
$this->uids = $uids;
$method = $_SERVER['REQUEST_METHOD'];
@ -96,8 +98,28 @@ class Resource extends Object
if ($this->auth === true
|| (isset($this->auth[$method]) && $this->auth[$method]))
{
print_r($_SERVER);
exit('needs auth');
if (!$this->config->pickles['auth'])
{
throw new Exception('401 - Authentication is not configured properly.');
}
// This class should be in the classes directory of the service
$auth = new Auth();
switch ($this->config->pickles['auth'])
{
case 'basic':
$auth->basic();
break;
case 'oauth2':
$auth->oauth2();
break;
default:
throw new Exception('401 - Invalid authentication scheme.');
break;
}
}
$filter = isset($this->filter[$method]);

View file

@ -84,6 +84,14 @@ function __autoload($class)
'class' => $pickles_path,
];
// Hack to deal with namespaces
if (strpos($class, '\\') !== false)
{
list($namespace, $class) = explode('\\', $class);
return require_once $pickles_path . 'classes/' . $class . '.php';
}
// Path as the key, boolean value is whether ot not to convert back to hyphenated
$paths = [
$pickles_paths['class'] => false,