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

Compatibility bug with Symfony 6.1 & ApiPlatform 3.0 #342

Open
ppoz21 opened this issue Sep 24, 2022 · 6 comments
Open

Compatibility bug with Symfony 6.1 & ApiPlatform 3.0 #342

ppoz21 opened this issue Sep 24, 2022 · 6 comments

Comments

@ppoz21
Copy link

ppoz21 commented Sep 24, 2022

Hi everyone,

I have problem with Symfony 6.1.0 and ApiPlatform 3.0.0

After installing bundle via composer all my API routes disappeared (only LexikJWT route added by OpenAPI decorator left)

image

When I remove bundle from bundles.php all endpoints return

image

Here is my code:

RefreshToken.php

<?php

declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken as BaseRefreshToken;

#[ORM\Entity]
#[ORM\Table('`refresh_tokens`')]
class RefreshToken extends BaseRefreshToken
{
}

security.yaml

security:
    password_hashers:
        Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
    enable_authenticator_manager: true
    providers:
        app_user_provider:
            entity:
                class: App\Entity\User
                property: email
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false

        main:
            stateless: true
            provider: app_user_provider
            entry_point: jwt
            json_login:
                check_path: /authentication_token
                username_path: email
                password_path: password
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure
            jwt: ~
            refresh_jwt:
                check_path: /token/refresh
                provider: app_user_provider

    access_control:
        - { path: ^/authentication_token, roles: PUBLIC_ACCESS }
        - { path: ^/token/refresh, roles: PUBLIC_ACCESS }
        - { path: ^/api$, roles: PUBLIC_ACCESS }
#        - { path: ^/, roles: IS_AUTHENTICATED_FULLY }

Anyone have any solution?

@dutchtux3000
Copy link

dutchtux3000 commented Sep 28, 2022

I got the same problem here too.
I just see that when enabling the bundle all the routes of the Entities disappear from the routes list.

With bundle enabled

-------------------------- -------- -------- ------ ------------------------------------- --------------------------------------------------------- 
  Name                       Method   Scheme   Host   Path                                  Controller                                               
 -------------------------- -------- -------- ------ ------------------------------------- --------------------------------------------------------- 
  _preview_error             ANY      ANY      ANY    /_error/{code}.{_format}              error_controller::preview()                              
  _wdt                       ANY      ANY      ANY    /_wdt/{token}                         web_profiler.controller.profiler::toolbarAction()        
  _profiler_home             ANY      ANY      ANY    /_profiler/                           web_profiler.controller.profiler::homeAction()           
  _profiler_search           ANY      ANY      ANY    /_profiler/search                     web_profiler.controller.profiler::searchAction()         
  _profiler_search_bar       ANY      ANY      ANY    /_profiler/search_bar                 web_profiler.controller.profiler::searchBarAction()      
  _profiler_phpinfo          ANY      ANY      ANY    /_profiler/phpinfo                    web_profiler.controller.profiler::phpinfoAction()        
  _profiler_xdebug           ANY      ANY      ANY    /_profiler/xdebug                     web_profiler.controller.profiler::xdebugAction()         
  _profiler_search_results   ANY      ANY      ANY    /_profiler/{token}/search/results     web_profiler.controller.profiler::searchResultsAction()  
  _profiler_open_file        ANY      ANY      ANY    /_profiler/open                       web_profiler.controller.profiler::openAction()           
  _profiler                  ANY      ANY      ANY    /_profiler/{token}                    web_profiler.controller.profiler::panelAction()          
  _profiler_router           ANY      ANY      ANY    /_profiler/{token}/router             web_profiler.controller.router::panelAction()            
  _profiler_exception        ANY      ANY      ANY    /_profiler/{token}/exception          web_profiler.controller.exception_panel::body()          
  _profiler_exception_css    ANY      ANY      ANY    /_profiler/{token}/exception.css      web_profiler.controller.exception_panel::stylesheet()    
  auth_user_login            POST     ANY      ANY    /authentication/user/login                                                                     
  auth_user_refresh          ANY      ANY      ANY    /authentication/user/refresh                                                                   
  api_genid                  ANY      ANY      ANY    /api/.well-known/genid/{id}           api_platform.action.not_exposed()                        
  api_entrypoint             ANY      ANY      ANY    /api/{index}.{_format}                api_platform.action.entrypoint()                         
  api_doc                    ANY      ANY      ANY    /api/docs.{_format}                   api_platform.action.documentation()                      
  api_jsonld_context         ANY      ANY      ANY    /api/contexts/{shortName}.{_format}   api_platform.jsonld.action.context()                     
 -------------------------- -------- -------- ------ ------------------------------------- --------------------------------------------------------- 

