title: Laravel + JWT - Invalid_token error while calling next get API with received token
body: <p>I am using jwt-auth token with laravel 5. I have followed all installation steps mentioned here: <a href="https://github.com/tymondesigns/jwt-auth/wiki/Installation" rel="nofollow">https://github.com/tymondesigns/jwt-auth/wiki/Installation</a>.</p>
  
  <p>1) Called an APIs for login and received a token</p>
  
  <p>2) While using this token - Called user API with Authorization Bearer {token}  and getting response 
  {"error": "token_invalid"
  } </p>
  
  <p>Note : Tried in postman client</p>
  
  <pre><code>**route.php**
  
  Route::group(['prefix' =&gt; 'api'], function(){
  
  Route::resource('authenticate','AuthenticateController', ['only' =&gt;['index']]);
  
  Route::post('auth/login', 'AuthenticateController@authenticate');
  });
  
  **AuthenticateController.php**
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  
  use App\Http\Requests;
  use App\Http\Controllers\Controller;
  use JWTAuth;
  use Tymon\JWTAuth\Exceptions\JWTException;
  
  class AuthenticateController extends Controller
  {
     public function __construct()
     {
       // Apply the jwt.auth middleware to all methods in this controller
      // except for the authenticate method. We don't want to prevent
      // the user from retrieving their token if they don't already have it
  
       $this-&gt;middleware('jwt.auth', ['except' =&gt; ['authenticate']]);
      }
  /**
   * Display a listing of the resource.
   *
   * @return \Illuminate\Http\Response
   */
    public function index()
    {
      //
      $users = User::all();
      return $users;
  
     }
    // Login API
    public function authenticate(Request $request)
    {
      $credentials = $request-&gt;only('email', 'password');
  
      try {
          // attempt to verify the credentials and create a token for the user
          if (! $token = JWTAuth::attempt($credentials)) {
              return response()-&gt;json(['error' =&gt; 'invalid_credentials'], 401);
          }
      } catch (JWTException $e) {
          // something went wrong whilst attempting to encode the token
          return response()-&gt;json(['error' =&gt; 'could_not_create_token'], 500);
      }
  
      // all good so return the token
      return response()-&gt;json(compact('token'));
      }
  }
  </code></pre>
  
  <h2>kernel.php</h2>
  
  <pre><code>&lt;?php
  
  namespace App\Http;
  
  use Illuminate\Foundation\Http\Kernel as HttpKernel;
  
  class Kernel extends HttpKernel
  {
  /**
   * The application's global HTTP middleware stack.
   *
   * @var array
   */
  protected $middleware = [
      \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
      \App\Http\Middleware\EncryptCookies::class,
      \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
      \Illuminate\Session\Middleware\StartSession::class,
      \Illuminate\View\Middleware\ShareErrorsFromSession::class
     // \App\Http\Middleware\VerifyCsrfToken::class,
  ];
  
  /**
   * The application's route middleware.
   *
   * @var array
   */
  protected $routeMiddleware = [
      'auth' =&gt; \App\Http\Middleware\Authenticate::class,
      'auth.basic' =&gt; \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
      'guest' =&gt; \App\Http\Middleware\RedirectIfAuthenticated::class,
      'jwt.auth' =&gt; \Tymon\JWTAuth\Middleware\GetUserFromToken::class,
      'jwt.refresh' =&gt; \Tymon\JWTAuth\Middleware\RefreshToken::class
    ];
  }
  ?&gt;
  </code></pre>
  
  <h2>.htaccess</h2>
  
  <p>Added this in .htaccess file:</p>
  
  <pre><code>RewriteCond %{HTTP:Authorization} ^(.*)
  RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
  </code></pre>