38

I'm working on a project to learn laravel, I saw a couple of tutorials to use jwt auth in this. It was working good but now is show an error not always but I don't know why. this is it:

Argument 3 passed to Lcobucci\JWT\Signer\Hmac::doVerify() must be an instance of Lcobucci\JWT\Signer\Key, null given, called in C:\xampp\htdocs\inmobiliaria\vendor\lcobucci\jwt\src\Signer\BaseSigner.php on line 42

Sometimes it works but not another. so I don't know what can I do. I tried with

  1. php artisan cache:clear
  2. php artisan config:clear
  3. php artisan jwt:secret

but the problem still there, sometimes i get good answer from server(200) but the most part of then al bad (500).

Screenshots

enter image description here

enter image description here

Navarasu
  • 8,209
  • 2
  • 21
  • 32
Esteban
  • 485
  • 1
  • 4
  • 6
  • Can you show code where you're doing the authentication? – petersowah Nov 19 '18 at 21:52
  • The authentication isn't the problem. This error appear when i try to make class::all(); method in php: public function all() { $properties = Property::with('images')->get(); return response()->json([ 'properties' => $properties ], 200); } – Esteban Nov 20 '18 at 22:05
  • 1
    Hi @Esteban, I have the same issue, did you find the solution? – Max M. Nov 27 '18 at 11:28
  • hi @MaxM. Actually no i don't, still looking! – Esteban Nov 28 '18 at 14:21
  • I have the same issue. Type error: Argument 3 passed to Lcobucci\JWT\Signer\Hmac::doVerify() must be an instance of Lcobucci\JWT\Signer\Key, null given, called in \vendor\lcobucci\jwt\src\Signer\BaseSigner.php on line 42 It appears when I make many queries (some times it can be with similar params) – Oleksii.B Dec 17 '18 at 12:57
  • Usually it appears when I make many queries in one moment. – Oleksii.B Dec 17 '18 at 14:05

11 Answers11

89

Here's complete snippet

php artisan key:generate
php artisan jwt:secret
php artisan cache:clear
php artisan config:clear

Before run above commands make sure there is install jwt package, than check its config file name jwt.php in config folder.

Muhammad Sulman
  • 1,611
  • 1
  • 19
  • 25
30

In fact it's the right thing to solve it:

php artisan key:generate
php artisan jwt:secret
Tiago Gouvêa
  • 15,036
  • 4
  • 75
  • 81
6

This error can occur when

  • JWT_SECRET is missing on the .env
  • JWT_SECRET is commented in the .env
  • The value of JWT_SECRET is wrong.

In my case, running php artisan jwt:secret it was appending the key on the current JWT_SECRET. So checking my .env file, the value of JWT_SECRET was very long and wrong (it should be 64 chars long).

To solve it:

  1. Open the .env and remove the JWT_SECRET value (note that you have to remove it and not comment it).
  2. Run php artisan jwt:secret
  3. Run php artisan cache:clear && php artisan config:clear
Dan
  • 3,329
  • 2
  • 21
  • 28
4
php artisan jwt:secret
php artisan config:cache

These both command will be enough

Recep Gümüş
  • 179
  • 1
  • 12
2

I came across this error when I deployed my application after testing and everything else worked well on the local server.

I noticed the following;

  • It's possible that you are getting this error when you uploaded the applications before implementing the JWT and re-uploaded directly via the Cpanel upload without reuploading the .env file.

    • if this is the case, the simplest way to solve this is my merely adding the JWT:key in your .env file (at the bottom) ef

JWT_SECRET=roCZauuldMpw5i4039393939393372y98bEWumqd9ls7Uk8DEpr0gIZ6WIWB

Hope this helps :)

1

This can also happen when using the Laravel Vapor service if you haven't remembered to add the JWT_SECRET to the env file used by Vapor.

In that case just pull the .env file down for the current environment (in this case staging):

vapor env:pull staging

and add the JWT_SECRECT line to it, followed by a push:

vapor env:push staging

and re-deploy.

kjones
  • 1,339
  • 1
  • 13
  • 28
1

I had this problem with my Laravel 8.x and PHP 7.4 so I solved the problem by updating my keys just with these commands:

php artisan key:generate
php artisan jwt:secret
Pejman Kheyri
  • 4,044
  • 9
  • 32
  • 39
0

I have resolved the same on Hostinger - Shared Hosting in a bit different manner than others explained. On shared hosting's user will not have access to shell/cmd/ssh access to the server - So I have executed the commands using composer - Thanks to Ángel Carlos del Pozo Muela for sharing the idea in https://stackoverflow.com/a/48682668 for a different solution but it worked in my case here as well

I have updated the composer.json >> script tag with extra values

"scripts": {
    "pre-generate-key": [
        "@php artisan key:generate",
         "@php artisan cache:clear",
        "@php artisan config:clear"
    ],"post-autoload-dump": [
        "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
        "@php artisan package:discover --ansi"
    ]

Followed by that I have created a new parameter in .env file using going to hostinger file manager and deployed the changes.

 JWT_SECRET={{value}}

on successful completion of deployment - Tested the all service -> all services started working fine - then I removed the "pre-generate-key" bit from composer.json and re-deployed code

0

i'm working on App platform - Digital Ocean php artisan jwt:secret does it for me -> it just genarates a new secret and that's what's messing (just check your .env file)

0

Problem Statement :

TypeError: Argument 3 passed to Lcobucci\JWT\Signer\Hmac::doVerify() m
Facing above problem

Larave version:    8.77
Php Versionn: 7.4

Solution works 100%

php artisan key:generate
php artisan jwt:secret
php artisan cache:clear
Kaleemullah
  • 446
  • 3
  • 8
0

Here is the solution it will work for me

php artisan key:generate

php artisan jwt:secret

php artisan cache:clear

php artisan config:clear

Before running the above commands make sure there is an install jwt package, then check its config file name jwt.php in the config folder

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
sivan
  • 57
  • 8