FriendsOfSymfony / FOSFacebookBundle

NOT MAINTAINED - see https://github.com/hwi/HWIOAuthBundle
322 stars 140 forks source link

Cannot get User as entity #214

Open mrares opened 11 years ago

mrares commented 11 years ago

Hello,

I am trying to use the FOSUserBundle together with FOSFacebookBundle to authenticate users via FB. Symfony reports the user as authenticated with the FB user-id and $this->get('security.context')->getToken()->getUser() also returns the user id but as Symfony\Bundle\FrameworkBundle\Controller->getUser() calls for $user to be an object, everything else fails.

I have followed the docs but in my FacebookProvider the loadUserByUsername method is not called at every request (I am not sure if it should be called).

Also I am not declaring the provider in the firewall section as when I do I get redirected to the /login which is an unhandled, non-existing route (when I've tried to declare it in the routing I still get an exception).

Also the user doesn't have any role or any other related info, it's practically just a string representing the facebook userid of the logged-in user.

security.yml

providers:
        my_facebook_provider:
            id: my.fb.user

firewalls:
        public:
            # since anonymous is allowed users will not be forced to login
            pattern:   ^/.*
            fos_facebook:
                app_url: "http://apps.facebook.com/muttery"
                server_url: "http://muttery.rares.webicks.com/"
                login_path: /loginFB
                check_path: /login_check
                default_target_path: /
\#                provider: my_facebook_provider
            anonymous: true
            logout:
                handlers: ["fos_facebook.logout_handler"]

routing.yml

webicks_muttery:
    resource: "@WebicksMutteryBundle/Controller/"
    type:     annotation
    prefix:   /

_assetic:
    resource: .
    type:     assetic

_security_check:
    pattern:  /login_check
_security_logout:
    pattern:  /logout
_security_login:
    pattern:  /loginFB

services.yml

services:
    my.fb.user:
        class: Webicks\MutteryBundle\Security\User\Provider\FacebookProvider
        arguments:
            facebook: "@fos_facebook.api"
            userManager: "@fos_user.user_manager"
            validator: "@validator"
            container: "@service_container"
diegoholiveira commented 11 years ago

This issue is solved?

ghost commented 11 years ago

i have the same problem! did you get the answer?

Chrysweel commented 11 years ago

I have the same question.

Take an example of a user named JAMES. If James from my web logs with facebook everything works correctly, he can use all the functionalities for a user, but if James logged into facebook and go to my site, he is not recognized as a user of the application

All functionalities of dependende app.user {% if%} for example not working.

Login button recognizes James but nothing else.

Someone knows how to fix this?

bartmfc commented 11 years ago

I have the same problem. Have someone found a solution?

bartmfc commented 11 years ago

I found the problem in my code. I've forgotten provider in firewalls: firewalls: main: pattern: ^/ fos_facebook: provider: fos_facebook_provider #Problem

After add provider everything seems to be fine.