Working on oauth
This commit is contained in:
parent
846f75d0f3
commit
aa8c86e5c2
4 changed files with 35 additions and 29 deletions
|
@ -23,7 +23,7 @@
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.4",
|
"php": ">=5.4",
|
||||||
"league/oauth2-server": "3.*"
|
"league/oauth2-server": "4.*"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
11
src/Auth.php
11
src/Auth.php
|
@ -27,14 +27,19 @@ class Auth extends Object
|
||||||
* Rather use an API key and not worry about the password? Do it. Return
|
* Rather use an API key and not worry about the password? Do it. Return
|
||||||
* true when authentication is successful and false when it is not.
|
* true when authentication is successful and false when it is not.
|
||||||
*/
|
*/
|
||||||
public function basic()
|
public static function basic()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function oauth2()
|
/**
|
||||||
|
* OAuth2
|
||||||
|
*
|
||||||
|
* Handles authentication of the access token.
|
||||||
|
*/
|
||||||
|
final static public function oauth2()
|
||||||
{
|
{
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,47 +95,46 @@ 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]))
|
||||||
{
|
{
|
||||||
if (!$this->config['pickles']['auth'])
|
if (!$this->config['auth'][$_SERVER['__version']])
|
||||||
{
|
{
|
||||||
throw new \Exception('Authentication is not configured properly.', 401);
|
throw new \Exception('Authentication is not configured properly.', 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This class should be in the classes directory of the service
|
switch ($this->config['auth'][$_SERVER['__version']]['strategy'])
|
||||||
$auth = '\\' . $this->config['pickles']['namespace'] . '\\Classes\\Auth';
|
|
||||||
|
|
||||||
// Strips preceding slashs when there is no namespace
|
|
||||||
if (strpos($auth, '\\\\') === 0)
|
|
||||||
{
|
|
||||||
$auth = substr($auth, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
$auth = new $auth();
|
|
||||||
|
|
||||||
// @todo Remove when switch is implemented
|
|
||||||
if (!$auth->basic())
|
|
||||||
{
|
|
||||||
throw new \Exception('Invalid authentication credentials.', 401);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @todo Not yet implemented
|
|
||||||
/*
|
|
||||||
switch ($this->config['pickles']['auth'])
|
|
||||||
{
|
{
|
||||||
case 'basic':
|
case 'basic':
|
||||||
if (!$auth->basic())
|
// @todo Check if Auth class has been implemented, if
|
||||||
|
// not, fallback to the parent
|
||||||
|
|
||||||
|
// This class should be in the classes directory of the service
|
||||||
|
$auth = '\\' . $this->config['pickles']['namespace'] . '\\Classes\\Auth';
|
||||||
|
|
||||||
|
// Strips preceding slashs when there is no namespace
|
||||||
|
if (strpos($auth, '\\\\') === 0)
|
||||||
|
{
|
||||||
|
$auth = substr($auth, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @todo Custom method
|
||||||
|
if (!$auth::basic())
|
||||||
{
|
{
|
||||||
throw new \Exception('Invalid authentication credentials.', 401);
|
throw new \Exception('Invalid authentication credentials.', 401);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'oauth2':
|
case 'oauth2':
|
||||||
$auth->oauth2();
|
/*
|
||||||
|
if (!Auth::oauth2())
|
||||||
|
{
|
||||||
|
throw new \Exception('Invalid access token.', 401);
|
||||||
|
}
|
||||||
|
*/
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new \Exception('Invalid authentication scheme.', 401);
|
throw new \Exception('Invalid authentication strategy.', 401);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hack together some new globals
|
// Hack together some new globals
|
||||||
|
|
|
@ -46,6 +46,8 @@ class Router extends Object
|
||||||
$nouns = [];
|
$nouns = [];
|
||||||
$uids = [];
|
$uids = [];
|
||||||
|
|
||||||
|
$_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