oauth2-server/examples/relational/Storage/ClientStorage.php

71 lines
2.1 KiB
PHP
Raw Normal View History

2014-05-09 15:16:59 +05:30
<?php
namespace RelationalExample\Storage;
2014-11-08 23:56:12 +05:30
use Illuminate\Database\Capsule\Manager as Capsule;
2014-05-09 15:16:59 +05:30
use League\OAuth2\Server\Entity\ClientEntity;
use League\OAuth2\Server\Entity\SessionEntity;
use League\OAuth2\Server\Storage\AbstractStorage;
2014-11-08 23:56:12 +05:30
use League\OAuth2\Server\Storage\ClientInterface;
2014-05-09 15:16:59 +05:30
class ClientStorage extends AbstractStorage implements ClientInterface
2014-05-09 15:16:59 +05:30
{
/**
* {@inheritdoc}
*/
public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null)
{
2014-06-23 12:50:34 +05:30
$query = Capsule::table('oauth_clients')
->select('oauth_clients.*')
->where('oauth_clients.id', $clientId);
if ($clientSecret !== null) {
$query->where('oauth_clients.secret', $clientSecret);
}
if ($redirectUri) {
$query->join('oauth_client_redirect_uris', 'oauth_clients.id', '=', 'oauth_client_redirect_uris.client_id')
->select(['oauth_clients.*', 'oauth_client_redirect_uris.*'])
->where('oauth_client_redirect_uris.redirect_uri', $redirectUri);
}
$result = $query->get();
if (count($result) === 1) {
$client = new ClientEntity($this->server);
2014-07-11 22:57:03 +05:30
$client->hydrate([
'id' => $result[0]['id'],
2014-11-08 23:56:12 +05:30
'name' => $result[0]['name'],
2014-07-11 22:57:03 +05:30
]);
2014-06-23 12:50:34 +05:30
return $client;
}
2014-12-10 18:40:35 +05:30
return;
2014-05-09 15:16:59 +05:30
}
/**
* {@inheritdoc}
*/
public function getBySession(SessionEntity $session)
{
$result = Capsule::table('oauth_clients')
->select(['oauth_clients.id', 'oauth_clients.name'])
->join('oauth_sessions', 'oauth_clients.id', '=', 'oauth_sessions.client_id')
->where('oauth_sessions.id', $session->getId())
->get();
if (count($result) === 1) {
$client = new ClientEntity($this->server);
2014-07-11 22:57:03 +05:30
$client->hydrate([
'id' => $result[0]['id'],
2014-11-08 23:56:12 +05:30
'name' => $result[0]['name'],
2014-07-11 22:57:03 +05:30
]);
2014-05-09 15:16:59 +05:30
return $client;
}
2014-06-23 12:50:34 +05:30
2014-12-10 18:40:35 +05:30
return;
2014-05-09 15:16:59 +05:30
}
}