使用cloudfront通过签名的cookies提供来自s3存储桶的私有内容。我能够生成cookie,但是当我请求资源时,我会从node.js或任何客户端/浏览器/邮递员那里得到缺少密钥对Id查询参数或Cookie值错误
const cloudFront = new AWS.CloudFront.Signer(
fs.readFileSync('./rsa-APKAIQSVJ2R3T6PYTOUQ.pem', 'utf8'),
fs.readFileSync('./pk-APKAIQSVJ2R3T6PYTOUQ.pem', 'utf8')
);
const policy = JSON.stringify({
Statement: [{
Resource: 'http*://d2q89b5pewg0ry.cloudfront.net/images/',
Condition: {
DateLessThan: {
'AWS:EpochTime': Math.floor(new Date().getTime() / 1000) + 60 * 60 * 3
}
},
}]
});
const cookie = cloudFront.getSignedCookie({
policy: policy
});
let cookieString = '';
for(var cookieKey in cookie)
{
cookieString += cookieKey + '=' + cookie[cookieKey] + ";";
}
return axios.get('https://d2q89b5pewg0ry.cloudfront.net/images/hikup.jpg',{
headers: {
Cookie: cookieString
}
}).then((response) => {
return response;
}).catch((error) => {
return error;
});发布于 2019-11-25 12:40:34
您没有使用完整的构造函数,请检查以下内容:
CloudFront signed cookies node,js
cookies应该有3个键及其值:
CloudFront-Expires
CloudFront-Signature
CloudFront-Key-Pair-Id请求时还需要添加cookie/key CloudFront-Key-Pair-Id= APKAIQSVJ2R3T6PYTOUQ。
CloudFront- key -Pair-Id不是公钥,它只是一个ID(类似于访问密钥ID),这样CloudFront就可以看到它需要哪个公钥来解密签名。您在CloudFront上最多可以有2个激活密钥,您可以使用私钥和公钥创建签名,当cloudfront收到请求时,它会检查CloudFront- key -Pair-Id以了解它应该使用哪个公共密钥,所以故事结束时,CloudFront- Key -Pair-Id是当您登录到CloudFront控制台并转到安全凭证并单击CloudFront密钥对时的ID,您将看到一个访问密钥ID,这是您需要定义的ID。(与文件名相同)
https://stackoverflow.com/questions/59022405
复制相似问题