With bundle disabled:

 ----------------------------------------- -------- -------- ------ ------------------------------------- --------------------------------------------------------- 
  Name                                      Method   Scheme   Host   Path                                  Controller                                               
 ----------------------------------------- -------- -------- ------ ------------------------------------- --------------------------------------------------------- 
  _preview_error                            ANY      ANY      ANY    /_error/{code}.{_format}              error_controller::preview()                              
  _wdt                                      ANY      ANY      ANY    /_wdt/{token}                         web_profiler.controller.profiler::toolbarAction()        
  _profiler_home                            ANY      ANY      ANY    /_profiler/                           web_profiler.controller.profiler::homeAction()           
  _profiler_search                          ANY      ANY      ANY    /_profiler/search                     web_profiler.controller.profiler::searchAction()         
  _profiler_search_bar                      ANY      ANY      ANY    /_profiler/search_bar                 web_profiler.controller.profiler::searchBarAction()      
  _profiler_phpinfo                         ANY      ANY      ANY    /_profiler/phpinfo                    web_profiler.controller.profiler::phpinfoAction()        
  _profiler_xdebug                          ANY      ANY      ANY    /_profiler/xdebug                     web_profiler.controller.profiler::xdebugAction()         
  _profiler_search_results                  ANY      ANY      ANY    /_profiler/{token}/search/results     web_profiler.controller.profiler::searchResultsAction()  
  _profiler_open_file                       ANY      ANY      ANY    /_profiler/open                       web_profiler.controller.profiler::openAction()           
  _profiler                                 ANY      ANY      ANY    /_profiler/{token}                    web_profiler.controller.profiler::panelAction()          
  _profiler_router                          ANY      ANY      ANY    /_profiler/{token}/router             web_profiler.controller.router::panelAction()            
  _profiler_exception                       ANY      ANY      ANY    /_profiler/{token}/exception          web_profiler.controller.exception_panel::body()          
  _profiler_exception_css                   ANY      ANY      ANY    /_profiler/{token}/exception.css      web_profiler.controller.exception_panel::stylesheet()    
  auth_user_login                           POST     ANY      ANY    /authentication/user/login                                                                     
  auth_user_refresh                         ANY      ANY      ANY    /authentication/user/refresh                                                                   
  api_genid                                 ANY      ANY      ANY    /api/.well-known/genid/{id}           api_platform.action.not_exposed()                        
  api_entrypoint                            ANY      ANY      ANY    /api/{index}.{_format}                api_platform.action.entrypoint()                         
  api_doc                                   ANY      ANY      ANY    /api/docs.{_format}                   api_platform.action.documentation()                      
  api_jsonld_context                        ANY      ANY      ANY    /api/contexts/{shortName}.{_format}   api_platform.jsonld.action.context()                     
  _api_/students/{id}.{_format}_get         GET      ANY      ANY    /api/students/{id}.{_format}          api_platform.action.placeholder()                        
  _api_/students.{_format}_get_collection   GET      ANY      ANY    /api/students.{_format}               api_platform.action.placeholder()                        
  _api_/students.{_format}_post             POST     ANY      ANY    /api/students.{_format}               api_platform.action.placeholder()                        
  _api_/students/{id}.{_format}_put         PUT      ANY      ANY    /api/students/{id}.{_format}          api_platform.action.placeholder()                        
  _api_/students/{id}.{_format}_patch       PATCH    ANY      ANY    /api/students/{id}.{_format}          api_platform.action.placeholder()                        
  _api_/students/{id}.{_format}_delete      DELETE   ANY      ANY    /api/students/{id}.{_format}          api_platform.action.placeholder()                        
  _api_/users/{id}.{_format}_get            GET      ANY      ANY    /api/users/{id}.{_format}             api_platform.action.placeholder()                        
  _api_/users.{_format}_get_collection      GET      ANY      ANY    /api/users.{_format}                  api_platform.action.placeholder()                        
  _api_/users.{_format}_post                POST     ANY      ANY    /api/users.{_format}                  api_platform.action.placeholder()                        
  _api_/users/{id}.{_format}_put            PUT      ANY      ANY    /api/users/{id}.{_format}             api_platform.action.placeholder()                        
  _api_/users/{id}.{_format}_patch          PATCH    ANY      ANY    /api/users/{id}.{_format}             api_platform.action.placeholder()                        
  _api_/users/{id}.{_format}_delete         DELETE   ANY      ANY    /api/users/{id}.{_format}             api_platform.action.placeholder()                        
 ----------------------------------------- -------- -------- ------ ------------------------------------- --------------------------------------------------------- 

