Module for ZF2 which allows the developer to implement Facebook. Twitter, Google and Linked in connect using their own database storage for the user.
Module for ZF2 which allows the developer to implement Facebook. Twitter, Google and Linked in connect using their own database storage for the user. layer.
Install the module via composer by running:
php composer.phar require middleout/third-party-connect:dev-master
or download it directly from github and place it in your application's
ThirdPartyConnectmodule to the module section of your
./config/autoload/third-party-connect.local.php. Change any settings in it according to your needs.
Define your public/private keys in the third-party-connect.local.php
Define the permissions for facebook in the same file (you can find the definition in the class FacebookService)
Define the route for the return URL.
Make an "a" tag with the href like this:
<a href="$this->url('third-party-connect', array('controller' => 'authorize', 'action' => 'facebook'), true);">Connect with facebook</a>
the action can be one of the following: facebook, twitter, linkedin, google
If you want to show a popup window, set in the config file the "use_popup" to true.
In your controller/action retrieve from the service manager one of the following keys (depending on what you did) $serviceManager->get('facebookConnect') $serviceManager->get('twitterConnect') $serviceManager->get('googleConnect') $serviceManager->get('linkedinConnect')
and then run on this object the method getUserData()
this method may return false if there was an error (like decline permissions). It is up to you to treat the error cases due to the fact that you get the information in the URL. However there is a method called "hasErrors()" which already knows what to look for in the $_GET for errors.
all 4 services return the same array of user data (normalized) so you don't have to worry about it.