In your composer.json add- "laravel/socialite": "~2.0",
"require": {
"laravel/framework": "5.0.*",
"laravel/socialite": "~2.0",
the run composer update
In config/services.php add:
//Socialite
'facebook' => [
'client_id' => '1234567890444',
'client_secret' => '1aa2af333336fffvvvffffvff',
'redirect' => 'http://laravel.dev/login/callback/facebook',
],
You need to create two routes, mine are like these:
//Social Login
Route::get('/login/{provider?}',[
'uses' => 'AuthController@getSocialAuth',
'as' => 'auth.getSocialAuth'
]);
Route::get('/login/callback/{provider?}',[
'uses' => 'AuthController@getSocialAuthCallback',
'as' => 'auth.getSocialAuthCallback'
]);
You also need to create controller for the routes above like so:
<?php namespace AppHttpControllers;
use LaravelSocialiteContractsFactory as Socialite;
class AuthController extends Controller
{
public function __construct(Socialite $socialite){
$this->socialite = $socialite;
}
public function getSocialAuth($provider=null)
{
if(!config("services.$provider")) abort('404'); //just to handle providers that doesn't exist
return $this->socialite->with($provider)->redirect();
}
public function getSocialAuthCallback($provider=null)
{
if($user = $this->socialite->with($provider)->user()){
dd($user);
}else{
return 'something went wrong';
}
}
}
and finally add Site URL to your Facebook App like so:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…