We started working on Socnet plugin that will allow your cake apps to be easily integrated with most social network sites. For now, we coded and released FacebookAuth component, which will allows to specify which actions require facebook authentication and redirects to facebook for authentication.

Installation

To add FacebookAuth component to your project, please do the following:

1. Download the plugin code from http://github.com/loadsys/socnet and extract all the code into plugins/socnet.

2. Create an application with Facebook at http://www.facebook.com/developers/createapp.php. Set your Connect URL to <your URL>/socnet/facebook/connect.

3. Add the following configuration paramters (Configure::write):
Socnet.Facebook.enabled[0,1] – a flag to disable/enable Facebook support
Socnet.Facebook.api_key – application key (from Facebook)
Socnet.Facebook.app_secret – application secret (from Facebook)

Controller Requirements

Load FacebookAuth component where needed and specify actions that require facebook authentication:

class FacebookFriendsController extends AppControoler {
var $components = array('socnet.FacebookAuth');
var $helpers = array('socnet.Facebook');

function beforeFilter() {
parent::beforeFilter();
$this->FacebookAuth->requireLogin('index');
}

function index() {
...
}
}

Layout Requirements

Facebook helper provides all the methods needed to setup Facebook in your layout.

# Use <?php echo $facebook->htmlTag(); ?> to render the html tag. This function will setup all necessary namespaces.
# Include this line <?php echo $facebook->jsScript(); ?> somewhere in the body. This library is needed for rendering FBML scripts (ex. <fb:connect-button />).
# Add this line <script type=”text/javascript”><?php echo $facebook->jsInit(); ?></script> before </body> tag.

Please look at the sample layout file in views/layouts/facebook.ctp inside the provided plugin.

You can test the plugin integration by going to /socnet/facebook/friends. If everything is setup properly, you should get redirected to facebook for login and then see all your friends thumbs.