I use the same configuration that @ppoz21 is given in the example above.

EDIT: The console debug:api-resource I can debug the API resource with no problem.

@tamsirgueye
Copy link

tamsirgueye commented Sep 29, 2022

Hi!

I use google translation.

I have the same problem also.

First of all the bundle disrupted the functioning of the maker-bundle. Take a look at this issue.

Then after configuration all my routes that are generated with the #[ApiResource] attribute disappear completely.

I think the bundle is not ready for symfony 6 yet

@dutchtux3000
Copy link

I think the problem is that entity is using the old style annotation of doctrine instead of the PHP 8 attributes.

@mbabker
Copy link
Contributor

mbabker commented Oct 4, 2022

I think the problem is that entity is using the old style annotation of doctrine instead of the PHP 8 attributes.

The doc examples and the file added by the Flex recipe use annotations, but if your application is using attributes, you can update the code in your application to use those. Annotations use is still valid on PHP 8, but the ecosystem is moving away from it (if everything only documented/configured attributes by default, then folks running on PHP 7 would have broken apps; it's one of those "you can't win them all" situations).

@erikkubica
Copy link

erikkubica commented Nov 16, 2022

Hi everyone, is there any workaround?

As described by others, API platform API resources are debug-able but they don't appear in routing therefore the routes are not callable and they don't appear in swagger. It feels like it's preventing API platform from registering routes which makes no sense to me if it's not decorated with the #[ApiResource]

I have changed my RefreshToken entity to

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken as BaseRefreshToken;

#[ORM\Entity]
#[ORM\Table(name: 'refresh_tokens')]
class RefreshToken extends BaseRefreshToken { }

security.yml

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js|docs.jsonld|docs|nextjs)/
            security: false
        main:
            pattern: ^/
            stateless: true
            lazy: true
            provider: app_user_provider
            entry_point: jwt
            json_login:
                check_path: /token/request
                username_path: email
                password_path: password
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure
            jwt: ~
            refresh_jwt:
                check_path: /token/refresh

    access_control:
        - { path: ^/(docs|docs.jsonld), roles: PUBLIC_ACCESS }
        - { path: ^/token/(refresh|request), roles: PUBLIC_ACCESS }
        - { path: ^/admin, roles: PUBLIC_ACCESS }
        - { path: ^/form_datas/submit/*/*, roles: PUBLIC_ACCESS }
        - { path: ^/, roles: IS_AUTHENTICATED_FULLY }

routes/token.yml

token_request:
    path: /token/request
    methods: [ 'POST' ]

token_refresh:
    path:       /token/refresh
    controller: gesdinet.jwtrefreshtoken::refresh
/srv/app # php bin/console debug:router
 -------------------------- -------- -------- ------ ----------------------------------- 
  Name                       Method   Scheme   Host   Path                               
 -------------------------- -------- -------- ------ ----------------------------------- 
  api_genid                  ANY      ANY      ANY    /.well-known/genid/{id}            
  api_entrypoint             ANY      ANY      ANY    /{index}.{_format}                 
  api_doc                    ANY      ANY      ANY    /docs.{_format}                    
  api_jsonld_context         ANY      ANY      ANY    /contexts/{shortName}.{_format}    
  _preview_error             ANY      ANY      ANY    /_error/{code}.{_format}           
  token_request              POST     ANY      ANY    /token/request                     
  token_refresh              ANY      ANY      ANY    /token/refresh                     
  _wdt                       ANY      ANY      ANY    /_wdt/{token}                      
  _profiler_home             ANY      ANY      ANY    /_profiler/                        
  _profiler_search           ANY      ANY      ANY    /_profiler/search                  
  _profiler_search_bar       ANY      ANY      ANY    /_profiler/search_bar              
  _profiler_phpinfo          ANY      ANY      ANY    /_profiler/phpinfo                 
  _profiler_xdebug           ANY      ANY      ANY    /_profiler/xdebug                  
  _profiler_search_results   ANY      ANY      ANY    /_profiler/{token}/search/results  
  _profiler_open_file        ANY      ANY      ANY    /_profiler/open                    
  _profiler                  ANY      ANY      ANY    /_profiler/{token}                 
  _profiler_router           ANY      ANY      ANY    /_profiler/{token}/router          
  _profiler_exception        ANY      ANY      ANY    /_profiler/{token}/exception       
  _profiler_exception_css    ANY      ANY      ANY    /_profiler/{token}/exception.css   

@erikkubica
Copy link

Don't know what made a difference, maybe installing symfony then adding api-platform, but flex + api-platform actually works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants