mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-16 02:08:56 +05:30
Started PDO storage classes
This commit is contained in:
parent
81d6bcf00a
commit
7bfbe81f61
45
src/OAuth2/Storage/PDO/Client.php
Normal file
45
src/OAuth2/Storage/PDO/Client.php
Normal 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
|
||||
);
|
||||
}
|
||||
}
|
12
src/OAuth2/Storage/PDO/Db.php
Normal file
12
src/OAuth2/Storage/PDO/Db.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace OAuth2\Storage\PDO;
|
||||
|
||||
class Db
|
||||
{
|
||||
public function __construct($dsn = '')
|
||||
{
|
||||
$db = \ezcDbFactory::create($dsn);
|
||||
\ezcDbInstance::set($db);
|
||||
}
|
||||
}
|
31
src/OAuth2/Storage/PDO/Scope.php
Normal file
31
src/OAuth2/Storage/PDO/Scope.php
Normal 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
|
||||
);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user