I did FOSOAuthServer as in documentation https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/blob/master/Resources/doc/index.md
but have exception:
Doctrine\Common\Persistence\Mapping\MappingException:
The class 'OAuthBundle\Entity\Client' was not found in the chain configured namespaces FOS\OAuthServerBundle\Document
at vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\MappingException.php:37
at Doctrine\Common\Persistence\Mapping\MappingException::classNotFoundInNamespaces('OAuthBundle\\Entity\\Client', array('FOS\\OAuthServerBundle\\Document'))
(vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain.php:112)
at Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForClass('OAuthBundle\\Entity\\Client', object(ClassMetadata))
(vendor\doctrine\mongodb-odm\lib\Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory.php:159)
at Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory->doLoadMetadata(object(ClassMetadata), object(ClassMetadata), false, array())
(vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php:333)
at Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata('OAuthBundle\\Entity\\Client')
(vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php:217)
at Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor('OAuthBundle\\Entity\\Client')
(vendor\doctrine\mongodb-odm\lib\Doctrine\ODM\MongoDB\DocumentManager.php:286)
at Doctrine\ODM\MongoDB\DocumentManager->getClassMetadata('OAuthBundle\\Entity\\Client')
(vendor\doctrine\mongodb-odm\lib\Doctrine\ODM\MongoDB\Repository\DefaultRepositoryFactory.php:24)
at Doctrine\ODM\MongoDB\Repository\DefaultRepositoryFactory->getRepository(object(DocumentManager), 'OAuthBundle\\Entity\\Client')
(vendor\doctrine\mongodb-odm\lib\Doctrine\ODM\MongoDB\DocumentManager.php:508)
at Doctrine\ODM\MongoDB\DocumentManager->getRepository('OAuthBundle\\Entity\\Client')
(vendor\friendsofsymfony\oauth-server-bundle\Document\ClientManager.php:39)
at FOS\OAuthServerBundle\Document\ClientManager->__construct(object(DocumentManager), 'OAuthBundle\\Entity\\Client')
(var\cache\dev\appDevDebugProjectContainer.php:1780)
at appDevDebugProjectContainer->getFosOauthServer_ClientManager_DefaultService()
(vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Container.php:335)
at Symfony\Component\DependencyInjection\Container->get('fos_oauth_server.client_manager.default')
(var\cache\dev\appDevDebugProjectContainer.php:1820)
at appDevDebugProjectContainer->getFosOauthServer_StorageService()
(vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Container.php:335)
at Symfony\Component\DependencyInjection\Container->get('fos_oauth_server.storage')
(var\cache\dev\appDevDebugProjectContainer.php:1810)
at appDevDebugProjectContainer->getFosOauthServer_ServerService()
(vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Container.php:335)
at Symfony\Component\DependencyInjection\Container->get('fos_oauth_server.server')
(var\cache\dev\appDevDebugProjectContainer.php:1790)
at appDevDebugProjectContainer->getFosOauthServer_Controller_TokenService()
(vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Container.php:335)
at Symfony\Component\DependencyInjection\Container->get('fos_oauth_server.controller.token')
(vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Controller\ContainerControllerResolver.php:54)
at Symfony\Component\HttpKernel\Controller\ContainerControllerResolver->createController('fos_oauth_server.controller.token:tokenAction')
(vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver.php:52)
at Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver->createController('fos_oauth_server.controller.token:tokenAction')
(vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Controller\ControllerResolver.php:95)
at Symfony\Component\HttpKernel\Controller\ControllerResolver->getController(object(Request))
(vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Controller\TraceableControllerResolver.php:58)
at Symfony\Component\HttpKernel\Controller\TraceableControllerResolver->getController(object(Request))
(vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php:136)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
(vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php:68)
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
(vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php:171)
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
(web\app_dev.php:29)
at require('C:\\www\\symfony\\web\\app_dev.php')
(vendor\symfony\symfony\src\Symfony\Bundle\WebServerBundle\Resources\router.php:42)
My entities placed in /src/OAuthBundle/Entity
Client
namespace OAuthBundle\Entity;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Id;
use FOS\OAuthServerBundle\Document\Client as BaseClient;
/** @Document(collection="oauth_client") */
class Client extends BaseClient
{
/** @Id(strategy="AUTO") */
protected $id;
}
AccessToken
namespace OAuthBundle\Entity;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations\Id;
use Doctrine\ODM\MongoDB\Mapping\Annotations\ReferenceOne;
use FOS\OAuthServerBundle\Document\AccessToken as BaseAccessToken;
use FOS\OAuthServerBundle\Model\ClientInterface;
/**
* @Document(collection="oauth_access_token")
*/
class AccessToken extends BaseAccessToken
{
/**
* @Id(strategy="AUTO")
*/
protected $id;
/**
* @ReferenceOne(targetDocument="OAuthBundle\Entity\Client")
*/
protected $client;
public function getClient()
{
return $this->client;
}
public function setClient(ClientInterface $client)
{
$this->client = $client;
}
}
Other entities RefreshToken and AuthCodelike like this.
Application configuration:
doctrine_mongodb:
connections:
default:
server: "%mongodb_server%"
options: {}
default_database: symfony_test
document_managers:
default:
auto_mapping: true
fos_oauth_server:
db_driver: mongodb
client_class: OAuthBundle\Entity\Client
access_token_class: OAuthBundle\Entity\AccessToken
refresh_token_class: OAuthBundle\Entity\RefreshToken
auth_code_class: OAuthBundle\Entity\AuthCode
My composer.json
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle",
"OAuthBundle\\": "src/OAuthBundle"
},
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
},
console:
$ composer dumpautoload
Generating autoload files
$ ./bin/console cache:clear --env=dev
// Clearing the cache for the dev environment with debug
// true
[OK] Cache for the "dev" environment (debug=true) was successfully cleared.
I do not understand where is problem?
By default, the auto_mapping feature looks for entities under the Entity namespace, so given that your entity (FOS\OAuthServerBundle\Document\XXX) is not there, Doctrine does not know anything about it.
You need to configure entities of FOSOAuthServerBundle
in your doctrine mapping by hand to add your custom entity namespace.
entity_managers:
default:
mappings:
MyBundle:
type: annotation
custom_mapping:
type: annotation
prefix: FOS\OAuthServerBundle\Document\
dir: "%kernel.root_dir%/src/FOS/OAuthServerBundle/Document/"
is_bundle: false