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

Clean integration of CouchDB #524

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Controller/AuthorizeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect, you don't typehint against a debug version.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally don't understand why the initial version is not working and your comment. I just change this following error message, but I'm really not an expert.

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Router;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
Expand Down Expand Up @@ -101,7 +101,7 @@ class AuthorizeController implements ContainerAwareInterface
private $templateEngineType;

/**
* @var EventDispatcher
* @var TraceableEventDispatcher
*/
private $eventDispatcher;

Expand All @@ -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,
Expand All @@ -133,7 +133,7 @@ public function __construct(
TokenStorageInterface $tokenStorage,
Router $router,
ClientManagerInterface $clientManager,
EventDispatcher $eventDispatcher,
TraceableEventDispatcher $eventDispatcher,
$templateEngineType = 'twig'
) {
$this->requestStack = $requestStack;
Expand Down
20 changes: 20 additions & 0 deletions CouchDocument/AccessToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/*
* 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move MongoDB to make way for CouchDB? This way, one of them seems "more important".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Apache CouchDB can have real advantage. For my project, I use it for scalability, and master-master replication capability. But, like you said, library are not up-to-date, I try to make some PR to keep these libraries usable with Symfony 3.X but they are not ready for 4

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant, should we move the MongoDB models to say FOS\Document\MongoDB to make room for other ODM implementations?


use FOS\OAuthServerBundle\Model\AccessToken as BaseAccessToken;

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

declare(strict_types=1);

/*
* 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
{
}
23 changes: 23 additions & 0 deletions CouchDocument/AuthCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

/*
* 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 <[email protected]>
*/
class AuthCode extends BaseAuthCode
{
}
86 changes: 86 additions & 0 deletions CouchDocument/AuthCodeManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

/*
* 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()
{
return null;
}
}
20 changes: 20 additions & 0 deletions CouchDocument/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/*
* 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
{
}
86 changes: 86 additions & 0 deletions CouchDocument/ClientManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

/*
* 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\ClientInterface;
use FOS\OAuthServerBundle\Model\ClientManager as BaseClientManager;

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();
}
}
20 changes: 20 additions & 0 deletions CouchDocument/RefreshToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/*
* 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
{
}
20 changes: 20 additions & 0 deletions CouchDocument/RefreshTokenManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/*
* 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
{
}
Loading