Pier-Luc Gendreau
Pier-Luc Gendreau

Reputation: 13814

FOSFacebookBundle not adding users to database

I have successfully configured FOSUserBundle to connect to the admin section of the website, this works great.

We want public users to only be able to login to the website via Facebook so I have also installed FOSFacebookBundle, which works. Sort of. I can login, authenticate, access the user's profile page and logout; all that works as expected.

However, when a user logs in via Facebook, the user isn't added to the database. Am I mistaken that this is what the "Custom User Provider" at the bottom of the docs (https://github.com/FriendsOfSymfony/FOSFacebookBundle) is supposed to do?

Basically, when a Facebook login happens, the user is added (if necessary) and then fetched through FOSUserBundle.

I followed the docs time and time again, read questions here on SO and can't figure out what's (not) happening.

Anyone have ideas as to where in the code something could be causing the login action not to update the database with Facebook data?

Upvotes: 0

Views: 521

Answers (1)

Pier-Luc Gendreau
Pier-Luc Gendreau

Reputation: 13814

In security.yml:

    providers:
        chain_provider:
            chain:
                providers: [my_fos_facebook_provider, fos_userbundle]
        my_fos_facebook_provider:
            id: my.facebook.user
        fos_userbundle:
            id: fos_user.user_manager
    firewalls:
        admin:
            pattern:      /admin(.*)
            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
        public:
            # since anonymous is allowed users will not be forced to login
            pattern:   ^/.*
            fos_facebook:
                provider: my_fos_facebook_provider
                app_url: "http://www.facebook.com/apps/application.php?id=your_app_id"
                server_url: "http://localhost/facebookApp/"
                login_path: /
                check_path: /login_check_fb
                default_target_path: /moi
            anonymous: true
            logout:
                handlers: ["fos_facebook.logout_handler"]

The idea is that admin is accessed with a run of the mill username and password and normal users log in via Facebook.

Now, the key part is to define multiple providers (which I had), but perhaps most importantly is to specify the "provider" in each of the firewalls. fos_userbundle for admin and my_fos_facebook_provider for public

Upvotes: 2

Related Questions