Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to correctly set a JWT secret in Laravel with jwt-auth?

Tags:

php

laravel

jwt

I'd like to test the authentication of JWTs in my project as the JWTs will be sent from outside the app, and so they must be signed using the key from my application. Is this possible? Does anyone know of a site that allows you to sign a token using a secret?

I tried http://jwtbuilder.jamiekurtz.com/ but JWT-auth keeps returning {"error":"token_invalid"} if I enter the key which was returned by jwt:generate. This leads me to believe the key returned by this command is not actually the key used to sign JWTs in my application.

I'm using php artisan jwt:generate to generate a key, which returns the following:

jwt-auth secret [...] set successfully.

But where is it set? The JWT_SECRET variable in my .ENV file doesn't change, and if I perform a project wide search for the key it's not found.

Does this command work?

Laravel 5.3, jwt-auth 0.5.9.

like image 457
f7n Avatar asked Nov 09 '22 03:11

f7n


1 Answers

Just run this command:

php artisan jwt:secret

Reference

like image 55
Ayman Elshehawy Avatar answered Nov 14 '22 21:11

Ayman Elshehawy