title: Laravel Socialite Facebook error: "POST https://graph.facebook.com/oauth/access_token resulted in a `400 Bad Request` "
body: <p>I've made social login using <code>Laravel Socialite</code> for facebook and it was working fine. I haaven't changed anything and now it's not working. It shows this error when trying to login:</p>
  
  <p><code>Client error:</code>POST <a href="https://graph.facebook.com/oauth/access_token" rel="noreferrer">https://graph.facebook.com/oauth/access_token</a><code>resulted in a</code>400 Bad Request<code>response:
  {"error":{"message":"This IP can't make requests for that application.","type":"OAuthException","code":5,"fbtrace_id":"D (truncated...)</code></p>
  
  <p>I haven't changed setting in my facebook app, nor in my code.
  My code is the following:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Route::get('login', ['as' =&gt;'getLogin', 'uses'=&gt;'Auth\AuthController@getLogin']);
  Route::get('handleProviderCallback/{provider}', 'Auth\AuthController@handleProviderCallback');</code></pre>
  </div>
  </div>
  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>public function login($provider = false)
      {
       if(!$provider) {
              $user = Input::all();
              $auth_user = new AuthenticateUser();
              $is_logged = $auth_user-&gt;findByEmailOrCreate($user, false);
              if($is_logged) {
  
                  Session::put('user', Auth::user());
                  Session::put('user_id', Auth::user()-&gt;id);
                  Session::put('email', Auth::user()-&gt;email);
                  Session::put('name', Auth::user()-&gt;name);
  
                  return redirect()-&gt;intended('dashboard');
              }
              return redirect('/')-&gt;withInput()-&gt;with('error', 'Wrong username or password!');
          }
          return \Socialite::with('facebook')-&gt;redirect();
      }
      
      public function handleProviderCallback($provider=false) {
          if(Input::has('code')) {
              $user = \Socialite::with($provider)-&gt;user();
              $auth_user = new AuthenticateUser();
              $provider_user = $auth_user-&gt;findByEmailOrCreate($user, $provider);
              Session::put("user", array($provider_user));
              Session::put('user_id', $provider_user-&gt;id);
              Session::put('email',$provider_user-&gt;email);
              Session::put('name',$provider_user-&gt;name);
  
              return redirect('dashboard');
          }
      }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Problem appears in <code>handleProviderCallback</code> method in this line:</p>
  
  <p><code>$user = \Socialite::with($provider)-&gt;user();</code>.</p>
  
  <p>When I only dump this:
  <code>$user = \Socialite::with($provider)</code></p>
  
  <p>it shows data but when it is used like that to get user data it returns the error:</p>
  
  <p><code>$user = \Socialite::with($provider)-&gt;user();</code></p>
  
  <p>In <code>config/services.php</code> I've set settings like this example:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  'facebook' =&gt; [
          'client_id' =&gt; 'my-client-id-from-fb-app', 
          'client_secret' =&gt; 'my-secret-code-from-fb-app', 
          'redirect' =&gt; 'http://my-example-domain/my-site/handleProviderCallback/facebook'
      ],</code></pre>
  </div>
  </div>
  </p>
  
  <p>In my facebook app I've set in settings:</p>
  
  <p><code>App Domains: my-example-domain,
  Privacy Policy URL: http://my-example-domain/my-site/,
  Site URL: http://my-example-domain/my-site/handleProviderCallback/facebook,
  Valid OAuth redirect URIs: http://my-example-domain/my-site/handleProviderCallback/facebook</code></p>