title: Laravel 5.1 - Facebook Authentication through Socialite
body: <p>I am trying to implement Facebook Login to my project however I receive an error:</p>
  
  <blockquote>
    <p>ClientException in Middleware.php line 69:
    Client error: 400</p>
    
    <ol>
    <li><p><em>in /Applications/MAMP/htdocs/laratest/vendor/guzzlehttp/guzzle/src/Middleware.php line 69</em></p></li>
    <li><p><em>at Middleware::GuzzleHttp{closure}(object(Response)) in Promise.php line 199</em></p></li>
    <li><p><em>at Promise::callHandler('1', object(Response), array(object(Promise), object(Closure), null)) in Promise.php line 152</em></p></li>
    <li><p><em>at Promise::GuzzleHttp\Promise{closure}() in TaskQueue.php line 60</em></p></li>
    <li><p><em>at TaskQueue->run() in CurlMultiHandler.php line 96</em></p></li>
    </ol>
  </blockquote>
  
  <hr>
  
  <p>Steps I've gone through:</p>
  
  <ul>
  <li><p><code>composer require laravel/socialite</code> &amp; <code>composer update</code>.</p></li>
  <li><p>In my <em>config>services.app</em>, </p></li>
  </ul>
  
  <p><code>'facebook' =&gt; [
          'client_id' =&gt; env('FB_CLIENT_ID'),
          'client_secret' =&gt; env('FB_SECRET_ID'),
          'redirect' =&gt; 'http://localhost.com:8888',
  ],</code></p>
  
  <ul>
  <li><p>Added 
  <code>Laravel\Socialite\SocialiteServiceProvider::class,</code> &amp; <code>'Socialite' =&gt; Laravel\Socialite\Facades\Socialite::class,</code> in <em>config>app.php</em></p></li>
  <li><p>Set up the routes successfully.</p></li>
  </ul>
  
  <p><code>Route::get('auth/facebook', 'Auth\AuthController@redirectToProvider');
  Route::get('auth/facebook', 'Auth\AuthController@handleProviderCallback');</code></p>
  
  <ul>
  <li><p>Setup the link successfully in my blade file. <code>Login with Facebook</code></p></li>
  <li><p>In my <em>Controller>AuthController.php</em>, I added:</p>
  
  <pre><code>use Laravel\Socialite\Facades\Socialite;
  
  ** Beside everything that AuthController has, inside the AuthController class, I added:**
  
    public function redirectToProvider()
     {
      return Socialite::driver('facebook')
           -&gt;scopes(['scope1', 'scope2'])-&gt;redirect();
     }
  
  /**
   * Obtain the user information from Facebook.
   *
   * @return Response
   */
  
     public function handleProviderCallback()
      {
        $user = Socialite::driver('facebook')-&gt;user();
  
      // $user-&gt;token;
      }
  </code></pre></li>
  <li><p>Also users table:</p>
  
  <pre><code>   public function up()
      {
         Schema::create('users', function (Blueprint $table) {
            $table-&gt;increments('id');
            $table-&gt;string('username');
            $table-&gt;string('name');
            $table-&gt;string('email')-&gt;unique();
            $table-&gt;string('password', 60);
            $table-&gt;string('avatar');
            $table-&gt;string('provider');
            $table-&gt;string('provider_id');
            $table-&gt;rememberToken();
            $table-&gt;timestamps();
              });
      }
  </code></pre></li>
  </ul>
  
  <p><strong>Edit:</strong>
  When I comment out <code>$user = Socialite::driver('facebook')-&gt;user();</code> part, I get redirected to <code>localhost.com/auth/facebook</code></p>
  
  <p><strong>Edit 2:</strong>
  My <code>.env</code> file:</p>
  
  <p><code>'facebook' =&gt; [
          FB_CLIENT_ID =&gt; '###',
          FB_SECRET_ID =&gt; 'this-is-secret!',
  ],</code></p>