我在 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/