tymondesigns / jwt-auth

šŸ” JSON Web Token Authentication for Laravel & Lumen
https://jwt-auth.com
MIT License
11.23k stars 1.55k forks source link

In laravel jwt verify token always return XHR status:200 in testand in postman is working perfectly. #137 #1715

Open kalpeshaexonic opened 5 years ago

kalpeshaexonic commented 5 years ago

Api.php middleware jwt verify token

Route::group(['middleware' => ['jwt.verify']], function() {
        Route::get('getAuthenticatedUser', 'userController@getAuthenticatedUser');
  });

It's always return 200 status whether token is valid or not . if we are not added header still it get 200 status.

jwt.auth middleware (its always return 401 whether token is not valid )

Route::group(['middleware' => 'jwt.auth'], function () {
    Route::get('getAuthenticatedUser2', 'userController@getAuthenticatedUser')->name('getAuthenticatedUser2');
});

auth:api middleware (its always return 401 whether token is not valid )

Route::group(['middleware' => 'auth:api'], function () {
    Route::get('getAuthenticatedUser3', 'userController@getAuthenticatedUser')->name('getAuthenticatedUser3');
});

Authjwt middleware file.

try {
            $user = JWTAuth::parseToken()->authenticate();
             } catch (Exception $e) {
            if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException){
                return response()->json(['code'=>404,'message' => 'Token is Invalid'],404);
            }else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException){
                return response()->json(['code'=>404,'message' => 'Token is Expired'],404);
            }else{
                return response()->json(['code'=>404,'status' => 'Authorization Token not found']);
            }
        }
        return $next($request);
    }

Apache .htaccess file

  # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Even i try different coding still not working.

https://blog.pusher.com/laravel-jwt/
https://github.com/tymondesigns/jwt-auth/wiki/Authentication
https://github.com/tymondesigns/jwt-auth/issues/1632
https://blog.pusher.com/laravel-jwt/

If the token is not valid the status always return 200. What's the issue? How I can solve the bug

omajaqui commented 4 years ago

I can solve it, I have the same problem, help.

stale[bot] commented 3 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

camilosama commented 3 years ago

any one have the solution, I try all and i canĀ“t find any solution.