FOSFacebookBundle error after logging in. The controller should return a response (null)

I use Symfony FOSUserBundle, SonataUserBundle, FOSFacebookBundle. I added a login button to my application.

I can log in using facebook, but after logging in, the page is redirected to demo / secure / login_check and I get the following error.

"The controller should return a response (zero). Have you forgotten to add a return statement somewhere in your controller?"

I already watched

The service does not start: the controller should return a response (null)

https://github.com/FriendsOfSymfony/FOSFacebookBundle/issues/186

But I don’t know what changes I should make to my configuration.

Below if my security configuration

security: encoders: FOS\UserBundle\Model\UserInterface: sha512 role_hierarchy: ROLE_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN] ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] SONATA: - ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT # if you are using acl then this line must be commented providers: chain_provider: chain: providers: [fos_userbundle, fo_fos_facebook_provider] fos_userbundle: id: fos_user.user_manager fo_fos_facebook_provider: id: my.facebook.user firewalls: # Disabling the security for the web debug toolbar, the profiler and Assetic. dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false # -> custom firewall for the admin area of the URL admin: pattern: /admin(.*) context: user form_login: provider: fos_userbundle login_path: /admin/login use_forward: false check_path: /admin/login_check failure_path: null logout: path: /admin/logout anonymous: true main: pattern: ^/ context: user form_login: provider: fos_userbundle login_path: /login use_forward: false check_path: /login_check failure_path: null csrf_provider: form.csrf_provider logout: true anonymous: true public: # since anonymous is allowed users will not be forced to login pattern: ^/.* fos_facebook: app_url: "http://apps.facebook.com/my-app/" server_url: "http://localhost/me/my/symfony/web/app_dev.php/" login_path: /login check_path: /login_check default_target_path: / provider: fo_fos_facebook_provider redirect_to_facebook_login: false anonymous: true access_control: # URL of FOSUserBundle which need to be available to anonymous users - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } # Admin login page needs to be access without credential - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/admin/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY } # Secured part of the site # This config requires being logged for the whole site and having the admin role for the admin part. # Change these rules to adapt them to your needs - { path: ^/admin/, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN] } - { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/secured/.*, role: [IS_AUTHENTICATED_FULLY] } acl: connection: default 

I tried changing the configurations as shown below to avoid a firewall matching a single URL pattern.

 security: encoders: FOS\UserBundle\Model\UserInterface: sha512 role_hierarchy: ROLE_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN] ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] SONATA: - ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT # if you are using acl then this line must be commented providers: chain_provider: chain: providers: [fos_userbundle, fo_fos_facebook_provider] fos_userbundle: id: fos_user.user_manager fo_fos_facebook_provider: id: my.facebook.user firewalls: # Disabling the security for the web debug toolbar, the profiler and Assetic. dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false # -> custom firewall for the admin area of the URL admin: pattern: /admin(.*) context: user form_login: provider: fos_userbundle login_path: /admin/login use_forward: false check_path: /admin/login_check failure_path: null logout: path: /admin/logout anonymous: true main: pattern: ^/ context: user fos_facebook: app_url: "http://apps.facebook.com/my-app/" server_url: "http://localhost/me/my/symfony/web/app_dev.php/" login_path: /login check_path: /login_check default_target_path: / provider: fo_fos_facebook_provider redirect_to_facebook_login: false form_login: provider: fos_userbundle login_path: /login use_forward: false check_path: /login_check failure_path: null csrf_provider: form.csrf_provider logout: true anonymous: true access_control: # URL of FOSUserBundle which need to be available to anonymous users - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } # Admin login page needs to be access without credential - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/admin/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/admin/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY } # Secured part of the site # This config requires being logged for the whole site and having the admin role for the admin part. # Change these rules to adapt them to your needs - { path: ^/admin/, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN] } - { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/secured/.*, role: [IS_AUTHENTICATED_FULLY] } acl: connection: default 

But now I get another error, as below.

"InvalidConfigurationException: You are not allowed to define new elements for the" security.firewalls "path. Please define all elements for this path in the same configuration file."

0
source share
2 answers

I figured it out and am sharing my code here

https://github.com/vishalmelmatti/FOSSonataUserFacebookIntegration

Its fully operational integration is FOSUserBundle FOSFacebookBundle SonataAdminBundle SonataUserBundle.

0
source

As reported in the giyhub release: “You cannot have two firewalls with the same pattern: the first firewall will be used, so your public firewall cannot be used as the main one, it’s already“ after all ”

Your main template and your general template correspond to the same route. You can try it here: http://www.regular-expressions.info/javascriptexample.html

Case: ^ / topic: / home OK Case: ^ /. * Subject / home OK

So, you have two firewalls that match exactly the same URL. You must change the routing rule for your shared firewall or primary firewall.

+1
source

Source: https://habr.com/ru/post/907109/


All Articles