使用HTTP代理访问AWS API Gateway中的标头? [英] Access headers in AWS API Gateway using HTTP Proxy?

查看:266
本文介绍了使用HTTP代理访问AWS API Gateway中的标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AWS API Gateway及其HTTP代理

I'm using AWS API Gateway and it's HTTP Proxy,

我需要通过AWS API Gateway将Authorization标头传递给我的终端节点

I need to pass Authorization header to my endpoint through AWS API Gateway

我尝试过的事情:

设置方法请求类似,

集成请求设置

Integration Request setup

这不起作用,我的应用程序没有收到授权标头,

This doesn't work, my app doesn't receive the Authorization header,

我也尝试过使用映射模板

Also I've tried using mapping template

{
  "method": "$context.httpMethod",
  "body" : $input.json('$'),
  "headers": {
    #foreach($param in $input.params().header.keySet())
    "$param": "$util.escapeJavaScript($input.params().header.get($param))" #if($foreach.hasNext),#end

    #end
  },
  "queryParams": {
    #foreach($param in $input.params().querystring.keySet())
    "$param": "$util.escapeJavaScript($input.params().querystring.get($param))" #if($foreach.hasNext),#end

    #end
  },
  "pathParams": {
    #foreach($param in $input.params().path.keySet())
    "$param": "$util.escapeJavaScript($input.params().path.get($param))" #if($foreach.hasNext),#end

    #end
  }  
}

这也不起作用。

有人可以给我一些有关如何实现的提示吗?

Could Anyone give me some hint on how this might be accomplished ?

推荐答案

最近我不得不尝试使用API​​ Gateway HTTP代理将AWS SigV4 HTTP请求传递到终端节点。
经过测试和调试后,发现授权正在被使用并且没有通过!
因此,在将请求发送到API网关时-我发送了Authorization和Authorization的副本作为另一个标头 myauth。 (由于请求来自我自己的客户端,所以我能够执行此操作。)

Recently I had to try using an API Gateway HTTP proxy to pass an AWS SigV4 HTTP request to an endpoint. After testing and debugging found that the Authorization is being consumed and not passed! So while sending the request to the API Gateway - I sent Authorization and a copy of the Authorization as another header "myauth". (I was able to do this since the request is coming from my own client.)

在方法请求中,我添加了Authorization和myauth作为HTTP标头
< a href = https://i.stack.imgur.com/X12so.png rel = nofollow noreferrer>方法请求-HTTP标头

In the method request I added Authorization and myauth as HTTP Headers Method Request - HTTP Headers

在集成请求-HTTP标头中,我将myauth映射到授权,然后将其转发到端点

In the Integration Request - HTTP Headers I mapped myauth to Authorization before it was forwarded to the endpoint

集成请求-HTTP标头

不知道这是否是最好的方法,或者可能有任何潜在的问题,但这可行!希望这可以帮助某人或提供一些想法。

Dont know if this is the best way to do this or if there could be any potential issues but this worked! Hope this helps someone or gives some ideas.

这篇关于使用HTTP代理访问AWS API Gateway中的标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