I try to implement Facebook Login for my project, but I get an error message:
ClientException in line Middleware.php 69: Client error: 400
in / Applications / MAMP / htdocs / laratest / vendor / guzzlehttp / guzzle / src / Middleware.php line 69
in Middleware :: GuzzleHttp {clos} (object (response)) in Promise.php line 199
in Promise :: callHandler ('1', object (Response), array (object (Promise), object (Closure), null)) in the line Promise.php 152
in Promise :: GuzzleHttp \ Promise {close} () in the line TaskQueue.php 60
in TaskQueue-> run () in the line CurlMultiHandler.php 96
The steps that I went through:
'facebook' => [
'client_id' => env('FB_CLIENT_ID'),
'client_secret' => env('FB_SECRET_ID'),
'redirect' => 'http://localhost.com:8888',
],
Added
Laravel\Socialite\SocialiteServiceProvider::class,and 'Socialite' => Laravel\Socialite\Facades\Socialite::class,in the config> app.php
Set up routes successfully.
Route::get('auth/facebook', 'Auth\AuthController@redirectToProvider');
Route::get('auth/facebook', 'Auth\AuthController@handleProviderCallback');
. Login with Facebook
> AuthController.php :
use Laravel\Socialite\Facades\Socialite;
** Beside everything that AuthController has, inside the AuthController class, I added:**
public function redirectToProvider()
{
return Socialite::driver('facebook')
->scopes(['scope1', 'scope2'])->redirect();
}
/**
* Obtain the user information from Facebook.
*
* @return Response
*/
public function handleProviderCallback()
{
$user = Socialite::driver('facebook')->user();
// $user->token;
}
:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('username');
$table->string('name');
$table->string('email')->unique();
$table->string('password', 60);
$table->string('avatar');
$table->string('provider');
$table->string('provider_id');
$table->rememberToken();
$table->timestamps();
});
}
Edit:
$user = Socialite::driver('facebook')->user();, localhost.com/auth/facebook
2:
.env :
'facebook' => [
FB_CLIENT_ID => '###',
FB_SECRET_ID => 'this-is-secret!',
],