【发布时间】:2021-12-30 06:15:27
【问题描述】:
我正在尝试找到一种方法来在 AWS 的自定义授权方中允许 访客模式。
基本上,我想要实现的是以下场景:
- 如果请求中没有
Authorization标头,则触发响应一些数据的 lambda 函数 - 如果有
Authorization标头,那么我的自定义授权者应该检查JWT 令牌和Allow或Deny。如果custom-authorizer返回Allow,则触发 lambda
我知道我可以实现其中一个但不能同时实现,即我可以打开端点(完全删除 authorizer),它可以正常工作,或者我可以输入authorizer,它又可以正常工作。
但是,当没有 Authorization 标头时,我看不到绕过 custom-authorizer 的方法。
无服务器中的示例配置:
functions:
hello:
handler: handler.hello
events:
- http:
path: /hello
method: get
private: true
authorizer:
identitySource: method.request.header.Authorization # Can this be optional?
name: custom-authorizer
custom-authorizer:
handler: authorizer.handler
根据我的测试,我可以确认,一旦存在authorization 并且请求中没有Authorization 标头,那么我的custom-authorizer 根本不会被触发,API 网关会立即响应401 Unauthorized。
请注意,在我的访客模式下,我不想要获得自定义 API 网关响应(这是可能的并且有效)。我想触发 lambda 函数,就像根本没有授权一样。
我得出结论这是不可能的,唯一的解决方法是删除authorization,然后在 lambda 中执行一些自定义代码。
有什么建议吗?
【问题讨论】:
标签: amazon-web-services aws-lambda authorization serverless sls