Implementing storage interfaces

This commit is contained in:
Josh Sherman 2014-10-14 07:11:03 -04:00
parent 49a713eb35
commit c244e02d46
2 changed files with 31 additions and 12 deletions

View file

@ -55,25 +55,27 @@ class ClientStorage extends StorageAdapter implements ClientInterface
public function getBySession(SessionEntity $session) public function getBySession(SessionEntity $session)
{ {
/* $sql = 'SELECT oauth_clients.id, oauth_clients.name'
$result = Capsule::table('oauth_clients') . ' FROM oauth_clients'
->select(['oauth_clients.id', 'oauth_clients.name']) . ' JOIN oauth_sessions'
->join('oauth_sessions', 'oauth_clients.id', '=', 'oauth_sessions.client_id') . ' ON oauth_clients.id = oauth_sessions.client_id'
->where('oauth_sessions.id', $session->getId()) . ' WHERE oauth_sessions.id = ?';
->get();
if (count($result) === 1) { $results = $this->db->fetch($sql, [$session->getId()]);
if (count($results) === 1)
{
$client = new ClientEntity($this->server); $client = new ClientEntity($this->server);
$client->hydrate([ $client->hydrate([
'id' => $result[0]['id'], 'id' => $results[0]['id'],
'name' => $result[0]['name'] 'name' => $results[0]['name']
]); ]);
return $client; return $client;
} }
return null; return null;
*/
} }
} }

View file

@ -14,6 +14,12 @@
namespace Pickles; namespace Pickles;
use \League\OAuth2\Server\ResourceServer;
use Pickles\OAuth2\AccessTokenStorage;
use Pickles\OAuth2\ClientStorage;
use Pickles\OAuth2\ScopeStorage;
use Pickles\OAuth2\SessionStorage;
/** /**
* Resource Class * Resource Class
* *
@ -74,11 +80,22 @@ class Resource extends Object
try try
{ {
// Check auth if flag is explicitly true or is true for the method // Checks if auth flag is explicity true or true for the method
if ($this->auth === true if ($this->auth === true
|| (isset($this->auth[$method]) && $this->auth[$method])) || (isset($this->auth[$method]) && $this->auth[$method]))
{ {
if (!isset($this->config['oauth2'][$_SERVER['__version']])) if (isset($this->config['oauth'][$_SERVER['__version']]))
{
$server = new ResourceServer(
new SessionStorage,
new AccessTokenStorage,
new ClientStorage,
new ScopeStorage
);
$server->isValidRequest();
}
else
{ {
throw new \Exception('Authentication is not configured properly.', 401); throw new \Exception('Authentication is not configured properly.', 401);
} }