/Silex-SocialFactory

Social authentication classes to use with Silex: Twitter, Facebook,... You could use it with whatever, but you will have to change the session provider.

Primary LanguagePHPMIT LicenseMIT

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.

Twitter

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();

Facebook

Login

Returns the social ID of the user.
$facebookObject = SocialFactory::createFacebook($app);
$facebookObject
	->setAppId($config['facebook.appid'])
	->setSecret($config['facebook.secret']);

$result = $facebookObject->login();

Auth

Returns the data of the user.
$facebookObject = SocialFactory::createFacebook($app);
$facebookObject
	->setAppId($config['facebook.appid'])
	->setSecret($config['facebook.secret']);

$result = $facebookObject->auth();