Clone the session cookie for another domain in Symfony2

2k views Asked by At

I'm looking for a working solution, to set a secure clone of the session cookie for another domain in a different Symfony2 environment. My idea is, to set a cloned cookie just after a user logged in, so that the user can be authenticated in two different Symfony2 environments on two different domains.

Domain: mysite-a.com        // Environment -e site
Domain: api.mysite-b.com    // Environment -e api

Where to find something like a controller or event (best solution) to hook in?

I'm using the latest 2.x.dev version of FOSUserBundle.

I know, this configuration is pretty ugly. Unfortunately, I'm not allowed to change the Domain-Configuration from api.mysite-b.com to api.mysite-a.com (aka. wildcard-cookies).

1

There are 1 answers

6
Piotr Pasich On

I think there is no proper bundle to handle this problem, but in PHP specification you can find an accurate option to manage your problem $domain

bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] );

In symfony2 you ened to use Cookie object:

use Symfony\Component\HttpFoundation\Cookie;

$response->headers->setCookie(new Cookie('foo', 'bar'));

Cookie constructor has the same options as PHP method:

public function __construct($name, $value = null, $expire = 0, $path = '/', $domain = null, $secure = false, $httpOnly = true)

regards,