public function logUser(\upReal\UserBundle\Entity\User $user, \upReal\CoreBundle\Entity\UserOauth $userOauth) { // Here, "main" is the name of the firewall in your security.yml $token = new UsernamePasswordToken($user, null, 'oauth', $user->getRoles()); $this->get('security.context')->setToken($token); $this->get('session')->set('oauthDatas', $userOauth); // Fire the login event $this->get('event_dispatcher')->dispatch(AuthenticationEvents::AUTHENTICATION_SUCCESS, new AuthenticationEvent($token)); }