Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
{
"name": "mmanos/laravel-social",
"name": "chaospower/laravel-social",
"description": "A social login package for Laravel 4.",
"keywords": ["laravel", "social", "login", "providers", "oauth"],
"authors": [
{
"name": "Mark Manos",
"email": "[email protected]"
},
{
"name": "Randy Glenn Aguirre",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.4.0",
"illuminate/support": ">=4.1",
"lusitanian/oauth": "~0.3"
"illuminate/support": "~4|~5",
"chaospower/phpoauthlib": "~0.4"
},
"autoload": {
"classmap": [
Expand Down
37 changes: 20 additions & 17 deletions src/Mmanos/Social/Social.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class Social
* @var \OAuth\ServiceFactory
*/
protected $factory;

/**
* The Service Storage instance.
*
* @var \OAuth\Common\Storage\TokenStorageInterface
*/
protected $storage;

/**
* Create a new Social instance.
*
Expand All @@ -33,59 +33,62 @@ public function __construct()
$this->factory = new ServiceFactory;
$this->storage = new Session;
}

/**
* Return an instance of the requested service.
*
* @param string $provider
* @param string $url
* @param array $scope
*
*
* @return \OAuth\Common\Service\AbstractService
* @throws \Exception
*/
public function service($provider, $url = null, $scope = null)
public function service($provider, $url = null, $scope = null, $api_version = null)
{
$info = Config::get('laravel-social::providers.' . strtolower($provider));

if (empty($info) || !is_array($info)) {
throw new Exception('Missing configuration details for Social service: ' . $provider);
}

$client_id = array_get($info, 'client_id');
$client_secret = array_get($info, 'client_secret');
$scope = is_null($scope) ? array_get($info, 'scope') : $scope;


$client_id = array_get($info, 'client_id');
$client_secret = array_get($info, 'client_secret');
$scope = is_null($scope) ? array_get($info, 'scope') : $scope;
$api_version = is_null($api_version) ? array_get($info,'api_version') : $api_version;

if (empty($client_id) || empty($client_secret)) {
throw new Exception('Missing client id/secret for Social service: ' . $provider);
}

return $this->factory->createService(
ucfirst($provider),
new Credentials($client_id, $client_secret, $url ?: URL::current()),
$this->storage,
$scope
$scope,
null,
$api_version
);
}

/**
* Return the OAuth spec used by the given service provider.
*
* @param string $provider
*
*
* @return integer
*/
public function oauthSpec($provider)
{
$service = $this->service($provider);

if (false !== stristr(get_class($service), 'OAuth1')) {
return 1;
}
else if (false !== stristr(get_class($service), 'OAuth2')) {
return 2;
}

return null;
}
}
8 changes: 4 additions & 4 deletions src/Mmanos/Social/SocialServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SocialServiceProvider extends ServiceProvider
* @var bool
*/
protected $defer = false;

/**
* Bootstrap the application events.
*
Expand All @@ -21,7 +21,7 @@ class SocialServiceProvider extends ServiceProvider
public function boot()
{
$this->package('mmanos/laravel-social');

if ($route = Config::get('laravel-social::route')) {
Route::get($route . '/login/{provider}', array(
'as' => 'social-login',
Expand All @@ -34,7 +34,7 @@ public function boot()
Route::controller($route, 'Mmanos\Social\SocialController');
}
}

/**
* Register the service provider.
*
Expand All @@ -46,7 +46,7 @@ public function register()
return new \Mmanos\Social\Social;
});
}

/**
* Get the services provided by the provider.
*
Expand Down
10 changes: 5 additions & 5 deletions src/Mmanos/Social/SocialTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ public function providers()
{
return $this->hasMany('Mmanos\Social\Provider');
}

/**
* Return the reqeusted social provider associated with this user.
*
* @param string $name
*
*
* @var Provider
*/
public function provider($name)
{
$providers = $this->providers->filter(function ($provider) use ($name) {
return strtolower($provider->provider) == strtolower($name);
});

return $providers->first();
}

/**
* Return true if this user has connected to the requested social provider.
* False, otherwise.
*
* @param string $name
*
*
* @var boolean
*/
public function hasProvider($name)
Expand Down
1 change: 1 addition & 0 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'client_id' => '',
'client_secret' => '',
'scope' => array('email'),
'api_version' => 'v2.2',
'fetch_user_info' => function ($service) {
$result = json_decode($service->request('/me'), true);
return array(
Expand Down
Loading