Php Chrome上的EventSource不发送cookie

Php Chrome上的EventSource不发送cookie,php,symfony,cookies,eventsource,mercure,Php,Symfony,Cookies,Eventsource,Mercure,我一直在关注,我想在Symfony学习使用Mercure,一切都很顺利,直到我达到“授权”部分 我使用以下命令运行Mercure hub bin/mercure.exe--jwt algorithm='HS256'--jwt key='konshensx'--addr='localhost:3000'--allow-anonymous--cors-allowed-origines'https://localhost:8000" 我有一个端点来发送测试更新。我将第三个参数设置为true,这样更新将

我一直在关注,我想在Symfony学习使用Mercure,一切都很顺利,直到我达到“授权”部分

我使用以下命令运行Mercure hub

bin/mercure.exe--jwt algorithm='HS256'--jwt key='konshensx'--addr='localhost:3000'--allow-anonymous--cors-allowed-origines'https://localhost:8000"

我有一个端点来发送测试更新。我将第三个参数设置为true,这样更新将只发送给发送负载中具有相同主题的JWT的客户端

public function updateTest(PublisherInterface $publisher) {
        $update = new Update(
            'test',
            json_encode(['status' => 'something random']),
            true, // This thing make this update private
        );

        // The Publisher service is an invokable object
        $publisher($update);

        return $this->json(["testData" => "Monke"]);
}
这是我用来为模板提供正确JWT的代码,以便能够看到更新并像文档一样通过cookie发送

public function front(Request $request) {
        $hubUrl = $this->getParameter('mercure.default_hub');
        $this->addLink($request, new Link('mercure', $hubUrl));

        $token = (new Builder())
            // set other appropriate JWT claims, such as an expiration date
            ->withClaim('mercure', ['subscribe' => ["test"]]) // can also be a URI template, or *
            ->getToken(new Sha256(), new Key($this->getParameter('mercure_secret_key'))); // don't forget to set this parameter! Test value: !ChangeMe!

        $cookie = Cookie::create('mercureAuthorization')
            ->withValue($token)
            ->withPath('/.well-known/mercure')
            ->withSecure(true)
            ->withHttpOnly(true)
            ->withSameSite('strict')
        ;

        $response = $this->render('conversation/index.html.twig');
        $response->headers->setCookie($cookie);

        return $response;
}
我的模板中有一个小代码,用于获取默认的mercure hub链接

    public function discover(PublisherInterface $publisher, Request $request) {
        // This parameter is automatically created by the MercureBundle
        $hubUrl = $this->getParameter('mercure.default_hub');
        // $hubUrl = str_replace("localhost", "127.0.0.1", $hubUrl);

        // Link: <http://localhost:3000/.well-known/mercure>; rel="mercure"
        $this->addLink($request, new Link('mercure', $hubUrl));

        return $this->json(["testData" => "Monke"]);
    }
fetch({{path('conversation.discover')}}})。然后(response=>{
const hubUrl=response.headers.get('Link').match(/]+)>;\s+rel=(?:mercure |“[^”]*mercure[^”]*”/)[1];
//URL是用于操作URL的内置JavaScript类
const url=新url(hubUrl);
append('topic','test');
const eventSource=新事件源(url{
证书:正确
});
eventSource.onmessage=事件=>{
log(JSON.parse(event.data));
}
});
这是模板要求mercure hub链接的端点

    public function discover(PublisherInterface $publisher, Request $request) {
        // This parameter is automatically created by the MercureBundle
        $hubUrl = $this->getParameter('mercure.default_hub');
        // $hubUrl = str_replace("localhost", "127.0.0.1", $hubUrl);

        // Link: <http://localhost:3000/.well-known/mercure>; rel="mercure"
        $this->addLink($request, new Link('mercure', $hubUrl));

        return $this->json(["testData" => "Monke"]);
    }
公共函数发现(PublisherInterface$publisher,Request$Request){
//此参数由MercureBundle自动创建
$hubUrl=$this->getParameter('mercure.default_hub');
//$hubUrl=str_replace(“localhost”、“127.0.0.1”、$hubUrl);
//链接:;rel=“mercure”
$this->addLink($request,newlink('mercure',$hubUrl));
返回$this->json([“testData”=>“Monke”]);
}
这整件事在Firefox中运行得很好,我还没有测试过其他浏览器,因为这里的问题是Chrome不工作(Edge似乎也不工作,就像Chrome一样),当触发EventSource时,它不会发送任何cookie,即使我有withCredentials=true,实际上,似乎根本没有存储cookie

这是EventSource的Chrome开发工具中的网络选项卡

我想让它在Chrome中工作,但idk我该怎么做


我将项目中的每个url更改为相同的域名“localhost”,因此在另一个问题中,我看到“一个域中设置的Cookie不会发送到另一个域。请尝试通过localhost或127.0.0.1访问这两个站点”,但它仍然不起作用。

遇到了相同的问题。我的mercure在http上运行,应用程序在https上运行。所以我没有工作。也许这有帮助。当我在http上同时运行这两个命令时,它就工作了