jwt-auth: Token Invalid Error

I use Laravel 5.1 with jwt-auth ^0.5.9 .

After I got token value then I make get request as ?token=value, i got {"error":"token_invalid"} in the every request.

The following is my route

Route::group(['middleware' => 'jwt.auth'], function() {
    Route::get('test', function() {
        return 'Hello';
    });
});

The following is how I create token

try {
    // attempt to verify the credentials and create a token for the user
    if (! $token = JWTAuth::fromUser($user)) {
        return response()->json(['error' => 'invalid_credentials'], 401);
     }
} catch (JWTException $e) {
    // something went wrong whilst attempting to encode the token
   return response()->json(['error' => 'could_not_create_token'], 500);
}

// all good so return the token
return response()->json(compact('token'));

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (2 by maintainers)

Most upvoted comments

I just noticed that I was missing the JWT secret key, since I changed computers! That is why I had this error and the token was invalid. Adding the key with artisan jwt:generate solved this issue.

This is an installation step already covered in the Wiki : https://github.com/tymondesigns/jwt-auth/wiki/Installation

@setkyar, @lukeed : please try this and check if it solves your issue too.

I just $ composer update and it worked.

@mikepsinn Your issue seems almost the same as my. Do you have this issue only on mobile devices? I get the token invalid exception also on desktop browsers. The tokens are blacklisted to earlier. As a workaround I disabled the blacklisting. Which works good for now, but I hope there will be a fix soon, although the issue is open since 5. Aug. Maybe I will write my own blacklisting extension.

I also have this issue. Sometimes I can send 10-20 requests and all works, and sometimes I send 3 requests and I get a token is invalid exception. (The token has a correct signature.) @tymondesigns I tried to check with

Route::get('/test', function () {
   return JWTAuth::parseToken()->authenticate();
});

I got a token blacklisted exception. Any ideas?