简体   繁体   English

AWS Cloudfront 返回 Missing Key-Pair-Id 查询参数或 cookie 值

[英]AWS Cloudfront returning Missing Key-Pair-Id query parameter or cookie value

I have the code that returns the Cloud Front Signed Cookie Values.我有返回 Cloud Front Signed Cookie 值的代码。

CookiesForCustomPolicy signedCookiesUrl = AmazonCloudFrontCookieSigner.GetCookiesForCustomPolicy("https://example.cloudfront.net/movies/nature.mp4", new StreamReader(File.OpenRead(Path.Combine(AppContext.BaseDirectory, "pk-2.pem"))),"APKEXAMPLEKEYID", DateTime.Now.AddDays(10), DateTime.Now, null);

I use the returned values to request the object, however returns the我使用返回的值来请求对象,但是返回

<Error>
<Code>MissingKey</Code>
<Message>
Missing Key-Pair-Id query parameter or cookie value
</Message>
</Error>. 

I test this through the PostMan tool putting the headers and direct request through Chrome browser and still getting the same error.我通过 PostMan 工具测试这个,通过 Chrome 浏览器放置标题和直接请求,但仍然得到相同的错误。

I have use the correct Cloudfront Key Pair and correct resource URL.我使用了正确的 Cloudfront 密钥对和正确的资源 URL。 My objects are private and cloudfront have access to it.我的对象是私有的,cloudfront 可以访问它。 Is there any thing else that i need to work on to get this working?还有什么我需要做的事情才能让它工作吗?

When we use PUBLIC_KEY and PRIVATE_KEY then we get Key-Pair-Id missing.当我们使用 PUBLIC_KEY 和 PRIVATE_KEY 时,我们会丢失 Key-Pair-Id。 We should use Access Key Id instead of PUBLIC_KEY then it will work perfectly.我们应该使用 Access Key Id 而不是 PUBLIC_KEY 这样它就会完美地工作。

在此处输入图片说明

Add Header Key Pair添加标题密钥对

These aren't raw headers, they're cookies.这些不是原始标题,它们是 cookie。 Although I don't use postman, it sounds like this is your issue:虽然我不使用邮递员,但听起来这是您的问题:

Based on what you've said, you wouldn't add them like this:根据您所说的,您不会像这样添加它们:

[CloudFront-Key-Pair-Id, APKEXAMPLEQQ]

Instead it should look more like this:相反,它应该看起来更像这样:

[Cookie, CloudFront-Key-Pair-Id=APKEXAMPLEQQ]

Here is the example for Signed URL in C#.这是 C# 中签名 URL 的示例。

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CreateSignatureInCSharp.html http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/CreateSignatureInCSharp.html

When you return the signed keys, you can return with query string parameter or Cookies.当您返回签名密钥时,您可以使用查询字符串参数或 Cookie 返回。

You can return cookies to API Gateway in two ways, Do with ANY Integration and return the headers as it is.您可以通过两种方式将 cookie 返回到 API Gateway,Do with ANY Integration 并按原样返回标头。

If you do any other method, you need to return json data and map json data to headers in API Gateway.如果您使用其他任何方法,则需要返回 json 数据并将 json 数据映射到 API Gateway 中的 headers。

http://docs.aws.amazon.com/apigateway/latest/developerguide/request-response-data-mappings.html#mapping-response-parameters http://docs.aws.amazon.com/apigateway/latest/developerguide/request-response-data-mappings.html#mapping-response-parameters

Hope it helps.希望它有帮助。

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

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