amazon-web-services - 是否可以在 API 网关上添加来自 AWS 自定义身份验证的 HTTP header ?

标签 amazon-web-services aws-lambda aws-api-gateway

我在 AWS API Gateway 上使用自定义身份验证,但我想根据结果添加额外的 HTTP header 。有谁知道这是否可能,或者如何做到这一点。如果不是,是否知道是否或何时可能?

非常感谢。

最佳答案

我们最近增加了对此的支持。文档应该很快就出来了。

现在你可以从授权函数返回一个像这样的对象:

{
  "principalId": "xxxxxxxx", // The principal user identification associated with the token send by the client.
  "policyDocument": {
    "Version": "2012-10-17",
    "Statement": [
      {
        "Action": "execute-api:Invoke",
        "Effect": "Allow|Deny",
        "Resource": "arn:aws:execute-api:<regionId>:<accountId>:<appId>/<stage>/<httpVerb>/[<resource>/<httpVerb>/[...]]"
      }
    ]
  },
  "context" : {
    "key" : "value",
    "numKey" : 1,
    "boolKey" : true
  }
}

不允许使用数组和对象,只有字符串/数字/ bool 值作为有效的 JSON。根 key 必须命名为 context .

您可以在请求 $context 中访问这些值,如下所示:
$context.authorizer.key -> value 
$context.authorizer.numKey -> 1
$context.authorizer.boolKey -> true

因此,要回答您的问题,您将无法有条件地添加 header ,但您可以将 header 值设置为 $context.authorizer.yourKey如果 yourKey未在授权方响应中设置, header 值将为空(但仍将发送 header )。

编辑:

文档上线 http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html

关于amazon-web-services - 是否可以在 API 网关上添加来自 AWS 自定义身份验证的 HTTP header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40585016/

相关文章:

amazon-web-services - 如何使用Terraform在现有VPC中启动EC

amazon-web-services - 如何调试 AWS Api 网关和 Lambda 的 "AWS/ApiGateway 5XXError"

node.js - 如何让 Lambda 函数使用 ANY 方法从 ApiGateway 获取 httpmethod?

java - AWS API Gateway 集成响应

node.js - AWS DynamoDB 表的 StreamSpecification 属性有何用途?

windows-server-2008 - Windows EC2 机器上的固定 MAC 地址

amazon-web-services - AWS Bitnami 解析服务器 - 添加 HTTP 身份验证使我的应用程序在解析仪表板 'unauthorized'

amazon-web-services - 云信息 : is it possible to export current aws configuration as template?

amazon-web-services - 是否可以在 SAM 模板中定义常量以使我的模板文件更易于维护?

javascript - 是否可以撤销 AWS Cognito IdToken?