简体   繁体   English

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

[英]Clone the session cookie for another domain in Symfony2

I'm looking for a working solution, to set a secure clone of the session cookie for another domain in a different Symfony2 environment. 我正在寻找一个有效的解决方案,为另一个Symfony2环境中的另一个域设置会话cookie的安全克隆。 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. 我的想法是,在用户登录后立即设置克隆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.comapi.mysite-a.com (aka api.mysite-a.com -cookies)。

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, 问候,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM