无法让自定义用户提供程序使用FOSFacebookBundle和FOSUserBundle

时间:2012-06-02 12:58:25

标签: symfony fosuserbundle

我正在尝试让两个捆绑包一起工作,以便在使用提供的Facebook登录按钮发生facebook登录时创建并登录新用户。

我根据堆栈溢出的其他问题尝试了很多东西,但我仍然无法让它工作。这是我的代码(我已经把一些我在评论中尝试过的东西;我基本上尝试了每种可能的组合):

Config.yml

fos_facebook:
  file:   %kernel.root_dir%/../vendor/facebook/src/base_facebook.php
  alias:  facebook
  app_id: FOO
  secret: BAR
  cookie: true
  permissions: [email, user_birthday]

fos_user:
    db_driver: orm
    firewall_name: public
    user_class: Not\NotBundle\Entity\User

的routing.yml

# fos_user_security:
#     resource: "@FOSUserBundle/Resources/config/routing/security.xml"

_security_check:
    pattern:  /login_check

_security_logout:
    pattern:  /logout

Security.yml

security:
factories:
    - "%kernel.root_dir%/../vendor/bundles/FOS/FacebookBundle/Resources/config/security_factories.xml"

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

providers:
    # chain_provider:
    #     providers: [fos_userbundle, my_fos_facebook_provider]
    # fos_userbundle:
    #     id: fos_user.user_manager
    my_fos_facebook_provider:
        id: my.facebook.user

encoders:
    "FOS\UserBundle\Model\UserInterface": sha512

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
    public:
        pattern:   ^/.*
        fos_facebook:
            app_url: "http://apps.facebook.com/FOO/"
            server_url: "http://not.not/facebookApp/"
            login_path: ^/login$
            check_path: ^/login_check$
            default_target_path: /
            provider: my_fos_facebook_provider
        # form_login:
        #     login_path: /login
        #     check_path: /login_check
        #     provider: fos_userbundle
        anonymous: true
        logout:
            handlers: ["fos_facebook.logout_handler"]

Services.yml

parameters:
    #my_facebook_user.class: Not\NotBundle\Security\User\Provider\FacebookProvider

services:
    my.facebook.user:
        class: Not\NotBundle\Security\User\Provider\FacebookProvider
        arguments:
            facebook: "@fos_facebook.api"
            userManager: "@fos_user.user_manager"
            # userManager: "@my.facebook.user" # <-- Tried this as well but gives: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 523800 bytes) in /Foo/vendor/symfony/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraphEdge.php  
            validator: "@validator"
            container: "@service_container"

基本上这种配置最接近FOSFacebookBundle文档。目前我收到错误:

  

无法找到路径“/ login_check”的控制器。也许您忘了在路由配置中添加匹配的路由?

非常感谢任何帮助!

2 个答案:

答案 0 :(得分:1)

check_pathfos_facebook身份验证提供程序的

form_login应该不同。

答案 1 :(得分:1)

更改路径的检查路径和登录路径解决了我的问题:

<强> security.yml

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
    public:
        pattern:   ^/.*
        fos_facebook:
            app_url: "http://apps.facebook.com/Foo/"
            server_url: "http://localhost/facebookApp/"
            login_path: NotNotBundle_homepage
            check_path: _security_check
            default_target_path: /
        anonymous: true
        logout:
            handlers: ["fos_facebook.logout_handler"]