I'm trying to do a seemingly simple task of setting the session cookie domain in my application which uses Zend\Authentication. As I'm using Zend\Authentication\Storage\Session for storage, I'm trying to figure out how to set the cookie_domain for the session as I want to use same session variables across multiple sub-domains. This is not a ZF2 application, I'm just using the Zend\Authentication as a separate component.
Here is my code:
$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);
Firstly, I got this error:
Fatal error: Class 'Zend\Validator\Hostname' not found in /var/www/jt_sso/vendor/zendframework/zend-session/src/Config/StandardConfig.php on line 473
Seems strange I have to install Zend\Validator but I tried that anyway, and the error went away. But the authentication wasn't working anymore, I can only imagine I'm misconfigured things. What do I need to add to simply set my cookie domain. Here is my original code before attempting to do this:
$authService = new \Zend\Authentication\AuthenticationService();
$storage = new \Zend\Authentication\Storage\Session('jt_sso', null, $manager);
$authService->setStorage($storage);
Ideally I just wanna set this configuration in the simplest proper way but can't find any mention of this with relation to authentication (and seems setStorage will only accept an instance of Zend\Authentication\Storage\Session). Would appreciate any help, thanks