LionC / express-basic-auth

Plug & play basic auth middleware for express
325 stars 57 forks source link

Challenge doesn't show up on lambda / serverless API #42

Closed jakowenko closed 9 months ago

jakowenko commented 2 years ago

I'm running an express API with an AWS Lambda proxy function using @vendia/serverless-express. Locally the route produces the challenge prompt, but when deployed I only get the 401 unauthorized and am never prompted to enter the login information.

Does something else need to be done with serverless APIs or something specifically with AWS / Lambda?

router.use(
    '/docs',
    basicAuth({
      users: { admin: 'supersecret' },
      challenge: true,
    }),
    swaggerUi.serve,
    swaggerUi.setup(spec, {
      swaggerOptions: { persistAuthorization: true },
    })
  );
kmluns commented 1 year ago

Hey, I'm also looking for an answer. I also find that the problem was caused by the missing header WWW-Authenticate: Basic. So, the browser doesn't open the dialog for information.

Also, AWS Lambda or Http Integration remapped the WWW-Authenticate header. You can read here.

Also, you can follow that.

This looks like a solution but is still a temporary and bad solution.

So, you must do basic auth on the HTTP layer in aws.

Also, there is another reading for how you should do basic auth in AWS Serverless.

LionC commented 9 months ago

See @kmluns answer, seems to be out of scope for this middleware.