FriendsOfSymfony / FOSOAuthServerBundle

A server side OAuth2 Bundle for Symfony
1.09k stars 451 forks source link

The mapping file Client.mongodb.xml is invalid #633

Closed Evertt closed 4 years ago

Evertt commented 4 years ago

When installing this package (at version dev-master) I get.

!!  In MappingException.php line 236:
!!                                                                                 
!!    The mapping file /Users/evert/Sites/mei-api/vendor/friendsofsymfony/oauth-s  
!!    erver-bundle/Resources/config/doctrine/Client.mongodb.xml is invalid:        
!!    Line 8:0: Element '{http://doctrine-project.org/schemas/odm/doctrine-mongo-  
!!    mapping}field', attribute 'fieldName': The attribute 'fieldName' is not all  
!!    owed.                                                                        
!!                                                                                 
!!    Line 9:0: Element '{http://doctrine-project.org/schemas/odm/doctrine-mongo-  
!!    mapping}field', attribute 'fieldName': The attribute 'fieldName' is not all  
!!    owed.                                                                        
!!                                                                                 
!!    Line 10:0: Element '{http://doctrine-project.org/schemas/odm/doctrine-mongo  
!!    -mapping}field', attribute 'fieldName': The attribute 'fieldName' is not al  
!!    lowed.                                                                       
!!                                                                                 
!!    Line 11:0: Element '{http://doctrine-project.org/schemas/odm/doctrine-mongo  
!!    -mapping}field', attribute 'fieldName': The attribute 'fieldName' is not al  
!!    lowed.                                                                       
!!                                                                                 

I checked the file Client.mongodb.xml and indeed it says that the attribute fieldName should actually be called field-name. I was hoping that I could just ignore this error by not using mongodb, but orm instead.

# /config/packages/fos_auth_server.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
  service:
    user_provider: App\Provider\UserProvider

But that doesn't seem to make a difference. What do I do?

alcaeus commented 4 years ago

Which version of MongoDB ODM are you using? This bundle hasn't been updated for ODM 2.0 yet, which may be the problem you're running into.

Evertt commented 4 years ago

My composer.json says "doctrine/mongodb-odm-bundle": "^4.0". Which indeed uses ODM 2.0 I see.

However, when I try to install doctrine/mongodb-odm-bundle:^3.6 then I get:

  Problem 1
    - doctrine/mongodb-odm-bundle 3.6.0 requires doctrine/mongodb ^1.4 -> satisfiable by doctrine/mongodb[1.4.0, 1.5.0, 1.6.0, 1.6.1, 1.6.2, 1.6.3, 1.6.4].
    - doctrine/mongodb-odm-bundle 3.6.1 requires doctrine/mongodb ^1.4 -> satisfiable by doctrine/mongodb[1.4.0, 1.5.0, 1.6.0, 1.6.1, 1.6.2, 1.6.3, 1.6.4].
    - doctrine/mongodb 1.6.4 requires ext-mongo ^1.6.7 -> the requested PHP extension mongo is missing from your system.
    - doctrine/mongodb 1.6.3 requires ext-mongo ^1.6.7 -> the requested PHP extension mongo is missing from your system.
    - doctrine/mongodb 1.6.2 requires ext-mongo ^1.6.7 -> the requested PHP extension mongo is missing from your system.
    - doctrine/mongodb 1.6.1 requires ext-mongo ^1.6.7 -> the requested PHP extension mongo is missing from your system.
    - doctrine/mongodb 1.6.0 requires ext-mongo ^1.6.7 -> the requested PHP extension mongo is missing from your system.
    - doctrine/mongodb 1.5.0 requires ext-mongo ^1.5 -> the requested PHP extension mongo is missing from your system.
    - doctrine/mongodb 1.4.0 requires ext-mongo ^1.5 -> the requested PHP extension mongo is missing from your system.
    - Installation request for doctrine/mongodb-odm-bundle ^3.6 -> satisfiable by doctrine/mongodb-odm-bundle[3.6.0, 3.6.1].

Which confused me at first, because I do have the extension mongodb installed in my php. But then I noticed that the error is talking about the extension mongo, and not the extension mongodb. So I tried running pecl install mongo and then I get:

WARNING: "pecl/mongo" is deprecated in favor of "channel:///mongodb"
pecl/mongo requires PHP (version >= 5.3.0, version <= 5.99.99), installed version is 7.2.22
No valid packages found
install failed

Which suggests that that extension is very outdated. Which makes me think that if FOSOAuthServerBundle requires me to use such an old extension, then I may want to look for another bundle...

alcaeus commented 4 years ago

This bundle was designed for ODM 1.x, which was built around the legacy MongoDB extension. This legacy extension was dropped in favour of a new extension, as a result of which it wasn't ported to PHP 7. ODM 2.0 now uses the new extension, but contains a significant number of BC breaks, for which this bundle still hasn't been adapter (I haven't gotten to that yet).

However, if you want to run this with MongoDB on PHP 7, you can use my adapter library, which is also documented in the docs for the MongoDB ODM: https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/1.3/reference/introduction.html#using-php-7. This library provides the API of the legacy driver, but is built on top of the new driver.

As for ODM 2 support here, the plan is to have version 2.0 of this bundle out soon, which will have full support for ODM 2.0. Apologies for the inconvenience.

Evertt commented 4 years ago

Thanks, that worked.

sjoerdmaessen commented 4 years ago

I'm having the same issue but for me the adapter doesn't work because the issue really seems to be in the .xml files. If I change fieldName to field-name temporarily in the Vendor directory everything works as expected. Is there a way to override these xml's in a Symfony 4 project?

Files I would need to override:

What makes it even more strange is that I used Doctrine ORM for the oAuth, not the ODM. Yet it still includes the Mongodb.xml files.

fos_oauth_server: db_driver: orm

Ideally it shouldn't even include the .xml files.

alcaeus commented 4 years ago

@sjoerdmaessen I believe this is due to the auto_mapping setting which automatically loads these. I'd have to play around, but if you're using ODM but not for this bundle, you should disable auto_mapping and define mappings manually.

arekmalek1 commented 4 years ago

@alcaeus I would like to use ODM version 2.0 in my project. When are you planning support for ODM ^ 2.0?

alcaeus commented 4 years ago

@arekmalek1 I am not working on this project anymore, as my current workload does not allow for it. If you are interested in using this with 2.0, I encourage you to create a pull request with the necessary changes. If you need help with the migration from 1.x to 2.0, you are welcome to ping me in the Symfony Slack, but be aware that my responses may be delayed.

rupeshwankhede commented 1 year ago

Can you please merge https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/pull/669 this PR into dev-master branch. @alcaeus dev-1.6 version not supported for PHP 8.0. Currently I am trying with below configuration php8.1 version and Symfony 5.4 and mongodb-odm 2.0.