U
U
user98232020-11-14 19:13:23
symfony
user9823, 2020-11-14 19:13:23

How to get getUser from JWT in Symfony controller?

Hello everyone
, I'm trying to make a jwt for user authorization via api
, I did it according to the following instructions
https://smoqadam.me/posts/how-to-authenticate-user...
and everything seems to work according to the instructions, the very last test when called to ApiController returns a test message, everything is as it should, but the getUser($credentials, UserProviderInterface $userProvider) method is implemented in the JwtAuthenticator class,
and
now in the ApiController I want to automatically call getUser so that the $user property is automatically set for any request to the api,
how can I do this?
re-implement the baerer token decryption method in the api, and then pulling this method when accessing each method in the api is not good
those. How can I access this method in any controller?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Flying, 2020-11-14
@user9823

The method getUser() is in AbstractController, so you can just call it if your controllers inherit from AbstractController.
Alternatively, you can get the user through the method's action argument thanks to UserValueResolver
Decrypt in controllers, you definitely don't need anything, read how the Security system works in Symfony. User, after receiving it as a result of the authentication process, is stored in the security token in the form in which you gave it there, in your case - in the form of an entity.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question