Y
Y
Yuri Matveenko2018-04-21 00:06:50
symfony
Yuri Matveenko, 2018-04-21 00:06:50

Symfony 3.4. How to generate a token when authenticating a user?

I did the authorization according to the documentation, everything works, but I need to generate a token in the database every time I log in.
Actually action:

/**
     * @Route("/login", name="login")
     * @param Request $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function loginAction(Request $request)
    {
        $authenticationUtils = $this->get('security.authentication_utils');

        $error = $authenticationUtils->getLastAuthenticationError();

        $lastUsername = $authenticationUtils->getLastUsername();



        return $this->render('@User/security/login.html.twig', array(
            'last_username' => $lastUsername,
            'error'         => $error,
        ));
    }

As far as I understand, when sending data through a form, the framework somehow automatically intercepts the request and does something somewhere.
The security system intercepts the request, validates the provided user credentials, authenticates the user if they are correct, and sends the user back to the registration form if they are not.

To generate a token, I definitely need the user ID of the user who logged in and actually generate the token itself. I know how to do all this, I don’t know where to write all this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2018-04-21
@letsrock_inita

Subscribe to component security events symfony.com/doc/3.4/components/security/authentica...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question