Silex-SocialFactory
Social authentication classes to use with Silex. You could use it with any framework or code, but you will have to change the session provider.
Even it's ment to act as a factory, I've added methods as createTwitter so I can hardcode the return type and this way use the autocomplete functionallity of IDEs.
Dependencies
For Twitter we use Abraham's OAuth class: https://github.com/abraham/twitteroauth/
For Facebook we use Facebook's official class: https://github.com/facebook/facebook-php-sdk/
Examples
Login function returns the social ID of the user. Auth functions returns ReturnObject which is an unified format for the basic info: social ID, email (if given), avatar and the metadata as an array.
Login
$twitterObject = SocialFactory::createTwitter($app);
$twitterObject->setConsumerKey($twitterData['key']);
$twitterObject->setConsumerSecret($twitterData['secret']);
$twitterObject->setCallbackURL($config['application.host'] . 'login/twitter/auth/');
$redirectUrl = $twitterObject->login();
Auth
$twitterObject = SocialFactory::createTwitter($app);
$twitterObject->setConsumerKey($twitterData['key']);
$twitterObject->setConsumerSecret($twitterData['secret']);
$twitterObject->setOAuthToken($oAuthToken);
$twitterObject->setOAuthVerifier($oAuthVerifier);
$result = $twitterObject->auth();
Returns the social ID of the user. Login
$facebookObject = SocialFactory::createFacebook($app);
$facebookObject
->setAppId($config['facebook.appid'])
->setSecret($config['facebook.secret']);
$result = $facebookObject->login();
Returns the data of the user. Auth
$facebookObject = SocialFactory::createFacebook($app);
$facebookObject
->setAppId($config['facebook.appid'])
->setSecret($config['facebook.secret']);
$result = $facebookObject->auth();