首页 > 解决方案 > API Gateway HTTP 集成,如何传递授权标头?

问题描述

我在“集成请求”中。我已经设置了 HTTP 集成类型和端点 URL。下面,我看到“HTTP 标头,但是如果我尝试添加标头,则会出现一个奇怪的“映射自”值,我不明白。设置 HTTP 代理集成添加一个我也不明白的映射模板。

我只需要将原始请求中的 Authorization:xxxx 和 X-Auth-Username:xxxxx 传递给端点

找不到简单的方法...

我设置了 HTTP 代理集成并在 HTTP 标头中添加(并已部署):

 method.request.header.Authorization
 method.request.header.X-Auth-Username

我还根据需要在 Method 请求标头中添加了 Authoriaxtion 和 X-Auth-Username。但是调用 api 时出现错误:

Authorization header requires 'Credential' parameter. 
Authorization header requires 'Signature' parameter. 
Authorization header requires 'SignedHeaders' parameter. 
Authorization header requires existence of either a 'X-Amz-Date' or a 'Date' header

嗯,也许这是一个“命名”问题?所以我在方法请求中用 MyAuthentication 改变了“授权”,在集成 Header 之后,我将 Authorization 映射到

 method.request.header.MyAuthentication

现在,如果我在标题中使用 MyAuthorization 调用我的 api,我会得到“缺少身份验证令牌”,而不会访问 api 服务器

标签: aws-api-gateway

解决方案


在此处输入图像描述

单击“方法请求”,展开“HTTP 请求标头”并添加标头Authorization。现在返回并单击 'Integration Request' ,展开 'HTTP Headers' 并添加 Header NameAuthorization和 'Mapped from' method.request.header.Authorization。基本上对于“方法请求”选项卡上的任何标题 XYZ 都应该在“集成请求” method.request.header.XYZ 上具有相应的映射。


推荐阅读