在Symfony2中克隆另一个域的会话cookie

时间:2022-08-23 10:07:05

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.

我正在寻找一个有效的解决方案,为另一个Symfony2环境中的另一个域设置会话cookie的安全克隆。我的想法是,在用户登录后立即设置克隆cookie,以便可以在两个不同域上的两个不同Symfony2环境中对用户进行身份验证。

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.

我正在使用最新的2.x.dev版本的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).

我知道,这种配置非常难看。不幸的是,我不允许将域配置从api.mysite-b.com更改为api.mysite-a.com(又名.wildcard-cookies)。

1 个解决方案

#1


0  

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

我认为没有合适的捆绑来处理这个问题,但在PHP规范中,您可以找到一个准确的选项来管理您的问题$ 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:

在symfony2中,您只需使用Cookie对象:

use Symfony\Component\HttpFoundation\Cookie;

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

Cookie constructor has the same options as PHP method:

Cookie构造函数与PHP方法具有相同的选项:

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

regards,

问候,

#1


0  

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

我认为没有合适的捆绑来处理这个问题,但在PHP规范中,您可以找到一个准确的选项来管理您的问题$ 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:

在symfony2中,您只需使用Cookie对象:

use Symfony\Component\HttpFoundation\Cookie;

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

Cookie constructor has the same options as PHP method:

Cookie构造函数与PHP方法具有相同的选项:

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

regards,

问候,