简体   繁体   English

使用自定义授权者上下文在AWS API网关上添加标头不起作用

[英]Adding a header on AWS API gateway using custom authorizer context does not work

I've set up an API with a single method on AWS API gateway to an HTTP service using a VPC link. 我已经在使用VPC链接的AWS API网关到HTTP服务的单一方法中设置了API。

API网关设置

I've also set up a TOKEN custom authorizer for that API method using Lambda. 我还使用Lambda为该API方法设置了令牌自定义授权者。

授权者设定

The custom authorizer is based on the AWS Node.js custom authorizer blueprint, where I'm basically allowing all methods through and returning a 'context' section along with an IAM. 定制授权者基于AWS Node.js定制授权者蓝图,在这里,我基本上允许所有方法通过并返回一个“上下文”部分以及一个IAM。

{
  "principalId": "user|a1b2c3d4",
  "policyDocument": {
    "Version": "2012-10-17",
    "Statement": [
      {
        "Action": "execute-api:Invoke",
        "Effect": "Allow",
        "Resource": [
          "arn:aws:execute-api:[region]:[account_id]:[restApiId]/[stage]/*/*"
        ]
      }
    ]
  },
  "context": {
    "key": "new-token",
    "number": 1,
    "bool": true
  }
}

That's the result from the Lambda when I test it, both on the Lambda test console and one the API gateway custom authorizer console. 这是我在Lambda测试控制台和API网关自定义授权者控制台上进行测试时来自Lambda的结果。

Finally, I mapped the Authorization header to 'context.authorizer.key' in the Integration Request section. 最后,我在“集成请求”部分中将“授权”标头映射到“ context.authorizer.key”。

Now, when I execute the request, I expect that the Authorization header would be populated with the value from the 'context' section of the authorizer's response, but it's never populated. 现在,当我执行请求时,我希望将使用授权者响应的“上下文”部分中的值填充“授权”标头,但永远不会填充它。

What am I doing wrong? 我究竟做错了什么?

It turns out that my setup was correct all along. 事实证明,我的设置一直都是正确的。

I was testing using the AWS API Gateway testing tool (using the TEST button in one of the screenshots), but that tool does not really allow you to test this out end-to-end. 我当时使用AWS API Gateway测试工具(使用其中一个屏幕截图中的TEST按钮)进行了测试,但是该工具实际上不允许您端对端进行测试。 I ended up deploying my stage, and then testing it using Postman. 我最终部署了我的舞台,然后使用Postman对其进行了测试。 Then it started working. 然后它开始工作。 Weird. 奇怪的。

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

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