jwt-auth: Token invalid | Token Signature could not be verified.
I’m getting pretty tired of this error… Stuck for 2 days now.
I do receive a token on valid credentials, but my token stays invalid, no matter if I pass it through url parameter (?token=[token]) or as Auth header (Bearer: [token]). Anyone still experiencing this? I followed everything in the tutorial. Also configured both .htaccess in my public folder, and in my apache configuration.
Route::get('/test', function () {
return JWTAuth::parseToken()->authenticate();
});
Going to this route returns
TokenInvalidException in NamshiAdapter.php line 71:
Token Signature could not be verified.
For lookups, here is my authentication method from my AuthController.php
public function authenticate(Request $request) {
$credentials = $request->only('email', 'password');
$user = User::where('email', Input::get('email'))->first();
try {
if (!$token = JWTAuth::attempt($credentials)) {
return $this->respondUnauthorized();
}
} catch (JWTException $e) {
return $this->respondInternalError('Could not create token!');
}
// dd()
return $this->respond([
'token' => compact('token'),
'user' => $user]);
}
My routes middleware group:
Route::group(['middleware' => ['jwt.auth', 'jwt.refresh']], function() {
There must be something wrong? Is this just a minor bug or am I missing something?
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 8
- Comments: 19 (1 by maintainers)
I had been experiencing this issue as well, however I discovered the issue is having a colon
:afterbeareris actually not supported. Remove that from yourAuthorizationheader and you should be good to go.“setting the api secret in jwt.php”
in fact on config/jwt.php, there is the line’secret’ => env(‘JWT_SECRET’),
Generate the key with this helper
php artisan jwt:generate(for some reason I dont know why it doesnt set in the .env file itself likephp artisan key:generate). Copy the key (jwt-auth secret [DSvO98YtJ0204mBu9zqWN9QOMX7Tmvr9] set successfully.) without the bracket and add it in .env file likeJWT_SECRET=DSvO98YtJ0204mBu9zqWN9QOMX7Tmvr9or you can change it straigth in jwt.phpsecret' => env('DSvO98YtJ0204mBu9zqWN9QOMX7Tmvr9')remember to have your .env file in your project if you dont have do
php -r "copy('.env.example', '.env');"andphp artisan key:generate+1
I solve this issue running
php artisan jwt:secret
Hey all… for some reason this started working when I changed my auth header to be
bearer TOKENie:key:
Authorizationvalue:bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIU......Vlqb0AjEdsPreviously I used
bearer{djjdnskaF93jasdf.....FDSaM}- using the brackets{ }- which was throwing this error.My composer.json:
Thanks so much. Removing the brackets ‘{}’ worked.
Here same issue: i get randomly
Token Signature could not be verified.(but token validation performed with jwt debugger are correct). Here the stack:A pretty old project, i know…
I noticed vendor\tymon\jwt-auth\src\Providers\JWT\Namshi.php decode function takes in my token as: “: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJuYW1lIjoiTGF1cmkgRWxpYXMiLCJleHAiOjE0ODE4ODE0NjV9.PgENjq9vuTeijRrPIXIyc1ioFE1DoEzPikMZlZYsO7eJepRqj5SN354glSjqi2ozaYC2HQ1m2egi_WxH3tFifqefwhAeBAiHOuOTGQ9ZpDOUKWlM-ld8P4m3h0qEwg5hFPJ03r7lmjBKzxfU7rWPaeL3cmEOlfX4OWGRXAdUvcs” (notice the colon and space)
If I add a rather blunt workaround:
My tests go green.