Started PDO storage classes

This commit is contained in:
Alex Bilbie 2013-04-28 23:57:50 +01:00
parent 81d6bcf00a
commit 7bfbe81f61
3 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,45 @@
<?php
namespace OAuth2\Storage\PDO;
use OAuth2\Storage\ClientInterface;
class Client implements ClientInterface
{
public function getClient($clientId = null, $clientSecret = null, $redirectUri = null, $grantType = null)
{
$db = \ezcDbInstance::get();
if ( ! is_null($redirectUri) && is_null($clientSecret)) {
$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_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
);
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace OAuth2\Storage\PDO;
class Db
{
public function __construct($dsn = '')
{
$db = \ezcDbFactory::create($dsn);
\ezcDbInstance::set($db);
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace OAuth2\Storage\PDO;
use OAuth2\Storage\ScopeInterface;
class Scope implements ScopeInterface
{
public function getScope($scope, $clientId = null, $grantType = null)
{
$db = \ezcDbInstance::get();
$stmt = $db->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
);
}
}