2

So, I have deployed a JWT project in Heroku and I get following error

 Uncaught PHP Exception Lexik\Bundle\JWTAuthenticationBundle\Exception\JWTEncodeFailureException: "Unable to create a signed JWT from the given configuration." at /app/vendor/lexik/jwt-authentication-bundle/Encoder/LcobucciJWTEncoder.php line 38

.env

APP_ENV=prod
APP_SECRET=4b3623b38e2d6ba78fe9vdfx59dc3dd5
JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem
JWT_PASSPHRASE=pass
DATABASE_URL="sqlite:///%kernel.project_dir%/var/task.db"

In git cmd I also did, but didn't worked.

heroku config:set APP_ENV=prod
heroku config:set JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem
etc

In localhost it is working well JWT Token is generating fine but in heroku I get above error.

Demi St
  • 57
  • 1
  • 5
  • 1
    Have you checked that the certificates are actually deployed (or generated)? By default they are added to `.gitignore`, so depending on your deployment method they might not be. – msg Dec 19 '21 at 12:05
  • Did you find any solution for your problem? I can see that pem-files are generated correct on server. I can generate tokens using `bin/console lexik:jwt:generate-token` command but when calling /login I always get the "Unable to create a signed JWT from the given configuration." error :( Locally, everything is fine. I have no more ideas.. – Franziska Jan 30 '23 at 11:55

2 Answers2

8

if you used lexit have you thought of regenerating your private and public keys on your production environnement?

php bin/console lexik:jwt:generate-keypair    
AnTh0Ny77
  • 172
  • 7
0

I had the same issue recently and as @php-abs metioned, I just added it to the composer.json file in the scripts/auto-scripts section as a command as shown bellow:

"scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd",
            "lexik:jwt:generate-keypair": "symfony-cmd"
        },
...
}
Abdelilah Aassou
  • 148
  • 3
  • 15