离子身份验证 - 似乎随机将我注销



我正在使用ionAuth,它似乎几乎随机地将我注销?我正在使用 Codeigniter v2.1.4 - 它记录得很好,但是 ionAuth 似乎在随机插入时注销,有没有办法强制会话保持活动状态,直到我调用 ionAuth->logout 函数?

我的 CI 配置如下所示:

$config['sess_cookie_name']     = 'cisession';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 600;

我的ion_auth配置文件如下所示:

 $config['user_expire'] = 0;
 $config['user_extend_on_login'] = FALSE;

谁能给我任何可能导致问题的原因的指示?

问题的原因是执行 AJAX 调用时会话 cookie 轮换,CodeIgniter 3 中包含正确的修复

程序

您有四个选项:

应付:我自己以前也遇到过这个问题,但不知道它的确切原因。简而言之,我保存了每个 XMLHttpRequest 的承诺,如果遇到 HTTP 状态代码 401,客户端应用程序将以弹出窗口的形式请求凭据,然后重试 AJAX 承诺。

使用jQuery的客户端,只需添加此ajaxError处理程序:

$(document).ajaxError(function (e, xhr, settings, exception) {
    if (xhr.status == 401)
    {
        // open your popup
        $('#login-popup').modal('open');
        // attach the xhr object to the listener
        $(document).bind( "retry-xhr", {
                xhro: xhr
            },
            function( event ) {
            // retry the xhr when fired
            $.ajax( event.data.xhro );
        });
    }
});

当您重新登录时,只需调用以下命令即可重试您的请求:

$(document).trigger('retry-xhr');

服务器端,你只需要在你的构造函数中添加一个 if

if (!$this->session->userdata('logged_in') && $this->input->is_ajax_request())
        {
            $this->output->set_status_header('401');
            exit;
        }

这很有用,因为某些用户会让他们的 Web 应用程序窗口在夜间打开,会话超时将启动。然后用户会打电话给我说无法执行任何 AJAX 函数,我必须告诉他们按 F5

如果在 Angular 上,我已经成功地使用了 HTTP 身份验证拦截器模块

砍:看到这篇文章,他的解决方案是在ci_session表中创建另一个字段并检查两个cookie,因此您的会话在轮换后仍然有效。

它还详细解释了导致此故障的原因

http://www.hiretheworld.com/blog/tech-blog/codeigniter-session-race-conditions

升级:开始使用已修复的下一个版本:

https://github.com/EllisLab/CodeIgniter/tree/release/3.0

补丁替换系统/库/会话中的第 346 行.php(函数 sess_update(((

if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now)

跟:

if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now || $this->CI->input->is_ajax_request())

最新更新