在Express JS中设置跨域Cookie

我很难设置跨域Cookie。

我想使用在api上生成的经Cloudfront签名的cookie,以便在导致Cloudfront分发的另一个子域中使用。

Cookie显示在响应中,但未存储。 我仔细检查了,到期时间是将来的时间 我尝试了域上的各种变体

奇怪的是,一旦我在设置cookie时提供了选项,就不会存储它,即使我没有设置域设置。

这是我使用的代码段:

const AWS = require('aws-sdk');

const keyPairId = '******';
const privateKey = `******`
const signer = new AWS.CloudFront.Signer(keyPairId,privateKey);


const express = require('express')
const app = express()
const port = 80

app.get('/',(req,res) => {
    signer.getSignedCookie({
        url: '**********',expires: new Date().getTime() * 1000 + 30 * 24 * 3600,},(err,cookies) => {

        res.cookie('access-Control-Allow-Credentials',true);
        res.cookie('access-control-allow-origin','test.dummy.be');
        Object.keys(cookies).forEach(key => {
            const value = cookies[key];

            res.cookie(key,value,{
                domain: 'test.dummy.be',path: '/webapps/22-3cccc7af6f1cd8b4dbcf1c132f86746f',expires: new Date(new Date().getTime() + 30 * 24 * 3600000),httpOnly: true,secure: true
            });
        });

        res.send('Hello World2!')
    })
});

app.listen(port,() => console.log(`Example app listening on port ${port}!`))

在屏幕截图中,您可以看到标题位于响应中:

在Express JS中设置跨域Cookie

为什么它们不会显示在“应用程序”面板中

在Express JS中设置跨域Cookie

dmkut 回答:在Express JS中设置跨域Cookie

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3141722.html

大家都在问