Thomas K
Thomas K

Reputation: 6196

Can't get custom user provider working with FOSFacebookBundle and FOSUserBundle

I'm trying to get both bundles working together so that a new user is created and logged in whenever a facebook login occurs with the provided facebook login button.

I've tries a lot of things based on other questions here on stack overflow but I still can't get it to work. Here's my code (I've put some of the things i've tried in comments; I basically tried each possible combination with those):

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"

Basically this configuration is closest to the FOSFacebookBundle docs. At the moment I'm getting the error:

Unable to find the controller for path "/login_check". Maybe you forgot to add the matching route in your routing configuration?

Any help would be greatly appreciated!

Upvotes: 1

Views: 2592

Answers (2)

Thomas K
Thomas K

Reputation: 6196

Changing the check path and login path to routes solved my problem:

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"]

Upvotes: 1

Mun Mun Das
Mun Mun Das

Reputation: 15002

check_path for fos_facebook and form_login authentication provider should be different.

Upvotes: 1

Related Questions