我在为用 Node.js 编写的 AWS lambda 函数设置基本身份验证时遇到问题。
问题:
AWS lambda 函数是附加服务的代理。该函数仅转发整个请求并向用户提供整个响应。这就是为什么我需要强制使用Authentication
标题,我希望有一个传递凭据的提示窗口:https://developer.mozilla.org/en-US/docs/Web/HTTP/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'
端点工作正常,但无法获得传递凭据的提示窗口。我设置了GatewayResponse
根据这个https://medium.com/@Da_vidgf/http-basic-auth-with-api-gateway-and-serverless-5ae14ad0a270 https://medium.com/@Da_vidgf/http-basic-auth-with-api-gateway-and-serverless-5ae14ad0a270但我不想提供额外的 lambda 函数,它只负责用户的授权。
就我而言,我无法在执行最终的 lambda 函数之前对用户进行授权,因为该函数仅转发请求(也转发凭据),仅此而已。
有没有人尝试过使用无服务器和 AWS lambda 在没有额外授权者的情况下使用提示窗口设置基本身份验证?