Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic couchdb support #397

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions CouchDocument/AccessToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use FOS\OAuthServerBundle\Model\AccessToken as BaseAccessToken;

class AccessToken extends BaseAccessToken
{
}
18 changes: 18 additions & 0 deletions CouchDocument/AccessTokenManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use FOS\OAuthServerBundle\Model\AccessTokenManagerInterface;

class AccessTokenManager extends TokenManager implements AccessTokenManagerInterface
{
}
21 changes: 21 additions & 0 deletions CouchDocument/AuthCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use FOS\OAuthServerBundle\Model\AuthCode as BaseAuthCode;

/**
* @author Richard Fullmer <richard.fullmer@opensoftdev.com>
*/
class AuthCode extends BaseAuthCode
{
}
92 changes: 92 additions & 0 deletions CouchDocument/AuthCodeManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use Doctrine\ODM\CouchDB\DocumentManager;
use Doctrine\ODM\CouchDB\DocumentRepository;
use FOS\OAuthServerBundle\Model\AuthCodeInterface;
use FOS\OAuthServerBundle\Model\AuthCodeManager as BaseAuthCodeManager;

class AuthCodeManager extends BaseAuthCodeManager
{
/**
* @var DocumentManager
*/
protected $dm;

/**
* @var DocumentRepository
*/
protected $repository;

/**
* @var string
*/
protected $class;

public function __construct(DocumentManager $dm, $class)
{
$this->dm = $dm;
$this->repository = $dm->getRepository($class);
$this->class = $class;
}

/**
* {@inheritdoc}
*/
public function getClass()
{
return $this->class;
}

/**
* {@inheritdoc}
*/
public function findAuthCodeBy(array $criteria)
{
return $this->repository->findOneBy($criteria);
}

/**
* {@inheritdoc}
*/
public function updateAuthCode(AuthCodeInterface $authCode)
{
$this->dm->persist($authCode);
$this->dm->flush();
}

/**
* {@inheritdoc}
*/
public function deleteAuthCode(AuthCodeInterface $authCode)
{
$this->dm->remove($authCode);
$this->dm->flush();
}

/**
* {@inheritdoc}
*/
public function deleteExpired()
{
$result = $this
->repository
->createQueryBuilder()
->remove()
->field('expiresAt')->lt(time())
->getQuery(array('safe' => true))
->execute();

return $result['n'];
}
}
18 changes: 18 additions & 0 deletions CouchDocument/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use FOS\OAuthServerBundle\Model\Client as BaseClient;

class Client extends BaseClient
{
}
82 changes: 82 additions & 0 deletions CouchDocument/ClientManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use Doctrine\ODM\CouchDB\DocumentManager;
use Doctrine\ODM\CouchDB\DocumentRepository;
use FOS\OAuthServerBundle\Model\ClientManager as BaseClientManager;
use FOS\OAuthServerBundle\Model\ClientInterface;

class ClientManager extends BaseClientManager
{
/**
* @var DocumentManager
*/
protected $dm;

/**
* @var DocumentRepository
*/
protected $repository;

/**
* @var string
*/
protected $class;

public function __construct(DocumentManager $dm, $class)
{
$this->dm = $dm;
$this->repository = $dm->getRepository($class);
$this->class = $class;
}

/**
* {@inheritdoc}
*/
public function getClass()
{
return $this->class;
}

/**
* {@inheritdoc}
*/
public function findClientBy(array $criteria)
{
$client = $this->repository->findOneBy(array("randomId"=>$criteria["randomId"]));

if ($client != null)
if ($client->getId() == $criteria["id"])
return $client;

return null;
}

/**
* {@inheritdoc}
*/
public function updateClient(ClientInterface $client)
{
$this->dm->persist($client);
$this->dm->flush();
}

/**
* {@inheritdoc}
*/
public function deleteClient(ClientInterface $client)
{
$this->dm->remove($client);
$this->dm->flush();
}
}
18 changes: 18 additions & 0 deletions CouchDocument/RefreshToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use FOS\OAuthServerBundle\Model\RefreshToken as BaseRefreshToken;

class RefreshToken extends BaseRefreshToken
{
}
18 changes: 18 additions & 0 deletions CouchDocument/RefreshTokenManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use FOS\OAuthServerBundle\Model\RefreshTokenManagerInterface;

class RefreshTokenManager extends TokenManager implements RefreshTokenManagerInterface
{
}
90 changes: 90 additions & 0 deletions CouchDocument/TokenManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\OAuthServerBundle\CouchDocument;

use Doctrine\ODM\CouchDB\DocumentManager;
use Doctrine\ODM\CouchDB\DocumentRepository;
use FOS\OAuthServerBundle\Model\TokenInterface;
use FOS\OAuthServerBundle\Model\TokenManager as BaseTokenManager;

class TokenManager extends BaseTokenManager
{
/**
* @var DocumentManager
*/
protected $dm;

/**
* @var DocumentRepository
*/
protected $repository;

/**
* @var string
*/
protected $class;

public function __construct(DocumentManager $dm, $class)
{
$this->dm = $dm;
$this->repository = $dm->getRepository($class);
$this->class = $class;
}

/**
* {@inheritdoc}
*/
public function getClass()
{
return $this->class;
}

/**
* {@inheritdoc}
*/
public function findTokenBy(array $criteria)
{
return $this->repository->findOneBy($criteria);
}

/**
* {@inheritdoc}
*/
public function updateToken(TokenInterface $token)
{
$this->dm->persist($token);
$this->dm->flush();
}

/**
* {@inheritdoc}
*/
public function deleteToken(TokenInterface $token)
{
$this->dm->remove($token);
$this->dm->flush();
}

/**
* {@inheritdoc}
*/
public function deleteExpired()
{
$result = $this->dm->createQuery("symfony", "accesstoken")
->remove()
->field('expiresAt')->lt(time())
->getQuery(array('safe' => true))
->execute();

return $result['n'];
}
}
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getConfigTreeBuilder()
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('fos_oauth_server');

$supportedDrivers = array('orm', 'mongodb', 'propel');
$supportedDrivers = array('orm', 'mongodb', 'propel', 'couchdb');

$rootNode
->children()
Expand Down