generate token symfony authentication api platform 1

generate token symfony authentication api platform

Linux/Mac
curl -X POST -H "Content-Type: application/json" http://localhost/api/login_check -d '{"username":"johndoe","password":"test"}'
Windows
curl -X POST -H "Content-Type: application/json" http://localhost/api/login_check --data {\"username\":\"johndoe\",\"password\":\"test\"}

output:

{
   "token" : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJleHAiOjE0MzQ3Mjc1MzYsInVzZXJuYW1lIjoia29ybGVvbiIsImlhdCI6IjE0MzQ2NDExMzYifQ.nh0L_wuJy6ZKIQWh6OrW5hdLkviTs1_bau2GqYdDCB0Yqy_RplkFghsuqMpsFls8zKEErdX5TYCOR7muX0aQvQxGQ4mpBkvMDhJ4-pE4ct2obeMTr_s4X8nC00rBYPofrOONUOR4utbzvbd4d2xT_tj4TdR_0tsr91Y7VskCRFnoXAnNT-qQb7ci7HIBTbutb9zVStOFejrb4aLbr7Fl4byeIEYgp2Gd7gY"
}

Here is what the above code is Doing:
1. The user sends a POST request to the /api/login_check URL with his username and password in the request body.
2. The firewall checks if the user has the IS_AUTHENTICATED_FULLY role (he needs to be fully authenticated to log in).
3. The firewall calls the getUser() method to load the user’s details.
4. The firewall calls the checkCredentials() method to check the user’s password.
5. If the password is valid, the firewall returns a JWT token to the user.

Similar Posts