Skip to content
Advertisement

jwt token not found when i pass in username and password in curl

I want to use jwt token in my symfony project. But i have a problem because when i use: curl.exe -X POST -H "Content-Type: application/json" http://localhost:81/api/login_check -d '{"username": "f.djawid@outlook.com","password":"000000"}'

I get : {"code":401,"message":"JWT Token not found"}

This is my security.yml:

JavaScript

As you can see i use the lexikJWTAthenticationBundle. I made a private key and public key with ssl.

I use docker to run the apache server where my localhost is running. This is my vhost config:

JavaScript

I found on another post that the solution might be that i have to add the Rewrite for Autherization if i use Apache but its already added there and its still not posting the jwt token when used curl like i did above.

I also made user entity with make:user and i added the username, roles and password values in the table user. In the curl you can see that i use 000000 as the password. In the database this password is hashed with argon2i.

I really don’t know why i can’t see the jwt token. I have looked everywhere in the internet, but nothing seems to work for me.

EDIT

I also have this in the lexik_jwt_authentication.yml:

JavaScript

And this is what i defined in my .env file:

JavaScript

Also when in the security.yml when i swap the login and api headers i get this error:

JavaScript

Advertisement

Answer

So i just solved the problem. The problem was that i had to switch the position of login header and api header in security.yml. This time i used postman to test if it works and i get a token back. The reason why it’s still not working in my local server is because for some reason the symfony kernel isn’t giving any response, but that is entirly another problem.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement