Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lambda-api integration #917

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/middleware/authenticate.js
Expand Up @@ -91,6 +91,13 @@ module.exports = function authenticate(passport, name, options, callback) {
multi = false;
}

function isLambdaApiResponse(res) {
return typeof res === 'object' &&
typeof res.setHeader === 'undefined' &&
typeof res.location === 'function' &&
typeof res.end === 'undefined';
}

return function authenticate(req, res, next) {
req.login =
req.logIn = req.logIn || IncomingMessageExt.logIn;
Expand Down Expand Up @@ -160,7 +167,7 @@ module.exports = function authenticate(passport, name, options, callback) {
failure = failures[j];
challenge = failure.challenge;
status = failure.status;

rstatus = rstatus || status;
if (typeof challenge == 'string') {
rchallenge.push(challenge);
Expand Down Expand Up @@ -326,8 +333,15 @@ module.exports = function authenticate(passport, name, options, callback) {
// Express 4.x: res.redirect(status, url)
// - all versions (as of 4.8.7) continue to accept res.redirect(url, status)
// but issue deprecated versions
var statusCode = status || 302;

res.statusCode = status || 302;
if (isLambdaApiResponse(res)) {
res.location(url).status(statusCode);
res.send({});
return;
}

res.statusCode = statusCode;
res.setHeader('Location', url);
res.setHeader('Content-Length', '0');
res.end();
Expand Down