title: Laravel 5.2 Socialite Facebook API login redirect error
body: <p>My Facebook login has suddenly stopped working using the Socialite package with Laravel 5.2. I have had it fully functional for a few days now and it just seems to of dropped off. I am fairly new to Laravel so please have some grace if it is something easy.</p>
  
  <p>I get this error: </p>
  
  <p><strong><em>"The www.facebook.com page isn’t working. www.facebook.com redirected you too many times."</em></strong></p>
  
  <p>I have tried restarting the local server, running commands like <code>php artisan config:clear</code>. Also tried installing with composer running version <code>"laravel/socialite": "^2.0"</code>. I can't help but think it is something actually in the Facebook Developer Apps API config but everything looks okay! </p>
  
  <p>I will provide my code just in case anyone who has the time to help and can spot any bugs. I used this link as a guide to go off <a href="https://blog.damirmiladinov.com/laravel/laravel-5.2-socialite-facebook-login.html#.WK8bGBKLRBw" rel="nofollow noreferrer">https://blog.damirmiladinov.com/laravel/laravel-5.2-socialite-facebook-login.html#.WK8bGBKLRBw</a> </p>
  
  <p><strong>.env</strong></p>
  
  <pre><code>FACEBOOK_CLIENT_ID=xxxxxxxxx
  FACEBOOK_CLIENT_SECRET=xxxxxxxx
  FACEBOOK_CALLBACK_URL=http://localhost:8000/auth/facebook/
  </code></pre>
  
  <p><strong>routes.php</strong></p>
  
  <pre><code>Route::get('auth/facebook',  'Auth\FacebookController@redirectToProvider');
  Route::get('auth/facebook/callback',  'Auth\FacebookController@handleProviderCallback');
  </code></pre>
  
  <p><strong>FacebookController.php</strong></p>
  
  <pre><code>namespace App\Http\Controllers\Auth;
  
  use Illuminate\Http\Request;
  
  use App\Http\Requests;
  use App\Http\Controllers\Controller;
  use App\SocialAccountService;
  use Socialite;
  
  
  class FacebookController extends Controller
  {
  
      public function redirectToProvider()
      {
  
         //send off a request and to FB and get a token
         return Socialite::driver('facebook')-&gt;redirect();
  
      }
  
      public function handleProviderCallback(SocialAccountService $service)
      {
  
          $user = $service-&gt;createOrGetUser(Socialite::driver('facebook')-&gt;user());
  
          auth()-&gt;login($user);
  
          return redirect()-&gt;to('account/{id}/myaccount');
      }
  }
  </code></pre>
  
  <p><strong>SocialAccountService.php</strong></p>
  
  <pre><code>namespace App;
  
  use Laravel\Socialite\Contracts\User as ProviderUser;
  
  class SocialAccountService
  {
      public function createOrGetUser(ProviderUser $providerUser)
      {
  
          $account = SocialAccount::whereProvider('facebook')
              -&gt;whereProviderUserId($providerUser-&gt;getId())
              -&gt;first();
  
          if ($account) {
              return $account-&gt;user;
          } else {
  
              $account = new SocialAccount([
                  'provider_user_id' =&gt; $providerUser-&gt;getId(),
                  'provider' =&gt; 'facebook'
              ]);
  
              $user = User::whereEmail($providerUser-&gt;getEmail())-&gt;first();
  
              if (!$user) {
  
                  $user = User::create([
                      'email' =&gt; $providerUser-&gt;getEmail(),
                      'name' =&gt; $providerUser-&gt;getName(),
                  ]);
              }
  
              $account-&gt;user()-&gt;associate($user);
              $account-&gt;save();
  
              return $user;
  
          }
  
      }
  }
  </code></pre>