The controller is called from a route. The path /oauth maps to the oauthAction and /ajax maps to the ajaxAction. The main difference between these two actions is how they respond. Oauth redirects the page and ajax responds in JSON.
I previously had written about using the Facebook SDK inside of Zend Framework. It did not go very deep into actually using the Facebook SDK. In this post I will show you how to use it as a login system. But wait there is more. I will also show you how to use Twitter, Google, and essentially any other service you want. I use the abstraction that Zend Framework gives you for authentication and add one more layer to that so that you can easily plug in new services to authenticate to.
Zend Framework Setup
This is a basic Zend Framework 1.11 install. I did make a few modifications to it. Because one of the authentication methods is OpenId using Google you have to patch the Zend_Openid_Consumer. You can see this why in the Zend Framework issue browser. The other is a way to read attributes from OpenID. This was written by Chris Bisnett. That is the only modifications to the core of Zend Framework. You will want to make sure that you have the most current version of the Facebook SDK. The included Facebook SDK is 3.1.1.
It doesn’t matter if use Zend or not, you can follow along and use the code in your project as well.
Setup Zend Framework
First thing to do is download the latest version of Zend Framework. It is a free download, but you will have to create an account. If you don’t use Zend Framework (ZF from here on out) you really should. It is very extensible and versatile. I won’t continue to try and sell you on ZF (and most likely you already are using it).
Next thing to do is setup a project (of course if you have a project just use that). I won’t go into how to do this, but there is a great quickstart tutorial on Zend’s site that is a great introduction if you haven’t used ZF before.
You should now have the default ZF page if all is working correctly.