From 901da88842a72cc95796c96e559f6694533e98f7 Mon Sep 17 00:00:00 2001 From: Kieron Wiltshire Date: Thu, 6 Jul 2017 14:51:45 +0100 Subject: [PATCH 1/3] Added the ability to continue without token This allows the ability to explicitly check specific routes. --- index.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 99cd158..5d3635a 100644 --- a/index.js +++ b/index.js @@ -40,22 +40,28 @@ function ExpressOAuthServer(options) { */ ExpressOAuthServer.prototype.authenticate = function(options) { - var that = this; - - return function(req, res, next) { - var request = new Request(req); - var response = new Response(res); + const self = this; + options = options || {}; - return Promise.bind(that) + return function(request, response, next) { + return Promise.bind(self) .then(function() { - return this.server.authenticate(request, response, options); + return this.server.authenticate(new Request(request), new Response(response), options); }) .tap(function(token) { - res.locals.oauth = { token: token }; - next(); + _.extend(response.context, { + oauth: { + token + } + }); + return next(); }) - .catch(function(e) { - return handleError.call(this, e, req, res, null, next); + .catch(function(error) { + if (typeof options.catchErrorAndContinue !== 'undefined' && options.catchErrorAndContinue) { + return next(); + } else { + return handleError.call(this, error, request, response, null, next); + } }); }; }; From 1dd89158bc5c1038343eda540c2921edb7242fc1 Mon Sep 17 00:00:00 2001 From: Kieron Wiltshire Date: Thu, 6 Jul 2017 15:04:02 +0100 Subject: [PATCH 2/3] Update index.js --- index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/index.js b/index.js index 5d3635a..5d0eaab 100644 --- a/index.js +++ b/index.js @@ -49,11 +49,7 @@ ExpressOAuthServer.prototype.authenticate = function(options) { return this.server.authenticate(new Request(request), new Response(response), options); }) .tap(function(token) { - _.extend(response.context, { - oauth: { - token - } - }); + response.oauth = { token: token }; return next(); }) .catch(function(error) { From 170c13ae68672bef8c1f7fb1935d9c7f84ab3315 Mon Sep 17 00:00:00 2001 From: Kieron Wiltshire Date: Thu, 6 Jul 2017 15:17:41 +0100 Subject: [PATCH 3/3] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 5d0eaab..5822b30 100644 --- a/index.js +++ b/index.js @@ -49,7 +49,7 @@ ExpressOAuthServer.prototype.authenticate = function(options) { return this.server.authenticate(new Request(request), new Response(response), options); }) .tap(function(token) { - response.oauth = { token: token }; + request.oauth = { token: token }; return next(); }) .catch(function(error) {