I was slaving over a hot keyboard all Friday!
But at last it is done – FBConnect for sfGuard.
A detailed explanation of how to install it and use it is on the Symfony site.
Anyway, the plugin basically just introduces a new table to keep track of Facebook IDs <---> sfGuardUserIds
Here’s a fun nugget. One of the problems with using FB Connect is that you can’t mug a user’s email address from Facebook. Obviously this is a smart move on Facebook’s part but it makes life hard for my Nigerian spammer friends. If you want to snag a user’s email address (or anything else for that matter) while still using Facebook Connect here’s a sketch of how to do it.
Everything is the same except you can’t use Facebook’s FBML to render the FB Connect button. What you want to do instead is trigger the “connect” event by hand. Here is basically how we do it:
- The user requests to sign up.
- We pop up a Lightbox using Thickbox
- We ask the user for their email address and verify that is valid and unique via AJAX in the background.
- The validation routing sets an attribute on the user using setAttribute() that contains the entered email address.
- We close the Lightbox and initiate a Facebook Connect request with FB.Connect.requireSession
- In our createFbUser() method we get the attribute back and save it with the new user
Bam. Got the user’s email address and logged them in via FB Connect.