A
A
Alexey Sobolenko2019-05-10 13:40:35
symfony
Alexey Sobolenko, 2019-05-10 13:40:35

How to manually logout a user in symfony without redirecting to the /logout page?

The symphony project uses scheb/two-factor-bundle. It is necessary to prevent the user from entering the code if the user is locked out. Information about blocking is in a separate table from user data. / There is an event in the bundle that could be used to do this, scheb_two_factor.authentication.require. But, the fact is that it does not allow redirection to be done normally due to the fact that the user is authorized at that time and is waiting for the correct code for 2fa to be entered. It is necessary to exit the user, but I can not find how to do this from the handler of the above event.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Sobolenko, 2019-05-21
@alexsobolenko

The solution was to pass TokenStorageInterface $tokenStoragein the constructor of the event handler scheb_two_factor.authentication.require. And call it like this:

$request->getSession()->invalidate();
$this->tokenStorage->setToken(null);

A
Antony Tkachenko, 2019-05-11
@LemonFox

Most likely the best solution would be to redefine the query to search for a user .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question