From 29b09227ac54c1c5b672e02e36ba2c919c716b7a Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sun, 27 Jul 2014 17:12:03 +0100 Subject: [PATCH] Implemented more methods --- .../relational/Storage/AccessTokenStorage.php | 7 +++- .../relational/Storage/AuthCodeStorage.php | 35 +++++++++++++++---- .../relational/Storage/SessionStorage.php | 32 +++++++++++++---- 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/examples/relational/Storage/AccessTokenStorage.php b/examples/relational/Storage/AccessTokenStorage.php index 96481de5..e5b6d47c 100644 --- a/examples/relational/Storage/AccessTokenStorage.php +++ b/examples/relational/Storage/AccessTokenStorage.php @@ -73,7 +73,12 @@ class AccessTokenStorage extends Adapter implements AccessTokenInterface */ public function create($token, $expireTime, $sessionId) { - die(var_dump(__METHOD__, func_get_args())); + Capsule::table('oauth_access_tokens') + ->insert([ + 'access_token' => $token, + 'session_id' => $sessionId, + 'expire_time' => $expireTime + ]); } /** diff --git a/examples/relational/Storage/AuthCodeStorage.php b/examples/relational/Storage/AuthCodeStorage.php index 77126240..5a840237 100644 --- a/examples/relational/Storage/AuthCodeStorage.php +++ b/examples/relational/Storage/AuthCodeStorage.php @@ -24,13 +24,14 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface if (count($result) === 1) { $token = new AuthCodeEntity($this->server); $token->setId($result[0]['auth_code']); + $token->setRedirectUri($result[0]['client_redirect_uri']); return $token; } return null; } - public function create($token, $$expireTime, $sessionId) + public function create($token, $expireTime, $sessionId, $redirectUri) { Capsule::table('oauth_auth_codes') ->insert([ @@ -46,7 +47,25 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface */ public function getScopes(AuthCodeEntity $token) { - die(var_dump(__METHOD__, func_get_args())); + $result = Capsule::table('oauth_auth_code_scopes') + ->select(['oauth_scopes.id', 'oauth_scopes.description']) + ->join('oauth_scopes', 'oauth_auth_code_scopes.scope', '=', 'oauth_scopes.id') + ->where('auth_code', $token->getId()) + ->get(); + + $response = []; + + if (count($result) > 0) { + foreach ($result as $row) { + $scope = (new ScopeEntity($this->server))->hydrate([ + 'id' => $row['id'], + 'description' => $row['description'] + ]); + $response[] = $scope; + } + } + + return $response; } /** @@ -55,10 +74,10 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface public function associateScope(AuthCodeEntity $token, ScopeEntity $scope) { Capsule::table('oauth_auth_code_scopes') - ->insert([ - 'auth_code' => $token->getToken(), - 'scope' => $scope->getId() - ]); + ->insert([ + 'auth_code' => $token->getId(), + 'scope' => $scope->getId() + ]); } /** @@ -66,6 +85,8 @@ class AuthCodeStorage extends Adapter implements AuthCodeInterface */ public function delete(AuthCodeEntity $token) { - die(var_dump(__METHOD__, func_get_args())); + Capsule::table('oauth_auth_codes') + ->where('auth_code', $token->getId()) + ->delete(); } } diff --git a/examples/relational/Storage/SessionStorage.php b/examples/relational/Storage/SessionStorage.php index faf0162b..62e3ba3b 100644 --- a/examples/relational/Storage/SessionStorage.php +++ b/examples/relational/Storage/SessionStorage.php @@ -29,11 +29,10 @@ class SessionStorage extends Adapter implements SessionInterface $result = Capsule::table('oauth_sessions') ->select(['oauth_sessions.id', 'oauth_sessions.owner_type', 'oauth_sessions.owner_id', 'oauth_sessions.client_id', 'oauth_sessions.client_redirect_uri']) ->join('oauth_access_tokens', 'oauth_access_tokens.session_id', '=', 'oauth_sessions.id') - ->where('oauth_access_tokens.access_token', $accessToken->getToken()) + ->where('oauth_access_tokens.access_token', $accessToken->getId()) ->get(); if (count($result) === 1) { - // die(var_dump($result)); $session = new SessionEntity($this->server); $session->setId($result[0]['id']); $session->setOwner($result[0]['owner_type'], $result[0]['owner_id']); @@ -49,7 +48,21 @@ class SessionStorage extends Adapter implements SessionInterface */ public function getByAuthCode(AuthCodeEntity $authCode) { - die(var_dump(__METHOD__, func_get_args())); + $result = Capsule::table('oauth_sessions') + ->select(['oauth_sessions.id', 'oauth_sessions.owner_type', 'oauth_sessions.owner_id', 'oauth_sessions.client_id', 'oauth_sessions.client_redirect_uri']) + ->join('oauth_auth_codes', 'oauth_auth_codes.session_id', '=', 'oauth_sessions.id') + ->where('oauth_auth_codes.auth_code', $authCode->getId()) + ->get(); + + if (count($result) === 1) { + $session = new SessionEntity($this->server); + $session->setId($result[0]['id']); + $session->setOwner($result[0]['owner_type'], $result[0]['owner_id']); + + return $session; + } + + return null; } /** @@ -67,9 +80,10 @@ class SessionStorage extends Adapter implements SessionInterface $scopes = []; foreach ($result as $scope) { - $scopes[] = (new ScopeEntity($this->server)) - ->setId($scope['id']) - ->setDescription($scope['description']); + $scopes[] = (new ScopeEntity($this->server))->hydrate([ + 'id' => $scope['id'], + 'description' => $scope['description'] + ]); } return $scopes; @@ -95,6 +109,10 @@ class SessionStorage extends Adapter implements SessionInterface */ public function associateScope(SessionEntity $session, ScopeEntity $scope) { - die(var_dump(__CLASS__.'::'.__METHOD__, func_get_args())); + Capsule::table('oauth_session_scopes') + ->insert([ + 'session_id' => $session->getId(), + 'scope' => $scope->getId() + ]); } }