Access headers in AWS API Gateway using HTTP Proxy

2019-03-29 14:20发布

问题:

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

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

Things I've tried:

Setting Method Request like so,

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
  }  
}

This also doesn't worked.

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

回答1:

API Gateway strips the AWS SigV4 Authorization header due to security reasons. If you are using other Authorization mechanism like OAuth, the header wouldn't be stripped.