From 9438cfb51b99c044189071ee68695c2cf0b9dd43 Mon Sep 17 00:00:00 2001 From: Jimmy GAUBE Date: Thu, 25 Jan 2018 13:14:09 +0100 Subject: [PATCH 1/7] Adding document for couchdb --- Resources/config/doctrine/AccessToken.couchdb.xml | 6 +++--- Resources/config/doctrine/AuthCode.couchdb.xml | 4 ++-- Resources/config/doctrine/Client.couchdb.xml | 4 ++-- Resources/config/doctrine/RefreshToken.couchdb.xml | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Resources/config/doctrine/AccessToken.couchdb.xml b/Resources/config/doctrine/AccessToken.couchdb.xml index ae715578..f85b4b6d 100644 --- a/Resources/config/doctrine/AccessToken.couchdb.xml +++ b/Resources/config/doctrine/AccessToken.couchdb.xml @@ -1,9 +1,9 @@ - - - + + + diff --git a/Resources/config/doctrine/AuthCode.couchdb.xml b/Resources/config/doctrine/AuthCode.couchdb.xml index f9316f08..75e4939e 100644 --- a/Resources/config/doctrine/AuthCode.couchdb.xml +++ b/Resources/config/doctrine/AuthCode.couchdb.xml @@ -1,10 +1,10 @@ - + - + diff --git a/Resources/config/doctrine/Client.couchdb.xml b/Resources/config/doctrine/Client.couchdb.xml index b3968446..665ea722 100644 --- a/Resources/config/doctrine/Client.couchdb.xml +++ b/Resources/config/doctrine/Client.couchdb.xml @@ -1,8 +1,8 @@ - - + + diff --git a/Resources/config/doctrine/RefreshToken.couchdb.xml b/Resources/config/doctrine/RefreshToken.couchdb.xml index e59ba38b..78c38690 100644 --- a/Resources/config/doctrine/RefreshToken.couchdb.xml +++ b/Resources/config/doctrine/RefreshToken.couchdb.xml @@ -1,9 +1,9 @@ - - - + + + From 2e9c06401016ef85c25c5a99a665839ed0403552 Mon Sep 17 00:00:00 2001 From: Jimmy GAUBE Date: Thu, 25 Jan 2018 14:33:16 +0000 Subject: [PATCH 2/7] CouchDB support --- DependencyInjection/Configuration.php | 2 +- DependencyInjection/FOSOAuthServerExtension.php | 14 ++++++++++++++ Resources/config/AccessToken.couchdb.xml | 10 ++++++++++ Resources/config/AuthCode.couchdb.xml | 11 +++++++++++ Resources/config/Client.couchdb.xml | 10 ++++++++++ Resources/config/RefreshToken.couchdb.xml | 10 ++++++++++ Resources/config/couchdb.xml | 3 ++- 7 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 Resources/config/AccessToken.couchdb.xml create mode 100644 Resources/config/AuthCode.couchdb.xml create mode 100644 Resources/config/Client.couchdb.xml create mode 100644 Resources/config/RefreshToken.couchdb.xml diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index b715653f..d9ea2a10 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -34,7 +34,7 @@ public function getConfigTreeBuilder() /** @var ArrayNodeDefinition $rootNode */ $rootNode = $treeBuilder->root('fos_oauth_server'); - $supportedDrivers = ['orm', 'mongodb', 'propel']; + $supportedDrivers = ['orm', 'mongodb', 'propel', 'couchdb']; $rootNode ->children() diff --git a/DependencyInjection/FOSOAuthServerExtension.php b/DependencyInjection/FOSOAuthServerExtension.php index f9aeab42..78a950fd 100644 --- a/DependencyInjection/FOSOAuthServerExtension.php +++ b/DependencyInjection/FOSOAuthServerExtension.php @@ -78,6 +78,20 @@ public function load(array $configs, ContainerBuilder $container) } } + // Handle the MongoDB document manager name in a specific way as it does not have a registry to make it easy + // TODO: change it when bumping the requirement to Symfony 2.1 + if ('couchdb' === $config['db_driver']) { + if (null === $config['model_manager_name']) { + $container->setAlias('fos_oauth_server.document_manager', new Alias('doctrine_couchdb.odm.default_document_manager', false)); + } else { + $container->setAlias('fos_oauth_server.document_manager', new Alias( + sprintf('doctrine.odm.%s_couchdb.document_manager', + $config['model_manager_name']), + false + )); + } + } + // Entity manager factory definition // TODO: Go back to xml configuration when bumping the requirement to Symfony >=2.6 if ('orm' === $config['db_driver']) { diff --git a/Resources/config/AccessToken.couchdb.xml b/Resources/config/AccessToken.couchdb.xml new file mode 100644 index 00000000..f85b4b6d --- /dev/null +++ b/Resources/config/AccessToken.couchdb.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Resources/config/AuthCode.couchdb.xml b/Resources/config/AuthCode.couchdb.xml new file mode 100644 index 00000000..75e4939e --- /dev/null +++ b/Resources/config/AuthCode.couchdb.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Resources/config/Client.couchdb.xml b/Resources/config/Client.couchdb.xml new file mode 100644 index 00000000..665ea722 --- /dev/null +++ b/Resources/config/Client.couchdb.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Resources/config/RefreshToken.couchdb.xml b/Resources/config/RefreshToken.couchdb.xml new file mode 100644 index 00000000..78c38690 --- /dev/null +++ b/Resources/config/RefreshToken.couchdb.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Resources/config/couchdb.xml b/Resources/config/couchdb.xml index 15df13c5..18324160 100644 --- a/Resources/config/couchdb.xml +++ b/Resources/config/couchdb.xml @@ -25,7 +25,8 @@ %fos_oauth_server.model.refresh_token.class% - + + %fos_oauth_server.model_manager_name% From 8261b6a779bd41ad0f5cbee36cd36d6805184ad3 Mon Sep 17 00:00:00 2001 From: Jimmy GAUBE Date: Thu, 25 Jan 2018 15:14:39 +0000 Subject: [PATCH 3/7] Adding couchdbdocument and replace couchdb.xml files --- CouchDocument/AccessToken.php | 18 +++++ CouchDocument/AccessTokenManager.php | 18 +++++ CouchDocument/AuthCode.php | 21 ++++++ CouchDocument/AuthCodeManager.php | 92 +++++++++++++++++++++++ CouchDocument/Client.php | 18 +++++ CouchDocument/ClientManager.php | 82 ++++++++++++++++++++ CouchDocument/RefreshToken.php | 18 +++++ CouchDocument/RefreshTokenManager.php | 18 +++++ CouchDocument/TokenManager.php | 90 ++++++++++++++++++++++ Resources/config/AccessToken.couchdb.xml | 10 --- Resources/config/AuthCode.couchdb.xml | 11 --- Resources/config/Client.couchdb.xml | 10 --- Resources/config/RefreshToken.couchdb.xml | 10 --- 13 files changed, 375 insertions(+), 41 deletions(-) create mode 100644 CouchDocument/AccessToken.php create mode 100644 CouchDocument/AccessTokenManager.php create mode 100644 CouchDocument/AuthCode.php create mode 100644 CouchDocument/AuthCodeManager.php create mode 100644 CouchDocument/Client.php create mode 100644 CouchDocument/ClientManager.php create mode 100644 CouchDocument/RefreshToken.php create mode 100644 CouchDocument/RefreshTokenManager.php create mode 100644 CouchDocument/TokenManager.php delete mode 100644 Resources/config/AccessToken.couchdb.xml delete mode 100644 Resources/config/AuthCode.couchdb.xml delete mode 100644 Resources/config/Client.couchdb.xml delete mode 100644 Resources/config/RefreshToken.couchdb.xml diff --git a/CouchDocument/AccessToken.php b/CouchDocument/AccessToken.php new file mode 100644 index 00000000..0ccdbc19 --- /dev/null +++ b/CouchDocument/AccessToken.php @@ -0,0 +1,18 @@ + + * + * 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 +{ +} diff --git a/CouchDocument/AccessTokenManager.php b/CouchDocument/AccessTokenManager.php new file mode 100644 index 00000000..e827df45 --- /dev/null +++ b/CouchDocument/AccessTokenManager.php @@ -0,0 +1,18 @@ + + * + * 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 +{ +} diff --git a/CouchDocument/AuthCode.php b/CouchDocument/AuthCode.php new file mode 100644 index 00000000..bf4be3dc --- /dev/null +++ b/CouchDocument/AuthCode.php @@ -0,0 +1,21 @@ + + * + * 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 + */ +class AuthCode extends BaseAuthCode +{ +} diff --git a/CouchDocument/AuthCodeManager.php b/CouchDocument/AuthCodeManager.php new file mode 100644 index 00000000..e576fb4e --- /dev/null +++ b/CouchDocument/AuthCodeManager.php @@ -0,0 +1,92 @@ + + * + * 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']; + } +} diff --git a/CouchDocument/Client.php b/CouchDocument/Client.php new file mode 100644 index 00000000..c9c6b6d8 --- /dev/null +++ b/CouchDocument/Client.php @@ -0,0 +1,18 @@ + + * + * 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 +{ +} diff --git a/CouchDocument/ClientManager.php b/CouchDocument/ClientManager.php new file mode 100644 index 00000000..042cf2d1 --- /dev/null +++ b/CouchDocument/ClientManager.php @@ -0,0 +1,82 @@ + + * + * 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(); + } +} diff --git a/CouchDocument/RefreshToken.php b/CouchDocument/RefreshToken.php new file mode 100644 index 00000000..304ca1ef --- /dev/null +++ b/CouchDocument/RefreshToken.php @@ -0,0 +1,18 @@ + + * + * 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 +{ +} diff --git a/CouchDocument/RefreshTokenManager.php b/CouchDocument/RefreshTokenManager.php new file mode 100644 index 00000000..47f0e422 --- /dev/null +++ b/CouchDocument/RefreshTokenManager.php @@ -0,0 +1,18 @@ + + * + * 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 +{ +} diff --git a/CouchDocument/TokenManager.php b/CouchDocument/TokenManager.php new file mode 100644 index 00000000..81c13a79 --- /dev/null +++ b/CouchDocument/TokenManager.php @@ -0,0 +1,90 @@ + + * + * 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']; + } +} diff --git a/Resources/config/AccessToken.couchdb.xml b/Resources/config/AccessToken.couchdb.xml deleted file mode 100644 index f85b4b6d..00000000 --- a/Resources/config/AccessToken.couchdb.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/Resources/config/AuthCode.couchdb.xml b/Resources/config/AuthCode.couchdb.xml deleted file mode 100644 index 75e4939e..00000000 --- a/Resources/config/AuthCode.couchdb.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/Resources/config/Client.couchdb.xml b/Resources/config/Client.couchdb.xml deleted file mode 100644 index 665ea722..00000000 --- a/Resources/config/Client.couchdb.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/Resources/config/RefreshToken.couchdb.xml b/Resources/config/RefreshToken.couchdb.xml deleted file mode 100644 index 78c38690..00000000 --- a/Resources/config/RefreshToken.couchdb.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - From 214452f61ca1f0c2a212dbf6e9ac03f2cc194d2b Mon Sep 17 00:00:00 2001 From: Jimmy GAUBE Date: Thu, 25 Jan 2018 17:40:18 +0000 Subject: [PATCH 4/7] Fixing syntax for CI --- CouchDocument/AccessToken.php | 38 +++--- CouchDocument/AccessTokenManager.php | 38 +++--- CouchDocument/AuthCode.php | 44 +++--- CouchDocument/AuthCodeManager.php | 187 +++++++++++++------------- CouchDocument/Client.php | 38 +++--- CouchDocument/ClientManager.php | 168 ++++++++++++----------- CouchDocument/RefreshToken.php | 38 +++--- CouchDocument/RefreshTokenManager.php | 38 +++--- CouchDocument/TokenManager.php | 183 ++++++++++++------------- 9 files changed, 397 insertions(+), 375 deletions(-) diff --git a/CouchDocument/AccessToken.php b/CouchDocument/AccessToken.php index 0ccdbc19..1bf31e60 100644 --- a/CouchDocument/AccessToken.php +++ b/CouchDocument/AccessToken.php @@ -1,18 +1,20 @@ - - * - * 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 -{ -} + + * + * 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 +{ +} diff --git a/CouchDocument/AccessTokenManager.php b/CouchDocument/AccessTokenManager.php index e827df45..d1a2a3a4 100644 --- a/CouchDocument/AccessTokenManager.php +++ b/CouchDocument/AccessTokenManager.php @@ -1,18 +1,20 @@ - - * - * 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 -{ -} + + * + * 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 +{ +} diff --git a/CouchDocument/AuthCode.php b/CouchDocument/AuthCode.php index bf4be3dc..f218973a 100644 --- a/CouchDocument/AuthCode.php +++ b/CouchDocument/AuthCode.php @@ -1,21 +1,23 @@ - - * - * 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 - */ -class AuthCode extends BaseAuthCode -{ -} + + * + * 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 + */ +class AuthCode extends BaseAuthCode +{ +} diff --git a/CouchDocument/AuthCodeManager.php b/CouchDocument/AuthCodeManager.php index e576fb4e..0e386143 100644 --- a/CouchDocument/AuthCodeManager.php +++ b/CouchDocument/AuthCodeManager.php @@ -1,92 +1,95 @@ - - * - * 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']; - } -} + + * + * 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(['safe' => true]) + ->execute() + ; + + return $result['n']; + } +} diff --git a/CouchDocument/Client.php b/CouchDocument/Client.php index c9c6b6d8..ffa3ef26 100644 --- a/CouchDocument/Client.php +++ b/CouchDocument/Client.php @@ -1,18 +1,20 @@ - - * - * 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 -{ -} + + * + * 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 +{ +} diff --git a/CouchDocument/ClientManager.php b/CouchDocument/ClientManager.php index 042cf2d1..e483b645 100644 --- a/CouchDocument/ClientManager.php +++ b/CouchDocument/ClientManager.php @@ -1,82 +1,86 @@ - - * - * 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(); - } -} + + * + * 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(["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(); + } +} diff --git a/CouchDocument/RefreshToken.php b/CouchDocument/RefreshToken.php index 304ca1ef..7ccc6b59 100644 --- a/CouchDocument/RefreshToken.php +++ b/CouchDocument/RefreshToken.php @@ -1,18 +1,20 @@ - - * - * 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 -{ -} + + * + * 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 +{ +} diff --git a/CouchDocument/RefreshTokenManager.php b/CouchDocument/RefreshTokenManager.php index 47f0e422..57277236 100644 --- a/CouchDocument/RefreshTokenManager.php +++ b/CouchDocument/RefreshTokenManager.php @@ -1,18 +1,20 @@ - - * - * 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 -{ -} + + * + * 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 +{ +} diff --git a/CouchDocument/TokenManager.php b/CouchDocument/TokenManager.php index 81c13a79..4f7e53d0 100644 --- a/CouchDocument/TokenManager.php +++ b/CouchDocument/TokenManager.php @@ -1,90 +1,93 @@ - - * - * 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']; - } -} + + * + * 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(['safe' => true]) + ->execute() + ; + + return $result['n']; + } +} From 7fc056dd54186cb2a077c62ad13596f18e634685 Mon Sep 17 00:00:00 2001 From: Jimmy GAUBE Date: Tue, 30 Jan 2018 11:37:51 +0000 Subject: [PATCH 5/7] Fixing errors in syntax, missing clear expired token in couchdb, adding couchdb in dependencies. --- CouchDocument/AuthCodeManager.php | 11 +---------- CouchDocument/ClientManager.php | 16 ++++++++-------- CouchDocument/TokenManager.php | 9 +-------- composer.json | 11 ++++++++++- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/CouchDocument/AuthCodeManager.php b/CouchDocument/AuthCodeManager.php index 0e386143..90d70793 100644 --- a/CouchDocument/AuthCodeManager.php +++ b/CouchDocument/AuthCodeManager.php @@ -81,15 +81,6 @@ public function deleteAuthCode(AuthCodeInterface $authCode) */ public function deleteExpired() { - $result = $this - ->repository - ->createQueryBuilder() - ->remove() - ->field('expiresAt')->lt(time()) - ->getQuery(['safe' => true]) - ->execute() - ; - - return $result['n']; + return null; } } diff --git a/CouchDocument/ClientManager.php b/CouchDocument/ClientManager.php index e483b645..ec436c65 100644 --- a/CouchDocument/ClientManager.php +++ b/CouchDocument/ClientManager.php @@ -15,8 +15,8 @@ use Doctrine\ODM\CouchDB\DocumentManager; use Doctrine\ODM\CouchDB\DocumentRepository; -use FOS\OAuthServerBundle\Model\ClientManager as BaseClientManager; use FOS\OAuthServerBundle\Model\ClientInterface; +use FOS\OAuthServerBundle\Model\ClientManager as BaseClientManager; class ClientManager extends BaseClientManager { @@ -55,15 +55,15 @@ public function getClass() */ public function findClientBy(array $criteria) { - $client = $this->repository->findOneBy(["randomId"=>$criteria["randomId"]]); + $client = $this->repository->findOneBy(['randomId' => $criteria['randomId']]); - if ($client != null) { - if ($client->getId() == $criteria["id"]) { - return $client; - } - } + if ($client !== null) { + if ($client->getId() === $criteria['id']) { + return $client; + } + } - return null; + return null; } /** diff --git a/CouchDocument/TokenManager.php b/CouchDocument/TokenManager.php index 4f7e53d0..fcf852f1 100644 --- a/CouchDocument/TokenManager.php +++ b/CouchDocument/TokenManager.php @@ -81,13 +81,6 @@ public function deleteToken(TokenInterface $token) */ public function deleteExpired() { - $result = $this->dm->createQuery('symfony', 'accesstoken') - ->remove() - ->field('expiresAt')->lt(time()) - ->getQuery(['safe' => true]) - ->execute() - ; - - return $result['n']; + return null; } } diff --git a/composer.json b/composer.json index 0e301726..76e3652f 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ "friendsofsymfony/oauth2-php": "~1.1", "symfony/framework-bundle": "~3.0|^4.0", "symfony/security-bundle": "~3.0|^4.0", - "symfony/dependency-injection": "^2.8|~3.0|^4.0" + "symfony/dependency-injection": "^2.8|~3.0|^4.0", + "alcaeus/mongo-php-adapter": "^1.1" }, "require-dev": { "symfony/class-loader": "~3.0|^4.0", @@ -34,6 +35,9 @@ "doctrine/mongodb-odm": "~1.0", "doctrine/doctrine-bundle": "~1.0", "doctrine/orm": "~2.2", + "doctrine/couchdb": "1.0.x-dev", + "doctrine/couchdb-odm": "dev-master", + "doctrine/couchdb-odm-bundle": "@dev", "phpunit/phpunit": "~4.8|~5.0" }, "suggest": { @@ -52,5 +56,10 @@ "branch-alias": { "dev-master": "2.0-dev" } + }, + "config": { + "platform": { + "ext-mongo": "1.6.16" + } } } From a57222fe6f3edb5e84d10e09c541ff04cd2f11f1 Mon Sep 17 00:00:00 2001 From: Jimmy GAUBE Date: Wed, 31 Jan 2018 21:05:47 +0100 Subject: [PATCH 6/7] Fixing eventdispatcher error on wrong token --- Controller/AuthorizeController.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Controller/AuthorizeController.php b/Controller/AuthorizeController.php index a56a149c..70405a41 100644 --- a/Controller/AuthorizeController.php +++ b/Controller/AuthorizeController.php @@ -22,12 +22,12 @@ use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\Form\Form; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\SessionInterface; +use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Router; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; @@ -101,7 +101,7 @@ class AuthorizeController implements ContainerAwareInterface private $templateEngineType; /** - * @var EventDispatcher + * @var TraceableEventDispatcher */ private $eventDispatcher; @@ -111,17 +111,17 @@ class AuthorizeController implements ContainerAwareInterface * * @todo This controller could be refactored to do not rely on so many dependencies * - * @param RequestStack $requestStack - * @param SessionInterface $session - * @param Form $authorizeForm - * @param AuthorizeFormHandler $authorizeFormHandler - * @param OAuth2 $oAuth2Server - * @param EngineInterface $templating - * @param TokenStorageInterface $tokenStorage - * @param Router $router - * @param ClientManagerInterface $clientManager - * @param EventDispatcher $eventDispatcher - * @param string $templateEngineType + * @param RequestStack $requestStack + * @param SessionInterface $session + * @param Form $authorizeForm + * @param AuthorizeFormHandler $authorizeFormHandler + * @param OAuth2 $oAuth2Server + * @param EngineInterface $templating + * @param TokenStorageInterface $tokenStorage + * @param Router $router + * @param ClientManagerInterface $clientManager + * @param TraceableEventDispatcher $eventDispatcher + * @param string $templateEngineType */ public function __construct( RequestStack $requestStack, @@ -133,7 +133,7 @@ public function __construct( TokenStorageInterface $tokenStorage, Router $router, ClientManagerInterface $clientManager, - EventDispatcher $eventDispatcher, + TraceableEventDispatcher $eventDispatcher, $templateEngineType = 'twig' ) { $this->requestStack = $requestStack; From a9fc0a84f8b463faaa488288107a96e4b4f66f35 Mon Sep 17 00:00:00 2001 From: Jimmy GAUBE Date: Wed, 31 Jan 2018 21:36:36 +0100 Subject: [PATCH 7/7] Removing additionnal content --- composer.json | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 76e3652f..26ecfa67 100644 --- a/composer.json +++ b/composer.json @@ -19,9 +19,7 @@ "php": "^7.1", "friendsofsymfony/oauth2-php": "~1.1", "symfony/framework-bundle": "~3.0|^4.0", - "symfony/security-bundle": "~3.0|^4.0", - "symfony/dependency-injection": "^2.8|~3.0|^4.0", - "alcaeus/mongo-php-adapter": "^1.1" + "symfony/security-bundle": "~3.0|^4.0" }, "require-dev": { "symfony/class-loader": "~3.0|^4.0", @@ -56,10 +54,5 @@ "branch-alias": { "dev-master": "2.0-dev" } - }, - "config": { - "platform": { - "ext-mongo": "1.6.16" - } } }