I am facing "The token could not be parsed from the request" error in JWT in Laravel.
I have tried same code in localhost(Xampp in windows 7) it is working but on server it is not working.
I have passed "Authorization" token in header and also changed .htaccess file.
Please check below screenshot for passed token in request in angular 2.
Below is .htaccess file. (I have also tried this code in root .htaccess file and public .htaccess file both)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php/$1 [L]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
</IfModule>
And I have used below code for authenticated token.
public function image_upload(Request $request){
try{
if($user = JWTAuth::parseToken()->authenticate()){
\Api::success(['data' => $user]);
}else{
\Api::error("User is not found.");
}
}
catch(\Tymon\JWTAuth\Exceptions\TokenExpiredException $e){
\Api::error(['type'=> 'expired','message' => 'Your login has been expired. Please login and try again.']);
exit();
}
catch(\Tymon\JWTAuth\Exceptions\TokenInvalidException $e){
\Api::error(['type'=> 'invalid','message' => $e->getMessage()]);
exit();
}
catch(\Tymon\JWTAuth\Exceptions\JWTException $e){
\Api::error(['type'=> 'invalid','message' => $e->getMessage()]);
exit();
}
}