我正在使用Symfony FOSUserBundle,SonataUserBundle,FOSFacebookBundle。我已将登录按钮添加到我的应用程序中。
我可以使用facebook登录但登录后页面重定向到demo / secured / login_check,我收到以下错误。
“控制器必须返回响应(给定null)。您是否忘记在控制器的某处添加return语句?”
我已经看过了
Service not triggered : The controller must return a response (null given)
https://github.com/FriendsOfSymfony/FOSFacebookBundle/issues/186
但不确定我应该对我的配置做出哪些更改。
下面是我的安全配置
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
我尝试更改以下配置,以避免2个防火墙匹配相同的网址格式。
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
但我现在得到的错误如下所示
“InvalidConfigurationException:您不能为路径”security.firewalls“定义新元素。请在一个配置文件中定义此路径的所有元素。”
答案 0 :(得分:1)
据giyhub报道: “您不能拥有2个具有相同模式的防火墙:将使用匹配的第一个防火墙,因此您的公共防火墙不能用作主要已经是一个全能的”
您的主模式和公共模式匹配相同的路线。 你可以在这里试试:http://www.regular-expressions.info/javascriptexample.html
案例:^ / subject:/ home OK 案例:^ /。* subject / home OK
因此,您有两个匹配完全相同URL的防火墙。您必须更改公共防火墙或主防火墙的路由规则。
答案 1 :(得分:0)
我想出来并在这里分享我的代码
https://github.com/vishalmelmatti/FOSSonataUserFacebookIntegration
FOSUserBundle FOSFacebookBundle SonataAdminBundle SonataUserBundle全面整合。