Manual authenticate user

前端 未结 2 486
暖寄归人
暖寄归人 2020-12-16 15:53

I try to authenticate user:

getDoctr         


        
2条回答
  •  既然无缘
    2020-12-16 16:30

    Try code from this answer. In your case firewall name is secured_area:

    // your controller action
    public function myAction()
    {
    
        // Authenticating user
        $token = new UsernamePasswordToken($user, null, 'secured_area', $user->getRoles());
        $this->get('security.token_storage')->setToken($token);
        //For Symfony <= 2.3
        //$this->get('security.context')->setToken($token);
        $this->get('session')->set('_security_secured_area', serialize($token));
    
    }
    

提交回复
热议问题