To get a token, you must enter a security context.
1. Create a class exit listener, something like this:
namespace Yourproject\Yourbundle\Services; ... use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface; use Symfony\Component\Security\Core\SecurityContext; class LogoutListener implements LogoutSuccessHandlerInterface { private $security; public function __construct(SecurityContext $security) { $this->security = $security; } public function onLogoutSuccess(Request $request) { $user = $this->security->getToken()->getUser();
2. And then in service.yml, add this line:
.... logout_listener: class: Yourproject\Yourbundle\Services\LogoutListener arguments: [@security.context]
What is it, can it help.
tesmojones
source share