diff --git a/src/OAuth2/ClientStorage.php b/src/OAuth2/ClientStorage.php index fe02603..dddfeda 100644 --- a/src/OAuth2/ClientStorage.php +++ b/src/OAuth2/ClientStorage.php @@ -55,25 +55,27 @@ class ClientStorage extends StorageAdapter implements ClientInterface public function getBySession(SessionEntity $session) { - /* - $result = Capsule::table('oauth_clients') - ->select(['oauth_clients.id', 'oauth_clients.name']) - ->join('oauth_sessions', 'oauth_clients.id', '=', 'oauth_sessions.client_id') - ->where('oauth_sessions.id', $session->getId()) - ->get(); + $sql = 'SELECT oauth_clients.id, oauth_clients.name' + . ' FROM oauth_clients' + . ' JOIN oauth_sessions' + . ' ON oauth_clients.id = oauth_sessions.client_id' + . ' WHERE oauth_sessions.id = ?'; - if (count($result) === 1) { + $results = $this->db->fetch($sql, [$session->getId()]); + + if (count($results) === 1) + { $client = new ClientEntity($this->server); + $client->hydrate([ - 'id' => $result[0]['id'], - 'name' => $result[0]['name'] + 'id' => $results[0]['id'], + 'name' => $results[0]['name'] ]); return $client; } return null; - */ } } diff --git a/src/Resource.php b/src/Resource.php index 1b94fa2..4ca265f 100644 --- a/src/Resource.php +++ b/src/Resource.php @@ -14,6 +14,12 @@ 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 * @@ -74,11 +80,22 @@ class Resource extends Object 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 || (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); }