Finished up password grant

This commit is contained in:
Josh Sherman 2014-10-13 22:50:43 -04:00
parent ec14621e7c
commit 49a713eb35
3 changed files with 17 additions and 23 deletions

View file

@ -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)
{

View file

@ -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,

View file

@ -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);