在ZF2之外使用Zend \ Authenticate和子域

时间:2016-02-06 04:02:47

标签: php zend-framework

我正在尝试执行一个看似简单的任务,即在我的应用程序中设置使用Zend \ Authentication的会话cookie域。因为我正在使用Zend \ Authentication \ Storage \ Session进行存储,所以我想弄清楚如何为会话设置cookie_domain,因为我想在多个子域中使用相同的会话变量。这不是ZF2应用程序,我只是将Zend \ Authentication用作单独的组件。

这是我的代码:

$authService = new \Zend\Authentication\AuthenticationService();
$config = new \Zend\Session\Config\StandardConfig();
$config->setOptions(array(
    'cookie_domain' => '.jt.martyndev',
));
$manager = new \Zend\Session\SessionManager($config);
$storage = new \Zend\Authentication\Storage\Session('jt_sso', null, $manager);
$authService->setStorage($storage);

首先,我收到了这个错误:

Fatal error: Class 'Zend\Validator\Hostname' not found in /var/www/jt_sso/vendor/zendframework/zend-session/src/Config/StandardConfig.php on line 473

似乎很奇怪我必须安装Zend \ Validator但我还是试过了,错误就消失了。但是身份验证不再起作用,我只能想象我的配置错误。如果只是设置我的cookie域,我需要添加什么。在尝试执行此操作之前,这是我的原始代码:

$authService = new \Zend\Authentication\AuthenticationService();
$storage = new \Zend\Authentication\Storage\Session('jt_sso', null, $manager);
$authService->setStorage($storage);

理想情况下,我只是想以最简单的方式设置此配置,但无法找到与身份验证相关的任何提及(并且似乎setStorage将只接受Zend \ Authentication \ Storage \ Session的实例)。非常感谢任何帮助,谢谢

0 个答案:

没有答案