FOSOAuthServerBundle
FOSOAuthServerBundle copied to clipboard
Error requiring bundle from composer on SF4
Command: composer require friendsofsymfony/oauth-server-bundle:dev-master
Fails with
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 1
!!
!! In ArrayNode.php line 238:
!!
!! The child node "db_driver" at path "fos_oauth_server" must be configured.
!!
!!
!!
Shouldn't the configuration file be created automatically on composer require?
There needs to exist a Flex recipe for the package for it to be auto-configured.
Yes that is what I meant, I think a Flex recipe should be submitted to https://github.com/symfony/recipes at some point, but this is not a blocker, maybe a bit confusing for people new to Flex :)
@SebScoFr how can you solved this problem?
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 1
In ArrayNode.php line 238:
`The child node "db_driver" at path "fos_oauth_server" must be configured.`
@Luitame If you are using SF4, make sure your fos_auth_server.yaml looks something like this (note the db_driver section):
fos_oauth_server:
db_driver: mongodb
client_class: App\Document\Client
access_token_class: App\Document\AccessToken
refresh_token_class: App\Document\RefreshToken
auth_code_class: App\Document\AuthCode
service:
user_provider: App\Provider\UserProvider
If you're still on 3.x that will be within the app/config.yml file under the FOS configuration section
Hey, @SebScoFr let's join forces to create the recipe from Symfony Flex for this package?
@Luitame @SebScoFr @dkarlovi Configuration is fine and solves that problem, but then the next appears:
The service "fos_oauth_server.controller.authorize" has a dependency on a non-existent service "templating"
I'm using SF4, too. Can anyone confirm?
Here is what my composer.json
looks like:
"require": {
"php": "^7.1.3",
"doctrine/doctrine-fixtures-bundle": "^3.0",
"friendsofsymfony/oauth-server-bundle": "1.6.x-dev",
"myclabs/deep-copy": "^1.7",
"sensio/framework-extra-bundle": "^5.1",
"symfony/asset": "^4.0",
"symfony/console": "^4.0",
"symfony/dotenv": "^4.0",
"symfony/expression-language": "^4.0",
"symfony/flex": "^1.0",
"symfony/form": "^4.0",
"symfony/framework-bundle": "^4.0",
"symfony/lts": "^4@dev",
"symfony/monolog-bundle": "^3.1",
"symfony/orm-pack": "^1.0",
"symfony/process": "^4.0",
"symfony/profiler-pack": "^1.0",
"symfony/security-bundle": "^4.0",
"symfony/swiftmailer-bundle": "^3.1",
"symfony/twig-bundle": "^4.0",
"symfony/validator": "^4.0",
"symfony/yaml": "^4.0",
"twig/extensions": "^1.5"
},
"require-dev": {
"escapestudios/symfony2-coding-standard": "^3.0",
"symfony/maker-bundle": "^1.0",
"symfony/phpunit-bridge": "^4.0"
},
@Sengorius same here
My composer.json
:
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"friendsofsymfony/oauth-server-bundle": "dev-master",
"friendsofsymfony/rest-bundle": "^2.3",
"jms/serializer-bundle": "^2.3",
"symfony/console": "^4.0",
"symfony/flex": "^1.0",
"symfony/form": "^4.0",
"symfony/framework-bundle": "^4.0",
"symfony/lts": "^4@dev",
"symfony/orm-pack": "^1.0",
"symfony/security-bundle": "^4.0",
"symfony/templating": "^4.0",
"symfony/yaml": "^4.0"
},
"require-dev": {
"symfony/dotenv": "^4.0"
},
EDIT: I think I found a fix:
- Make sure you have installed twig:
composer require symfony/twig-bundle
- Make sure you have a valid fos_oauth_user.yaml:
fos_oauth_server:
db_driver: orm
client_class: App\Entity\OAuth2\Client
access_token_class: App\Entity\OAuth2\AccessToken
refresh_token_class: App\Entity\OAuth2\RefreshToken
auth_code_class: App\Entity\OAuth2\AuthCode
- Add this in framework.yaml:
templating:
engines: ['twig']
- Install FOSOAuthServerBundle:
composer require friendsofsymfony/oauth-server-bundle dev-master
And it should be OK Should also work with 1.6.x, I guess
@Sengorius @chriskaya The error message is pretty straightforward
The service "fos_oauth_server.controller.authorize" has a dependency on a non-existent service "templating"
You need to run
composer require symfony/templating
@SebScoFr as you can see above, I already had symfony/templating :/
I had the same error with a different bundle (sonata-admin) and I had to add the templating line to framework.yaml too. I didn't explicity require symfony/templating in composer.json but it was installed via fos-rest. Symfony 4 growing pains I suppose.
@haroldmodesto I think that symfony/templating
it's wrong. If you are using Symfony Flex try to run composer req template
and it'll install all dependencies from Twig. For me to work.
@Luitame The thing is (in my case) templating is already included (required) by some other bundle. I already have the library/bundle just not configured.
I know it's kind of difficult to decide which bundle should have the responsibility of auto-configuring some sane defaults and/or at the same time not override user settings.
@Luitame for me composer require templating
did nothing :/
EDIT: my bad, I read too quickly ^^
Unfortunately composer require template
didn't fix it either, I still need to add the templating thing in framework.yaml
PS: thx @Luitame for the link ;)
@chriskaya see this (https://knpuniversity.com/screencast/symfony) basic overview of Symfony 4 concepts. It's free!
Is there any fix for this problem? I'm trying to add it for authorizing API requests on a fresh Symfony 4.1 skeleton project? Am I forced to include twig and templating part of the project for no reason?
Thanks guys.
It's not for no reason — it's used to generate auth/deny template for a particular application. But sure, it should be included within composer.json.
Templating component was only made optional with Symfony 4.0, IIRC (citation needed). Since this bundle needs to support Symfony 2.8, 3.4, 4.x, we can't just remove it.
So this is where things get interesting: https://symfony.com/blog/new-in-symfony-4-3-deprecated-the-templating-component-integration
"templating" is deprecated from framework config
@elchris I m also getting same error The service "fos_oauth_server.controller.authorize" has a dependency on a non-existent service "templating" Is there any fix for this problem?
someone just needs to make a patch to tweak this project's templating dependencies, to just hardcode it to using twig templates, instead of referencing the Engine Interface as a dependency, which is basically what's being deprecated.
@papnoisanjeev
You must declare the templating engine. So, to avoid this error, add simply :
templating: { engines: ['twig'] }
in config/packages/framework.yaml
As explained by @chriskaya and @elchris and referenced here : https://symfony.com/doc/3.1/templating/templating_service.html
@tlemignan-teicee thanks for your support. I have declared templating: { engines: ['twig'] } before and it was working fine.
Any news here? This month we get Symfony 5.0 and this is a breaking issue.
@tlemignan-teicee @papnoisanjeev that is NOT the answer since "templating" is deprecated from Symfony 4.3 and is removed from Symfony 5.0.
This is a breaking issue for upgrading.
https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/pull/623
It's currently resolved here so we need some patience.
My solution for Symfony 3.4 and 4.4 is creating custom recipes for them:
# ORM
export SYMFONY_ENDPOINT=https://flex.symfony.com/r/github.com/symfony/recipes-contrib/832
composer require tienvx/fos-oauth-server-bundle-orm
# ODM
export SYMFONY_ENDPOINT=https://flex.symfony.com/r/github.com/symfony/recipes-contrib/833
composer remove tienvx/fos-oauth-server-bundle-mongodb
These custom recipes does not support Symfony 5.0 yet, because FOSOAuthServerBundle does not.
@Luitame If you are using SF4, make sure your fos_auth_server.yaml looks something like this (note the db_driver section):
fos_oauth_server: db_driver: mongodb client_class: App\Document\Client access_token_class: App\Document\AccessToken refresh_token_class: App\Document\RefreshToken auth_code_class: App\Document\AuthCode service: user_provider: App\Provider\UserProvider
If you're still on 3.x that will be within the app/config.yml file under the FOS configuration section
The problem is that fos_auth_server.yaml
does not exist until you successfully install the bundle when creating a new 4.4 project from scratch