【发布时间】:2019-06-27 10:34:36
【问题描述】:
我在为用 Node.js 编写的 AWS lambda 函数设置基本身份验证时遇到问题。
问题:
AWS lambda 函数,它是附加服务的代理。这个函数只转发整个请求并给用户整个响应。这就是为什么我需要强制使用 Authentication 标头,并且我希望有提示窗口来传递凭据:https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication
除了我的 lambda 函数的代理部分,我专注于身份验证问题,并编写了以下代码:
export const proxy = async (event) => {
const authorizationHeader = event.headers.Authorization;
if (typeof authorizationHeader === undefined) {
throw new Error("Unauthorized");
}
...
};
service:
name: proxy-auth-test
plugins:
- serverless-webpack
provider:
name: aws
runtime: nodejs8.10
memorySize: 128
timeout: 10
functions:
proxy-async:
handler: handler.proxy
events:
- http:
method: get
path: api/proxy
resources:
Resources:
GatewayResponse:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.WWW-Authenticate: "'Basic'"
ResponseType: UNAUTHORIZED
RestApiId:
Ref: 'ApiGatewayRestApi'
StatusCode: '401'
端点工作正常,但我无法获得传递凭据的提示窗口。我根据这个https://medium.com/@Da_vidgf/http-basic-auth-with-api-gateway-and-serverless-5ae14ad0a270设置了GatewayResponse,但我不想提供只负责用户授权的额外lambda函数。
在我的例子中,我不能在执行最终的 lambda 函数之前授权用户,因为这个函数只转发请求(也包括凭据),仅此而已。
有没有人尝试过使用无服务器和 AWS lambda 在没有额外授权的情况下使用提示窗口设置基本身份验证?
【问题讨论】:
标签: node.js aws-lambda basic-authentication serverless