是否可以从API网关上的AWS Custom Auth添加HTTP标头? [英] Is it possible to add an HTTP header from AWS Custom Auth on API gateway?

查看:111
本文介绍了是否可以从API网关上的AWS Custom Auth添加HTTP标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Custom Auth on AWS API Gateway, but I would like to add an extra HTTP header depending on the result. Does anyone know if this is possible, or how to do it. If it is not, is there an idea of if or when this will be possible?

非常感谢.

推荐答案

我们最近添加了对此的支持.文件应尽快上线.

We recently added support for this. Docs should be up soon.

现在,您可以从授权函数中返回这样的对象:

Now you can return an object like this from the authorizer function:

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

不允许使用数组和对象,只能使用字符串/数字/布尔值作为有效JSON.根密钥必须命名为context.

Arrays and objects aren't allowed, only string/number/boolean as valid JSON. The root key must be named context.

您可以像这样在请求$ context中访问这些值:

You can access those values in the request $context like so:

$context.authorizer.key -> value 
$context.authorizer.numKey -> 1
$context.authorizer.boolKey -> true

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

So to answer your question, you wont' be able to conditionally add the header, but you could set the header value to $context.authorizer.yourKey and if yourKey isn't set in the authorizer response, the header value would be blank (but the header would still be sent).

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

这篇关于是否可以从API网关上的AWS Custom Auth添加HTTP标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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