FOSOAuthServerBundle icon indicating copy to clipboard operation
FOSOAuthServerBundle copied to clipboard

Error requiring bundle from composer on SF4

Open SebScoFr opened this issue 7 years ago • 26 comments

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?

SebScoFr avatar Jan 05 '18 16:01 SebScoFr

There needs to exist a Flex recipe for the package for it to be auto-configured.

dkarlovi avatar Jan 05 '18 17:01 dkarlovi

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 avatar Jan 05 '18 19:01 SebScoFr

@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 avatar Jan 19 '18 18:01 Luitame

@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

SebScoFr avatar Jan 19 '18 20:01 SebScoFr

Hey, @SebScoFr let's join forces to create the recipe from Symfony Flex for this package?

Luitame avatar Jan 22 '18 19:01 Luitame

@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 avatar Jan 24 '18 15:01 Sengorius

@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:

  1. Make sure you have installed twig:
composer require symfony/twig-bundle
  1. 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
  1. Add this in framework.yaml:
    templating:
        engines: ['twig']
  1. Install FOSOAuthServerBundle:
composer require friendsofsymfony/oauth-server-bundle dev-master

And it should be OK Should also work with 1.6.x, I guess

chriskaya avatar Jan 25 '18 16:01 chriskaya

@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 avatar Jan 26 '18 08:01 SebScoFr

@SebScoFr as you can see above, I already had symfony/templating :/

chriskaya avatar Jan 26 '18 09:01 chriskaya

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 avatar Jan 29 '18 13:01 haroldmodesto

@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 avatar Jan 29 '18 14:01 Luitame

@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.

haroldmodesto avatar Jan 29 '18 14:01 haroldmodesto

@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 avatar Jan 30 '18 10:01 chriskaya

@chriskaya see this (https://knpuniversity.com/screencast/symfony) basic overview of Symfony 4 concepts. It's free!

Luitame avatar Jan 30 '18 12:01 Luitame

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.

mehranhadidi avatar Jun 09 '18 07:06 mehranhadidi

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.

er1z avatar Jun 15 '18 10:06 er1z

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.

dkarlovi avatar Jun 15 '18 10:06 dkarlovi

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 avatar Aug 08 '19 16:08 elchris

@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?

papnoisanjeev avatar Sep 04 '19 08:09 papnoisanjeev

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.

elchris avatar Sep 04 '19 08:09 elchris

@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 avatar Oct 04 '19 14:10 tlemignan-teicee

@tlemignan-teicee thanks for your support. I have declared templating: { engines: ['twig'] } before and it was working fine.

papnoisanjeev avatar Oct 05 '19 04:10 papnoisanjeev

Any news here? This month we get Symfony 5.0 and this is a breaking issue.

phtmgt avatar Nov 03 '19 11:11 phtmgt

@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.

jakub-rompca avatar Nov 21 '19 09:11 jakub-rompca

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.

tienvx avatar Feb 04 '20 18:02 tienvx

@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

sterichards avatar Dec 07 '20 15:12 sterichards