Symfony2,FOSUserBundle,禁用cookies身份验证

Symfony2,FOSUserBundle,禁用cookies身份验证,symfony,cookies,sessionid,Symfony,Cookies,Sessionid,如何在没有brouser中的Cookie的情况下在Symfony2中进行身份验证?如何生成这样或这样的url,或者始终可用的其他url sessionid参数。谢谢你的帮助 你必须做两件事。首先,必须扩展会话存储以从查询参数获取会话 namespace Elao\BackBundle\Session; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation

如何在没有brouser中的Cookie的情况下在Symfony2中进行身份验证?如何生成这样或这样的url,或者始终可用的其他url sessionid参数。谢谢你的帮助

你必须做两件事。首先,必须扩展会话存储以从查询参数获取会话

namespace Elao\BackBundle\Session;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Session\Storage\NativeFileSessionStorage;

class Storage extends NativeSessionStorage
{
    public function __construct($savePath = null, array $options = array(), ContainerInterface $container)
    {
        $request = $container->get('request');
        if ($request->query->has('sessionId')) {
            $request->cookies->set(session_name(), 1);    // We have to simulate this cookie, in order to bypass the "hasPreviousSession" security check
            session_id($request->query->get('sessionId'));
        }
        return parent::__construct($savePath, $options);
    }
}
资料来源:

下一点应该是替换UrlGenerator,以使用会话id参数生成每个url。可以在中找到这样做的示例


但正如nifr在评论中所说,这不是一个非常干净的要求。

您真的确定要使用url中的会话id进行身份验证吗?这对安全来说是最糟糕的事情。不要在没有https的情况下使用它,如果您想要简单的url身份验证,最好使用标准的http身份验证。我真的不确定你的目标客户机设备不会接受cookies。。。这样做的目的是什么?请描述…@nifr,我理解所有的风险。但这项任务是由客户提出的。需要摆脱这种状况。