Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/middleware/authenticate.js
Original file line number Diff line number Diff line change
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