FriendsOfSymfony/FOSFacebookBundle — Issue #121: Unclear custom UserProvider example in the documentation
Author: adurieux
Created: 2012-02-19 18:44:16+00:00
State: open

I recently dicovered a couple of bugs in my app that made me though that the **Custom User Provider using the FOS\UserBundle** example of the documentation is pretty unclear :

When I first implemented it, it seemed clear to me that this would allow me to use the FOSFacebookBundle **in addition** to the FOSUserBundle. But, depending how you setup you configuration, the FacebookProvider might be the only one to get called, thus preventing standard form login.

For instance, my configuration was working perfectly fine when login through a form or through the Facebook button (because each UserProvider was called independantly by two separate routes in this case), but was failing to authenticate the user from its remember_me cookie as soon as the session had expired (because the RememberMeListenner was only calling the FacebookProvider in this case).

A possible quick and dirty fix is to modify the way a user is identified in the FacebookProvider :

```
$user = $this->findUserByFbId($username);
if(!$user){
$user = $this->userManager->findUserBy(array('username'=>$username));
}
```

Even though it might not be the most standard case, I feel like this case should at least be mentioned in the documentation.

Please also note that it's **EXTREMELY** important that the `facebookId` column is a `VARCHAR`. It's not completely obvious since most of the facebookIds are integers, but, if saved as an `ÌNT`, the `findUserBy` method will return every row that is not `NULL`.