diff --git a/src/OAuth2/Storage/PDO/Client.php b/src/OAuth2/Storage/PDO/Client.php new file mode 100644 index 00000000..a972aa15 --- /dev/null +++ b/src/OAuth2/Storage/PDO/Client.php @@ -0,0 +1,45 @@ +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 = $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 = $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->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 + ); + } +} \ No newline at end of file diff --git a/src/OAuth2/Storage/PDO/Db.php b/src/OAuth2/Storage/PDO/Db.php new file mode 100644 index 00000000..0d47642e --- /dev/null +++ b/src/OAuth2/Storage/PDO/Db.php @@ -0,0 +1,12 @@ +prepare('SELECT * FROM oauth_scopes WHERE oauth_scopes.key = :scope'); + $stmt->bindValue(':scope', $scope); + $stmt->execute(); + + $row = $stmt->fetchObject(); + + if ($row === false) { + return false; + } + + return array( + 'id' => $row->id, + 'scope' => $row->key, + 'name' => $row->name, + 'description' => $row->description + ); + + } +} \ No newline at end of file