diff --git a/src/League/OAuth2/Server/Storage/DBAL/Client.php b/src/League/OAuth2/Server/Storage/DBAL/Client.php deleted file mode 100644 index 91e86f88..00000000 --- a/src/League/OAuth2/Server/Storage/DBAL/Client.php +++ /dev/null @@ -1,52 +0,0 @@ - - */ -namespace League\OAuth2\Server\Storage\DBAL; - -use League\OAuth2\Server\Storage\ClientInterface; - -class Client implements ClientInterface -{ - protected $db; - - public function __construct($db) - { - $this->db = $db; - } - - public function getClient($clientId, $clientSecret = null, $redirectUri = null, $grantType = null) - { - if ( ! is_null($redirectUri) && is_null($clientSecret)) { - $stmt = $this->db->prepare('SELECT oauth_clients.id, oauth_clients.secret, oauth_client_endpoints.redirect_uri, oauth_clients.name FROM oauth_clients LEFT JOIN oauth_client_endpoints ON oauth_client_endpoints.client_id = oauth_clients.id WHERE oauth_clients.id = :clientId AND oauth_client_endpoints.redirect_uri = :redirectUri'); - $stmt->bindValue(':redirectUri', $redirectUri); - } - - elseif ( ! is_null($clientSecret) && is_null($redirectUri)) { - $stmt = $this->db->prepare('SELECT oauth_clients.id, oauth_clients.secret, oauth_clients.name FROM oauth_clients WHERE oauth_clients.id = :clientId AND oauth_clients.secret = :clientSecret'); - $stmt->bindValue(':clientSecret', $clientSecret); - } - - elseif ( ! is_null($clientSecret) && ! is_null($redirectUri)) { - $stmt = $this->db->prepare('SELECT oauth_clients.id, oauth_clients.secret, oauth_client_endpoints.redirect_uri, oauth_clients.name FROM oauth_clients LEFT JOIN oauth_client_endpoints ON oauth_client_endpoints.client_id = oauth_clients.id WHERE oauth_clients.id = :clientId AND oauth_clients.secret = :clientSecret AND oauth_client_endpoints.redirect_uri = :redirectUri'); - $stmt->bindValue(':redirectUri', $redirectUri); - $stmt->bindValue(':clientSecret', $clientSecret); - } - - $stmt->bindValue(':clientId', $clientId); - $stmt->execute(); - - $row = $stmt->fetch(\PDO::FETCH_OBJ); - - if ($row === false) { - return false; - } - - return array( - 'client_id' => $row->id, - 'client_secret' => $row->secret, - 'redirect_uri' => (isset($row->redirect_uri)) ? $row->redirect_uri : null, - 'name' => $row->name - ); - } -} \ No newline at end of file diff --git a/src/League/OAuth2/Server/Storage/DBAL/Scope.php b/src/League/OAuth2/Server/Storage/DBAL/Scope.php deleted file mode 100644 index 3c5639ea..00000000 --- a/src/League/OAuth2/Server/Storage/DBAL/Scope.php +++ /dev/null @@ -1,38 +0,0 @@ - - */ -namespace League\OAuth2\Server\Storage\DBAL; - -use League\OAuth2\Server\Storage\ScopeInterface; - -class Scope implements ScopeInterface -{ - protected $db; - - public function __construct($db) - { - $this->db = $db; - } - - public function getScope($scope, $clientId = null, $grantType = null) - { - $stmt = $this->db->prepare('SELECT * FROM oauth_scopes WHERE oauth_scopes.scope = :scope'); - $stmt->bindValue(':scope', $scope); - $stmt->execute(); - - $row = $stmt->fetch(\PDO::FETCH_OBJ); - - if ($row === false) { - return false; - } - - return array( - 'id' => $row->id, - 'scope' => $row->scope, - 'name' => $row->name, - 'description' => $row->description - ); - - } -} \ No newline at end of file diff --git a/src/League/OAuth2/Server/Storage/DBAL/Session.php b/src/League/OAuth2/Server/Storage/DBAL/Session.php deleted file mode 100644 index 7423601f..00000000 --- a/src/League/OAuth2/Server/Storage/DBAL/Session.php +++ /dev/null @@ -1,176 +0,0 @@ - - */ -namespace League\OAuth2\Server\Storage\DBAL; - -use League\OAuth2\Server\Storage\SessionInterface; - -class Session implements SessionInterface -{ - protected $db; - - public function __construct($db) - { - $this->db = $db; - } - - public function createSession($clientId, $ownerType, $ownerId) - { - $this->db->insert('oauth_sessions', array( - 'client_id' => $clientId, - 'owner_type' => $ownerType, - 'owner_id' => $ownerId, - )); - - return $this->db->lastInsertId(); - } - - public function deleteSession($clientId, $ownerType, $ownerId) - { - $this->db->delete('oauth_sessions', array( - 'client_id' => $clientId, - 'owner_type' => $ownerType, - 'owner_id' => $ownerId, - )); - } - - public function associateRedirectUri($sessionId, $redirectUri) - { - $this->db->insert('oauth_session_redirects', array( - 'session_id' => $sessionId, - 'redirect_uri' => $redirectUri, - )); - } - - public function associateAccessToken($sessionId, $accessToken, $expireTime) - { - $this->db->insert('oauth_session_access_tokens', array( - 'session_id' => $sessionId, - 'access_token' => $accessToken, - 'access_token_expires' => $expireTime, - )); - - return $this->db->lastInsertId(); - } - - public function associateRefreshToken($accessTokenId, $refreshToken, $expireTime, $clientId) - { - $this->db->insert('oauth_session_refresh_tokens', array( - 'session_access_token_id' => $accessTokenId, - 'refresh_token' => $refreshToken, - 'refresh_token_expires' => $expireTime, - 'client_id' => $clientId, - )); - } - - public function associateAuthCode($sessionId, $authCode, $expireTime) - { - $this->db->insert('oauth_session_authcodes', array( - 'session_id' => $sessionId, - 'auth_code' => $authCode, - 'auth_code_expires' => $expireTime, - )); - - return $this->db->lastInsertId(); - } - - public function removeAuthCode($sessionId) - { - $this->db->delete('oauth_session_authcodes', array( - 'session_id' => $sessionId, - )); - } - - public function validateAuthCode($clientId, $redirectUri, $authCode) - { - $stmt = $this->db->prepare('SELECT oauth_sessions.id AS session_id, oauth_session_authcodes.id AS authcode_id - FROM oauth_sessions JOIN oauth_session_authcodes ON oauth_session_authcodes.`session_id` - = oauth_sessions.id JOIN oauth_session_redirects ON oauth_session_redirects.`session_id` - = oauth_sessions.id WHERE oauth_sessions.client_id = :clientId AND oauth_session_authcodes.`auth_code` - = :authCode AND `oauth_session_authcodes`.`auth_code_expires` >= :time AND - `oauth_session_redirects`.`redirect_uri` = :redirectUri'); - $stmt->bindValue(':clientId', $clientId); - $stmt->bindValue(':redirectUri', $redirectUri); - $stmt->bindValue(':authCode', $authCode); - $stmt->bindValue(':time', time()); - $stmt->execute(); - - $result = $stmt->fetch(\PDO::FETCH_OBJ); - - return ($result === false) ? false : (array) $result; - } - - public function validateAccessToken($accessToken) - { - $stmt = $this->db->prepare('SELECT session_id, oauth_sessions.`client_id`, oauth_sessions.`owner_id`, oauth_sessions.`owner_type` FROM `oauth_session_access_tokens` JOIN oauth_sessions ON oauth_sessions.`id` = session_id WHERE access_token = :accessToken AND access_token_expires >= ' . time()); - $stmt->bindValue(':accessToken', $accessToken); - $stmt->execute(); - - $result = $stmt->fetch(\PDO::FETCH_OBJ); - return ($result === false) ? false : (array) $result; - } - - public function removeRefreshToken($refreshToken) - { - $this->db->delete('oauth_session_refresh_tokens', array( - 'refresh_token' => $refreshToken, - )); - } - - public function validateRefreshToken($refreshToken, $clientId) - { - $stmt = $this->db->prepare('SELECT session_access_token_id FROM `oauth_session_refresh_tokens` WHERE - refresh_token = :refreshToken AND client_id = :clientId AND refresh_token_expires >= ' . time()); - $stmt->bindValue(':refreshToken', $refreshToken); - $stmt->bindValue(':clientId', $clientId); - $stmt->execute(); - - $result = $stmt->fetch(\PDO::FETCH_OBJ); - return ($result === false) ? false : $result->session_access_token_id; - } - - public function getAccessToken($accessTokenId) - { - $stmt = $this->db->prepare('SELECT * FROM `oauth_session_access_tokens` WHERE `id` = :accessTokenId'); - $stmt->bindValue(':accessTokenId', $accessTokenId); - $stmt->execute(); - - $result = $stmt->fetch(\PDO::FETCH_OBJ); - return ($result === false) ? false : (array) $result; - } - - public function associateAuthCodeScope($authCodeId, $scopeId) - { - $this->db->insert('oauth_session_authcode_scopes', array( - 'oauth_session_authcode_id' => $authCodeId, - 'scope_id' => $scopeId, - )); - } - - public function getAuthCodeScopes($oauthSessionAuthCodeId) - { - $stmt = $this->db->prepare('SELECT scope_id FROM `oauth_session_authcode_scopes` WHERE oauth_session_authcode_id = :authCodeId'); - $stmt->bindValue(':authCodeId', $oauthSessionAuthCodeId); - $stmt->execute(); - - return $stmt->fetchAll(); - } - - public function associateScope($accessTokenId, $scopeId) - { - $this->db->insert('oauth_session_token_scopes', array( - 'session_access_token_id' => $accessTokenId, - 'scope_id' => $scopeId, - )); - } - - public function getScopes($accessToken) - { - $stmt = $this->db->prepare('SELECT oauth_scopes.* FROM oauth_session_token_scopes JOIN oauth_session_access_tokens ON oauth_session_access_tokens.`id` = `oauth_session_token_scopes`.`session_access_token_id` JOIN oauth_scopes ON oauth_scopes.id = `oauth_session_token_scopes`.`scope_id` WHERE access_token = :accessToken'); - $stmt->bindValue(':accessToken', $accessToken); - $stmt->execute(); - - return $stmt->fetchAll(); - } -} \ No newline at end of file diff --git a/src/League/OAuth2/Server/Storage/Fluent/Client.php b/src/League/OAuth2/Server/Storage/Fluent/Client.php deleted file mode 100644 index 4a26a513..00000000 --- a/src/League/OAuth2/Server/Storage/Fluent/Client.php +++ /dev/null @@ -1,51 +0,0 @@ -join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id') - ->where('oauth_clients.id', $clientId) - ->where('oauth_client_endpoints.redirect_uri', $redirectUri) - ->first(); - - } elseif (!is_null($clientSecret) && is_null($redirectUri)) { - $result = DB::table('oauth_clients') - ->where('id', $clientId) - ->where('secret', $clientSecret) - ->first(); - - } elseif (!is_null($clientSecret) && !is_null($redirectUri)) { - $queries = DB::getQueryLog(); - - $result = DB::table('oauth_clients') - ->join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id') - ->where('oauth_clients.id', $clientId) - ->where('oauth_clients.secret', $clientSecret) - ->where('oauth_client_endpoints.redirect_uri', $redirectUri) - ->first(); - - } - - if (is_null($result)) { - return false; - } - - return array( - 'client_id' => $result->id, - 'client_secret' => $result->secret, - 'redirect_uri' => (isset($result->redirect_uri)) ? $result->redirect_uri : null, - 'name' => $result->name, - 'auto_approve' => $result->auto_approve - ); - } - -} diff --git a/src/League/OAuth2/Server/Storage/Fluent/Scope.php b/src/League/OAuth2/Server/Storage/Fluent/Scope.php deleted file mode 100644 index 636a59df..00000000 --- a/src/League/OAuth2/Server/Storage/Fluent/Scope.php +++ /dev/null @@ -1,27 +0,0 @@ -where('scope', $scope) - ->first(); - - if (is_null($result)) { - return false; - } - - return array( - 'id' => $result->id, - 'scope' => $result->scope, - 'name' => $result->name, - 'description' => $result->description - ); - } - -} \ No newline at end of file diff --git a/src/League/OAuth2/Server/Storage/Fluent/Session.php b/src/League/OAuth2/Server/Storage/Fluent/Session.php deleted file mode 100644 index 5625ebb1..00000000 --- a/src/League/OAuth2/Server/Storage/Fluent/Session.php +++ /dev/null @@ -1,154 +0,0 @@ -insertGetId([ - 'client_id' => $clientId, - 'owner_type' => $ownerType, - 'owner_id' => $ownerId - ]); - } - - public function deleteSession($clientId, $ownerType, $ownerId) { - DB::table('oauth_sessions') - ->where('client_id', $clientId) - ->where('owner_type', $ownerType) - ->where('owner_id', $ownerId) - ->delete(); - } - - public function associateRedirectUri($sessionId, $redirectUri) { - DB::table('oauth_session_redirects')->insert([ - 'session_id' => $sessionId, - 'redirect_uri' => $redirectUri, - ]); - } - - public function associateAccessToken($sessionId, $accessToken, $expireTime) { - return DB::table('oauth_session_access_tokens')->insertGetId([ - 'session_id' => $sessionId, - 'access_token' => $accessToken, - 'access_token_expires' => $expireTime, - ]); - } - - public function associateRefreshToken($accessTokenId, $refreshToken, $expireTime, $clientId) { - DB::table('oauth_session_refresh_tokens')->insert([ - 'session_access_token_id' => $accessTokenId, - 'refresh_token' => $refreshToken, - 'refresh_token_expires' => $expireTime, - 'client_id' => $clientId, - ]); - } - - public function associateAuthCode($sessionId, $authCode, $expireTime) { - - - DB::table('oauth_session_authcodes')->insert([ - 'session_id' => $sessionId, - 'auth_code' => $authCode, - 'auth_code_expires' => $expireTime - ]); - - return DB::table('oauth_session_authcodes')->where('auth_code',$authCode)->first()->id; - - } - - public function removeAuthCode($sessionId) { - DB::table('oauth_session_authcodes') - ->where('session_id', $sessionId) - ->delete(); - } - - public function validateAuthCode($clientId, $redirectUri, $authCode) { - $result = DB::table('oauth_sessions') - ->select(['oauth_sessions.id as session_id', 'oauth_session_authcodes.id as authcode_id']) - ->join('oauth_session_authcodes', 'oauth_sessions.id', '=', 'oauth_session_authcodes.session_id') - ->join('oauth_session_redirects', 'oauth_sessions.id', '=', 'oauth_session_redirects.session_id') - ->where('oauth_sessions.client_id', $clientId) - ->where('oauth_session_authcodes.auth_code', $authCode) - ->where('oauth_session_authcodes.auth_code_expires', '>=', time()) - ->where('oauth_session_redirects.redirect_uri', $redirectUri) - ->first(); - - return (is_null($result)) ? false : (array) $result; - } - - public function validateAccessToken($accessToken) { - $result = DB::table('oauth_session_access_tokens') - ->join('oauth_sessions', 'oauth_session_access_tokens.session_id', '=', 'oauth_sessions.id') - ->where('access_token', $accessToken) - ->where('access_token_expires', '>=', time()) - ->first(); - - return (is_null($result)) ? false : (array) $result; - } - - public function validateRefreshToken($refreshToken, $clientId) { - $result = DB::table('oauth_session_refresh_tokens') - ->where('refresh_token', $refreshToken) - ->where('client_id', $clientId) - ->where('refresh_token_expires', '>=', time()) - ->first(); - - return (is_null($result)) ? false : $result->session_access_token_id; - } - - public function getAccessToken($accessTokenId) { - $result = DB::table('oauth_session_access_tokens') - ->where('id', $accessTokenId) - ->first(); - - return (is_null($result)) ? false : (array) $result; - } - - public function associateScope($accessTokenId, $scopeId) { - - - - DB::table('oauth_session_token_scopes')->insert([ - 'session_access_token_id' => $accessTokenId, - 'scope_id' => $scopeId, - ]); - } - - public function getScopes($accessToken) { - return DB::table('oauth_session_token_scopes') - ->join('oauth_session_access_tokens', 'oauth_session_token_scopes.session_access_token_id', '=', 'oauth_session_access_tokens.id') - ->join('oauth_scopes', 'oauth_session_token_scopes.session_access_token_id', '=', 'oauth_scopes.id') - ->where('access_token', $accessToken) - ->get(); - } - - public function associateAuthCodeScope($authCodeId, $scopeId) { - - DB::table('oauth_session_authcode_scopes')->insert([ - 'oauth_session_authcode_id' => $authCodeId, - 'scope_id' => $scopeId - ]); - } - - public function getAuthCodeScopes($oauthSessionAuthCodeId) { - $result = DB::table('oauth_session_authcode_scopes') - ->where('oauth_session_authcode_id', '=', $oauthSessionAuthCodeId) - ->get(); - - return array_map(function($val) - { - return json_decode(json_encode($val), true); - }, $result); - } - - public function removeRefreshToken($refreshToken) { - DB::table('oauth_session_refresh_tokens') - ->where('refresh_token', '=', $refreshToken) - ->delete(); - } - -} \ No newline at end of file diff --git a/src/League/OAuth2/Server/Storage/PDO/Client.php b/src/League/OAuth2/Server/Storage/PDO/Client.php deleted file mode 100644 index d56a540f..00000000 --- a/src/League/OAuth2/Server/Storage/PDO/Client.php +++ /dev/null @@ -1,46 +0,0 @@ -prepare('SELECT oauth_clients.id, oauth_clients.secret, oauth_client_endpoints.redirect_uri, oauth_clients.name, oauth_clients.auto_approve FROM oauth_clients LEFT JOIN oauth_client_endpoints ON oauth_client_endpoints.client_id = oauth_clients.id WHERE oauth_clients.id = :clientId AND oauth_client_endpoints.redirect_uri = :redirectUri'); - $stmt->bindValue(':redirectUri', $redirectUri); - } - - elseif ( ! is_null($clientSecret) && is_null($redirectUri)) { - $stmt = $db->prepare('SELECT oauth_clients.id, oauth_clients.secret, oauth_clients.name, oauth_clients.auto_approve FROM oauth_clients WHERE oauth_clients.id = :clientId AND oauth_clients.secret = :clientSecret'); - $stmt->bindValue(':clientSecret', $clientSecret); - } - - elseif ( ! is_null($clientSecret) && ! is_null($redirectUri)) { - $stmt = $db->prepare('SELECT oauth_clients.id, oauth_clients.secret, oauth_client_endpoints.redirect_uri, oauth_clients.name, oauth_clients.auto_approve FROM oauth_clients LEFT JOIN oauth_client_endpoints ON oauth_client_endpoints.client_id = oauth_clients.id WHERE oauth_clients.id = :clientId AND oauth_clients.secret = :clientSecret AND oauth_client_endpoints.redirect_uri = :redirectUri'); - $stmt->bindValue(':redirectUri', $redirectUri); - $stmt->bindValue(':clientSecret', $clientSecret); - } - - $stmt->bindValue(':clientId', $clientId); - $stmt->execute(); - - $row = $stmt->fetchObject(); - - if ($row === false) { - return false; - } - - return array( - 'client_id' => $row->id, - 'client_secret' => $row->secret, - 'redirect_uri' => (isset($row->redirect_uri)) ? $row->redirect_uri : null, - 'name' => $row->name, - 'auto_approve' => $row->auto_approve - ); - } -} diff --git a/src/League/OAuth2/Server/Storage/PDO/Db.php b/src/League/OAuth2/Server/Storage/PDO/Db.php deleted file mode 100644 index 5922df19..00000000 --- a/src/League/OAuth2/Server/Storage/PDO/Db.php +++ /dev/null @@ -1,17 +0,0 @@ -prepare('SELECT * FROM oauth_scopes WHERE oauth_scopes.scope = :scope'); - $stmt->bindValue(':scope', $scope); - $stmt->execute(); - - $row = $stmt->fetchObject(); - - if ($row === false) { - return false; - } - - return array( - 'id' => $row->id, - 'scope' => $row->scope, - 'name' => $row->name, - 'description' => $row->description - ); - - } -} \ No newline at end of file diff --git a/src/League/OAuth2/Server/Storage/PDO/Session.php b/src/League/OAuth2/Server/Storage/PDO/Session.php deleted file mode 100644 index abde8b2b..00000000 --- a/src/League/OAuth2/Server/Storage/PDO/Session.php +++ /dev/null @@ -1,206 +0,0 @@ -prepare('INSERT INTO oauth_sessions (client_id, owner_type, owner_id) VALUE - (:clientId, :ownerType, :ownerId)'); - $stmt->bindValue(':clientId', $clientId); - $stmt->bindValue(':ownerType', $ownerType); - $stmt->bindValue(':ownerId', $ownerId); - $stmt->execute(); - - return $db->lastInsertId(); - } - - public function deleteSession($clientId, $ownerType, $ownerId) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('DELETE FROM oauth_sessions WHERE client_id = :clientId AND - owner_type = :type AND owner_id = :typeId'); - $stmt->bindValue(':clientId', $clientId); - $stmt->bindValue(':type', $ownerType); - $stmt->bindValue(':typeId', $ownerId); - $stmt->execute(); - } - - public function associateRedirectUri($sessionId, $redirectUri) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('INSERT INTO oauth_session_redirects (session_id, redirect_uri) - VALUE (:sessionId, :redirectUri)'); - $stmt->bindValue(':sessionId', $sessionId); - $stmt->bindValue(':redirectUri', $redirectUri); - $stmt->execute(); - } - - public function associateAccessToken($sessionId, $accessToken, $expireTime) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('INSERT INTO oauth_session_access_tokens (session_id, access_token, access_token_expires) - VALUE (:sessionId, :accessToken, :accessTokenExpire)'); - $stmt->bindValue(':sessionId', $sessionId); - $stmt->bindValue(':accessToken', $accessToken); - $stmt->bindValue(':accessTokenExpire', $expireTime); - $stmt->execute(); - - return $db->lastInsertId(); - } - - public function associateRefreshToken($accessTokenId, $refreshToken, $expireTime, $clientId) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('INSERT INTO oauth_session_refresh_tokens (session_access_token_id, refresh_token, refresh_token_expires, client_id) VALUE - (:accessTokenId, :refreshToken, :expireTime, :clientId)'); - $stmt->bindValue(':accessTokenId', $accessTokenId); - $stmt->bindValue(':refreshToken', $refreshToken); - $stmt->bindValue(':expireTime', $expireTime); - $stmt->bindValue(':clientId', $clientId); - $stmt->execute(); - } - - public function associateAuthCode($sessionId, $authCode, $expireTime) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('INSERT INTO oauth_session_authcodes (session_id, auth_code, auth_code_expires) - VALUE (:sessionId, :authCode, :authCodeExpires)'); - $stmt->bindValue(':sessionId', $sessionId); - $stmt->bindValue(':authCode', $authCode); - $stmt->bindValue(':authCodeExpires', $expireTime); - $stmt->execute(); - - return $db->lastInsertId(); - } - - public function removeAuthCode($sessionId) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('DELETE FROM oauth_session_authcodes WHERE session_id = :sessionId'); - $stmt->bindValue(':sessionId', $sessionId); - $stmt->execute(); - } - - public function validateAuthCode($clientId, $redirectUri, $authCode) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('SELECT oauth_sessions.id AS session_id, oauth_session_authcodes.id AS authcode_id - FROM oauth_sessions JOIN oauth_session_authcodes ON oauth_session_authcodes.`session_id` - = oauth_sessions.id JOIN oauth_session_redirects ON oauth_session_redirects.`session_id` - = oauth_sessions.id WHERE oauth_sessions.client_id = :clientId AND oauth_session_authcodes.`auth_code` - = :authCode AND `oauth_session_authcodes`.`auth_code_expires` >= :time AND - `oauth_session_redirects`.`redirect_uri` = :redirectUri'); - $stmt->bindValue(':clientId', $clientId); - $stmt->bindValue(':redirectUri', $redirectUri); - $stmt->bindValue(':authCode', $authCode); - $stmt->bindValue(':time', time()); - $stmt->execute(); - - $result = $stmt->fetchObject(); - - return ($result === false) ? false : (array) $result; - } - - public function validateAccessToken($accessToken) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('SELECT session_id, oauth_sessions.`client_id`, oauth_sessions.`owner_id`, oauth_sessions.`owner_type` FROM `oauth_session_access_tokens` JOIN oauth_sessions ON oauth_sessions.`id` = session_id WHERE access_token = :accessToken AND access_token_expires >= ' . time()); - $stmt->bindValue(':accessToken', $accessToken); - $stmt->execute(); - - $result = $stmt->fetchObject(); - return ($result === false) ? false : (array) $result; - } - - public function removeRefreshToken($refreshToken) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('DELETE FROM `oauth_session_refresh_tokens` WHERE refresh_token = :refreshToken'); - $stmt->bindValue(':refreshToken', $refreshToken); - $stmt->execute(); - } - - public function validateRefreshToken($refreshToken, $clientId) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('SELECT session_access_token_id FROM `oauth_session_refresh_tokens` WHERE - refresh_token = :refreshToken AND client_id = :clientId AND refresh_token_expires >= ' . time()); - $stmt->bindValue(':refreshToken', $refreshToken); - $stmt->bindValue(':clientId', $clientId); - $stmt->execute(); - - $result = $stmt->fetchObject(); - return ($result === false) ? false : $result->session_access_token_id; - } - - public function getAccessToken($accessTokenId) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('SELECT * FROM `oauth_session_access_tokens` WHERE `id` = :accessTokenId'); - $stmt->bindValue(':accessTokenId', $accessTokenId); - $stmt->execute(); - - $result = $stmt->fetchObject(); - return ($result === false) ? false : (array) $result; - } - - public function associateAuthCodeScope($authCodeId, $scopeId) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('INSERT INTO `oauth_session_authcode_scopes` (`oauth_session_authcode_id`, `scope_id`) VALUES (:authCodeId, :scopeId)'); - $stmt->bindValue(':authCodeId', $authCodeId); - $stmt->bindValue(':scopeId', $scopeId); - $stmt->execute(); - } - - public function getAuthCodeScopes($oauthSessionAuthCodeId) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('SELECT scope_id FROM `oauth_session_authcode_scopes` WHERE oauth_session_authcode_id = :authCodeId'); - $stmt->bindValue(':authCodeId', $oauthSessionAuthCodeId); - $stmt->execute(); - - return $stmt->fetchAll(); - } - - public function associateScope($accessTokenId, $scopeId) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('INSERT INTO `oauth_session_token_scopes` (`session_access_token_id`, `scope_id`) - VALUE (:accessTokenId, :scopeId)'); - $stmt->bindValue(':accessTokenId', $accessTokenId); - $stmt->bindValue(':scopeId', $scopeId); - $stmt->execute(); - } - - public function getScopes($accessToken) - { - $db = \ezcDbInstance::get(); - - $stmt = $db->prepare('SELECT oauth_scopes.* FROM oauth_session_token_scopes JOIN oauth_session_access_tokens ON oauth_session_access_tokens.`id` = `oauth_session_token_scopes`.`session_access_token_id` JOIN oauth_scopes ON oauth_scopes.id = `oauth_session_token_scopes`.`scope_id` WHERE access_token = :accessToken'); - $stmt->bindValue(':accessToken', $accessToken); - $stmt->execute(); - - return $stmt->fetchAll(); - } -} \ No newline at end of file