symfonysecurityjwtsymfony4lexikjwtauthbundle

Symfony JWT - Change the login way using symfony lexik JWT Authentication Bundle


In the Symfony Lexik JWT Authentication bundle, It is explained how to authenticate users using a table in the database.

In my case, My users aren't in the database but are in another application that I can access via API calls.

Also, to retrieve the users from this API, all I have to do is send a token associated with every user and get his information.

This token is well handled and is unique for each user.

How can I change the way LexikJWTAuthenticationBundle authenticate users using this API instead of the database.

And after this authentication, I want the JWT token to contain all the user information so I won't have to call this API each time a request is made to my application.

I made this diagram to explain my situation:

enter image description here

I tried from my side building a custom ApiUserProvider and an ApiUserAuthenticator but I am struggling to get this working.

Any help?


Solution

  • Here's described how to manually create JWTs for users: https://github.com/lexik/LexikJWTAuthenticationBundle/blob/2.x/Resources/doc/7-manual-token-creation.md you should be able to use that in your endpoint which authenticates the user, and return your own JWT.