【问题标题】:Automatic user authentication自动用户认证
【发布时间】:2013-01-01 02:00:36
【问题描述】:

基于这个问题:Automatic post-registration user authentication

$token = new UsernamePasswordToken($userEntity, null, 'main', array('ROLE_USER'));
$this->get('security.context')->setToken($token);

这在 Symfony 2 上运行良好,但在 Symfony 2.1 的实际版本中,这个接缝不再起作用,我尝试相同的代码但没有成功(也没有错误)。这个想法是在不使用登录表单的情况下通过 ajax 对我的用户进行身份验证。这是因为我使用这个架构:

if(user_on_data_base) { 
 if(user_fb_linked_with_us) { // authenticate him and redirect to /home }
}

这是通过 ajax 执行的。

编辑: 最奇怪的是,如果我从用户控制器执行此代码,它就可以工作!但不要从我的 ajax 控制器执行它。

【问题讨论】:

    标签: symfony symfony-2.1


    【解决方案1】:

    查看 HWIOAuthBundle does this 的方式,看来您需要抛出 security.interactive_login 事件。

    你可以这样做:

    $this->get('event_dispatcher')->dispatch(
        SecurityEvents::INTERACTIVE_LOGIN,
        new InteractiveLoginEvent($this->container->get('request'), $token)
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-22
      • 2018-07-26
      • 2021-07-06
      • 1970-01-01
      • 2017-11-01
      • 2018-01-26
      • 2016-10-22
      • 1970-01-01
      相关资源
      最近更新 更多