diff --git a/src/OAuth2/Resource.php b/src/OAuth2/Resource.php index 7f949b9..68a3a73 100644 --- a/src/OAuth2/Resource.php +++ b/src/OAuth2/Resource.php @@ -5,13 +5,12 @@ namespace Pickles\OAuth2; use \League\OAuth2\Server\AuthorizationServer; use \League\OAuth2\Server\Grant\PasswordGrant; use \Pickles\App\Models\User; +use \Pickles\Config; class Resource extends \Pickles\Resource { - public function __construct() + public function POST() { - parent::__construct(); - if (!isset($this->config['oauth'][$_SERVER['__version']])) { throw new \Exception('Forbidden.', 403); @@ -48,7 +47,11 @@ class Resource extends \Pickles\Resource $grant->setVerifyCredentialsCallback(function ($username, $password) { - $user = new User(['email' => $username]); + $user = new User([ + 'conditions' => [ + 'email' => $username, + ], + ]); return $user->count() && password_verify($password, $user->record['password']); @@ -64,6 +67,8 @@ class Resource extends \Pickles\Resource $server->addGrantType($grant); $response = $server->issueAccessToken(); + + return $response; } catch (\Exception $e) { diff --git a/src/Resource.php b/src/Resource.php index 9857cb2..1b94fa2 100644 --- a/src/Resource.php +++ b/src/Resource.php @@ -26,15 +26,6 @@ namespace Pickles; */ class Resource extends Object { - /** - * HTTPS - * - * Whether or not the page should be loaded via HTTP Secure. - * - * @var boolean defaults to false - */ - public $https = false; - /** * Filter * @@ -83,14 +74,6 @@ class Resource extends Object try { - // Determines if we need to serve over HTTP or HTTPS - if (($this->https === true - || (isset($this->https[$method]) && $this->https[$method])) - && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == false)) - { - throw new \Exception('HTTPS is required.', 400); - } - // Check auth if flag is explicitly true or is true for the method if ($this->auth === true || (isset($this->auth[$method]) && $this->auth[$method])) @@ -101,7 +84,7 @@ class Resource extends Object } } - // Hack together some new globals + // Hacks together some new globals if (in_array($method, ['PUT', 'DELETE'])) { $GLOBALS['_' . $method] = []; @@ -337,7 +320,7 @@ class Resource extends Object { http_response_code($this->status); header('Content-Type: application/json'); - header('X-Powered-By: Pickles v2 - https://picklesphp.com'); + header('X-Powered-By: Pickles (http://picklesphp.com)'); $meta = [ 'status' => $this->status, diff --git a/src/Router.php b/src/Router.php index c41baf7..c9b0a90 100644 --- a/src/Router.php +++ b/src/Router.php @@ -39,6 +39,12 @@ class Router extends Object try { + // Secure by default + if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == false) + { + throw new \Exception('HTTPS is required.', 400); + } + // Grabs the requested page $request = $_REQUEST['request']; $components = explode('/', $request);