FriendsOfSymfony / FOSFacebookBundle

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

refreshUser method in FacebookProvider : There is no user provider for user "Acme\DemoBundle\Entity\User" #75

Closed bellecp closed 12 years ago

bellecp commented 13 years ago

After following all the instructions from FOSUserBundle and FOSFacebookBundle to set up an external facebook auth that triggers symfony security mechanism, I ended up with the error :

There is no user provider for user "Acme\DemoBundle\Entity\User".

when accessing /login_check (redirected from facebook.com) The exception was thrown in the refreshUser method.

It seemed that at this point, $user had a username but no facebookId. Adding the proposed line solves the issue. (but is it the good way to solve it ?...)

qpleple commented 13 years ago

I ran also into this bug and this patch fixed it.

lsmith77 commented 13 years ago

this sounds fishy to me. not sure if something has changed some where else, but i don't see why we would need to set the Facebook id based on the username inside refresh user. this defiantly looks like the wrong fix, but i am not sure why it would even be needed to begin with.

stof commented 13 years ago

I think I know what the issue is: the facebook id may not be part of the serialized data so it is not available when unserializing the data. the good fix in this case would be to extend the serialization defined by FOSUserBundle:

<?php

use FOS\UserBundle\Entity\User as BaseUser

class User extends BaseUser
{
// ...

    public function serialize()
    {
        return serialize(array($this->facebookId, parent::serialize()));
    }

    public function unserialize($data)
    {
        list($this->facebookId, $parentData) = unserialize($data);
        parent::unserialize($parentData);
    }
}
lsmith77 commented 13 years ago

then again if the user name is the Facebook id, then maybe the if statement in refreshUser() should just be adapted.

stof commented 13 years ago

yeah, if it is the username, the statement need to be adapted, or the getFacebookId method to return the username

lsmith77 commented 13 years ago

that code is taken from the LiipHelloBundle .. would be nice if someone could look into our comments to see if you can come up with a proper fix .. otherwise i will check if i can get it to work inside the LiipHelloBundle ..