Worked through basic authentication
This commit is contained in:
parent
718f8d64bb
commit
8a1ac4fb47
3 changed files with 49 additions and 2 deletions
17
src/classes/Auth.php
Normal file
17
src/classes/Auth.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pickles;
|
||||||
|
|
||||||
|
abstract class Auth extends \Object
|
||||||
|
{
|
||||||
|
public function basic()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function oauth2()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -77,6 +77,8 @@ class Resource extends Object
|
||||||
*/
|
*/
|
||||||
public function __construct($uids = false)
|
public function __construct($uids = false)
|
||||||
{
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
$this->uids = $uids;
|
$this->uids = $uids;
|
||||||
$method = $_SERVER['REQUEST_METHOD'];
|
$method = $_SERVER['REQUEST_METHOD'];
|
||||||
|
|
||||||
|
@ -96,8 +98,28 @@ class Resource extends Object
|
||||||
if ($this->auth === true
|
if ($this->auth === true
|
||||||
|| (isset($this->auth[$method]) && $this->auth[$method]))
|
|| (isset($this->auth[$method]) && $this->auth[$method]))
|
||||||
{
|
{
|
||||||
print_r($_SERVER);
|
if (!$this->config->pickles['auth'])
|
||||||
exit('needs 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]);
|
$filter = isset($this->filter[$method]);
|
||||||
|
|
|
@ -84,6 +84,14 @@ function __autoload($class)
|
||||||
'class' => $pickles_path,
|
'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
|
// Path as the key, boolean value is whether ot not to convert back to hyphenated
|
||||||
$paths = [
|
$paths = [
|
||||||
$pickles_paths['class'] => false,
|
$pickles_paths['class'] => false,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue