title: Laravel 5 auth guard with RESTful API
body: <p>I have a solution developed which uses <code>Laravel 5</code>. It's not entirely developed on laravel.</p>
  <p>API layer resides on another project and only the web layer uses laravel.</p>
  <p>So far I have been storing the auth details in session and using basic way to handle authenticated users.</p>
  <p>Now I have been trying to upgrade the web app structure into <code>laravel frontend &amp; backend</code> module. The difficulty that I'm facing is to use the <code>providers</code> &amp; <code>guards</code> concept as it doesn't interact with the database directly.</p>
  <p>So far what I have done is the controller I'm checking user's role and is authenticated using <code>$_Session</code>.</p>
  <p>It would be really helpful if one could enlighten me on using RESTful API with Laravel Auth guards.</p>
  <h1>Registration controller</h1>
  <pre><code>    &lt;?php
  
  namespace App\Http\Controllers;
  
  require_once dirname(__DIR__, 3) . '/web_api/DependencyManager.php';
  
  use DBHandlers;
  use Facebook;
  use Google;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\Mail;
  use SessionManager;
  use Session;
  
  class RegisterController extends Controller
  {
      public function mRegister($ref = null)
      {
          $session = new SessionManager();
          $db = new DBHandlers();
  
  
          isset($ref) &amp;&amp; $ref == 'google' ? $registered_via_google = true : $registered_via_fb = true;
  
          if (isset($_SERVER['QUERY_STRING'])) {
              if (isset($ref)) {
                  if (strcmp($ref, &quot;facebook&quot;) == 0) {
                      $registered_via_fb = true;
                  } else {
                      $registered_via_google = true;
                  }
              }
          }
  
  
          if (isset($registered_via_fb) &amp;&amp; $registered_via_fb) {
              //  echo 'Facebook';
              try {
                  $fb = new Facebook();
                  $fb-&gt;mProcess();
                  //   echo $_GET['code'];
                  //     print_r($fb-&gt;getAcessToken());
                  $fb_access_token = (string)$fb-&gt;getAcessToken();
                  //  echo $fb_access_token;
                  if (isset($fb_access_token) &amp;&amp; $fb_access_token != '' &amp;&amp; !empty($fb_access_token)) {
                      $result = $db-&gt;mFBLogin($fb_access_token);
                      $session-&gt;LogUserIn($result);
  
                  } else {
                      $registration_error = true;
                  }
              } catch (Exception $e) {
                  $registration_error = true;
              }
  
          } 
  
      }
  
      public function mLogout()
      {
          Session::flush();
          redirect()-&gt;route('index')-&gt;send();
          die();
      }
  </code></pre>