diff --git a/src/classes/Auth.php b/src/classes/Auth.php new file mode 100644 index 0000000..785e6bc --- /dev/null +++ b/src/classes/Auth.php @@ -0,0 +1,17 @@ +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]); diff --git a/src/pickles.php b/src/pickles.php index 3d80223..4e2d8c1 100644 --- a/src/pickles.php +++ b/src/pickles.php @@ -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,