reactjs - ReactJS- remove HTTP header before redirect
问题描述
In my React app, I'm making a GET
REST web service call to an endpoint whose purpose is to generate a presigned AWS URL to a protected S3 asset. We pass an Authorization
header and a token to the service.
This initial call works as expected and the service responds with a redirect (via a 307 response code) and includes the presigned URL in the response's Location
header.
The issue I'm facing is that when the redirect is followed, Amazon rejects the call with a 400 response code and the following message.
Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specified.
Is there a way to remove the Authorization
header before the redirect is followed?
This seems like it should be a fairly common situation (when a React application requires access to a protected S3 asset) - is there a better way to handle this use case?
解决方案
在与 Amazon 支持人员进行了几次对话后,实现上述目标的方法是在 S3 前面使用 CloudFront 分配。CloudFront 没有与 S3 相同的限制Only one auth mechanism allowed
这是我所做的:
- 创建具有 S3 源的 CloudFront 分配。
- 可选选择 - 限制存储桶访问。
- 您将需要一个 CloudFront 访问身份(使用现有身份或创建新身份)。
- 推荐选择 - 更新存储桶策略
- 在 S3 中
- 确保存储桶策略已更新(在上面选择“更新存储桶策略”时自动填充)
- 使用您需要支持的方法/标头更新 CORS 配置
您需要的另一件事是此处描述的 CloudFront 密钥对,然后在生成预签名链接时使用该信息。
更多信息
亚马逊肯定使这比它需要的复杂得多(即为什么Only one auth mechanism allowed
对 S3 有限制?)但至少对于那些需要它的人来说有一种解决方法。
推荐阅读
- matrix - 当我在内核中声明一个矩阵时没有输出
- php - 将 WooCommerce 产品简短描述限制为仅文本(禁用 tinymce 编辑器)
- javascript - React Native 中的图像更改 onPress
- python - 如何按标签分组并使用python创建新数据
- html - 用于在计算机和移动设备上查看的编码列
- javascript - 按 React Native 更改矢量图标
- c# - 如果没有队列绑定到 RabbitMQ 中的交换,如何“缓冲”消息?
- arrays - 在解决 c 中查找和计算重复项时面临运行时错误
- racket - Typed Racket 中的“n”是什么意思?
- android - Android 客户端无法使用套接字连接到服务器