title: Facebook login in laravel 5.2 can't hold the session after redirect
body: <p>I am using Facebook PHP SDK to log my user.</p>
  
  <p>I created a guard called login for this</p>
  
  <p><strong>Here is my config file of auth.php</strong></p>
  
  <pre><code>'guards' =&gt; [
      'web' =&gt; [
          'driver' =&gt; 'session',
          'provider' =&gt; 'users',
      ],
  
      'api' =&gt; [
          'driver' =&gt; 'token',
          'provider' =&gt; 'users',
      ],
      'admin'=&gt;[
          'driver'=&gt;'session',
          'provider'=&gt;'adminusers',
      ],
      'verify'=&gt;[
          'driver'=&gt;'session',
          'provider'=&gt;'verify',
      ],
      'login'=&gt;[
          'driver'=&gt;'session',
          'provider'=&gt;'users'
      ]
  ],
  </code></pre>
  
  <p>to access Facebook api i created a class in App\services namespace called it Facebook </p>
  
  <p><strong>App\Services\Facbook.php</strong></p>
  
  <pre><code>&lt;?php
  namespace App\Services;
  
  use Illuminate\Support\Facades\Cache;
  use Illuminate\Support\Facades\Config;
  
  use App\Extensions\Facebook\FacebookLaravelPersistentDataHandler; 
  use Facebook\Facebook as FB;
  use App;
  
  class Facebook{
  
  protected $fb;
  
  protected $helper;
  
  protected $permission;
  
  protected $log;
  
  protected $canvashelper;
  
  protected $persistentDataHandler;
  
  function __construct()
  {
      $this-&gt;fb   =   new FB([
                      'app_id'=&gt;Config::get('facebook.app_id'),
                      'app_secret'=&gt;Config::get('facebook.app_secret'),
                      'default_graph_version' =&gt; Config::get('facebook.default_graph_version'),
                      'persistent_data_handler' =&gt; new FacebookLaravelPersistentDataHandler(),
                      ]);
  
      $this-&gt;helper = $this-&gt;fb-&gt;getRedirectLoginHelper();
  
      $this-&gt;permission = Config::get('facebook.permission');
  
      $this-&gt;log = new Logging(Config::get('facebook.logfile'),'Facebook Log');
  
      $this-&gt;canvashelper =   $this-&gt;fb-&gt;getCanvasHelper();
  
      $this-&gt;persistentDataHandler = new FacebookLaravelPersistentDataHandler();
  }
  
  public function FBAuthUrl()
  {
      if($this-&gt;isFBAuth())
      {
          return $this-&gt;helper-&gt;getLogoutUrl($this-&gt;persistentDataHandler-&gt;get('facebook_access_token'),route('facebook.logout'));
      }
      else
      {
          return $this-&gt;helper-&gt;getLoginUrl(route('facebook.callback'),$this-&gt;permission);
      }
  }
  
  public function LoginCallback()
  {           
      $accessToken = $this-&gt;helper-&gt;getAccessToken(); 
      if(isset($accessToken))
      {   
          $this-&gt;persistentDataHandler-&gt;set('facebook_access_token',(string) $accessToken);
      }
  
  }
  
  public function isFBAuth()
  {
      return $this-&gt;persistentDataHandler-&gt;has('facebook_access_token');
  }
  
  public function getFBUser()
  {
      if($this-&gt;isFBAuth())
      {
          $this-&gt;fb-&gt;setDefaultAccessToken($this-&gt;persistentDataHandler-&gt;get('facebook_access_token'));
          /*,user_birthday,user_tagged_places*/
          $response = $this-&gt;fb-&gt;get("/me?fields=id,name,first_name,last_name,age_range,link,gender,locale,picture,timezone,updated_time,verified,email");
          return $response-&gt;getGraphUser();
      }
      else
      {
          return false;
      }
  }
  
  public function logout()
  {
      $this-&gt;persistentDataHandler-&gt;delete('facebook_access_token');
      $this-&gt;persistentDataHandler-&gt;delete('state');
  }
  
  }
  </code></pre>
  
  <p>And Here is my UserController Where i write my login logic</p>
  
  <pre><code>    class UserController extends Controller
  {
      .....
  /*
   * Facebook login callback function
   * @param Object App\services\Facebook
   * return redirect
   */
  
  public function fbLogin(Facebook $facebook)
  {
      $facebook-&gt;LoginCallback();
  
      /*
       * get the usergraphnode from facebook
       */
      $fbUser = $facebook-&gt;getFBUser();
  
      /*
       * Convert UserGraphNode User To Eloquent User
       */
      $user = $this-&gt;getFBLoggedUser($fbUser);        
  
      /*
       * Here Log the user in laravel System
       */
      Auth::guard('login')-&gt;login($user);
      //dump(Auth::guard($this-&gt;guard)-&gt;user());
      dump(session()-&gt;all());
      return reidrect('/');
  }
  
  
  public function getFBLoggedUser($fbUser)
  {
      if(User::where('email','=',$fbUser-&gt;getField('email'))-&gt;count())
      {
          $user = User::where('email','=',$fbUser-&gt;getField('email'))-&gt;first();
          if($user-&gt;fb_app_id){
              $user-&gt;fb_app_id = $fbUser-&gt;getField('id');
              $user-&gt;save();
          }
      }
      else
      {
          $user = $this-&gt;FBregister($fbUser);
      }
      return $user;
  }
  
  
  /**
   * Register The user logged in from Facebook
   *
   * @param \Facebook\GraphNodes\GraphUser;
   * 
   * return  \App\Models\User
   */
  public function FBregister($fbUser)
  {
      $user = new User();
      $user-&gt;fname = $fbUser-&gt;getField('first_name');
      $user-&gt;lname = $fbUser-&gt;getField('last_name');
      $user-&gt;gender = $fbUser-&gt;getField('gender');
      $user-&gt;email = $fbUser-&gt;getField('email');
      $user-&gt;fb_app_id = $fbUser-&gt;getField('id');
  
      $picture = $fbUser-&gt;getField('picture');
      if($picture-&gt;isSilhouette()){
          $user-&gt;profile_image = $picture-&gt;getUrl();
      }
  
      $user-&gt;save();
  
      return $user;
  }
  
  .........
  }
  </code></pre>
  
  <p>On Successful Facebook login redirect i am calling UserController@fbLogin
  after calling <code>Auth::guard()-&gt;login()</code> i dump session it successfully show a <code>login_login_randomstring=&gt;UserId</code> i session . but When i redirect it all session data lost.</p>
  
  <p>But the weird thing is that it only happen when it calling through facebook redirect. If i use this function like normal login routes it works perfactaly like this </p>
  
  <p><strong>in route.php</strong> </p>
  
  <pre><code>Route::get('/login','UserController@login');
  </code></pre>
  
  <p><strong>and in UserController</strong></p>
  
  <pre><code>function login(){
   $user = User::find(12);
   Auth::guard('login')-&gt;login($user);
   return redirect('/');
  }
  </code></pre>
  
  <p>Using this method i can easily access Session data after redirecting from here but in facebook case it doesn't happening.</p>
  
  <p>I stuck here for two days please anyone can help me</p>
  
  <p><strong><em>[Note: Please don't mention in your answer that i should grouped my routes in web middleware.  ]</em></strong></p>