From 5661173f8ae134ce064b7f746e7014d9c708025d Mon Sep 17 00:00:00 2001 From: David K Roberts Date: Sun, 27 May 2012 14:42:16 -0700 Subject: [PATCH 1/4] Created NonExistent Scoped User Error --- lib/requestMethods.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/requestMethods.js b/lib/requestMethods.js index 478c810..7b63d6d 100644 --- a/lib/requestMethods.js +++ b/lib/requestMethods.js @@ -155,17 +155,21 @@ module.exports.isUnAuthenticated= function(scope) { }; module.exports.logout= function( authContext, logoutHandler, middlewareCallback ) { - var ad= this.getAuthDetails(); - ad.trace( "Logout", authContext.scope, "!!!" ); - var user; - if( authContext.scope === undefined) { - user= ad.user; - delete ad.user; - ad.scopedUsers= {}; - } - else { - user= ad.scopedUsers[authContext.scope].user; - delete ad.scopedUsers[authContext.scope].user; - } - logoutHandler( authContext, user, middlewareCallback ); + var ad= this.getAuthDetails(); + ad.trace( "Logout", authContext.scope, "!!!" ); + var user; + if( authContext.scope === undefined) { + user= ad.user; + delete ad.user; + ad.scopedUsers= {}; + } + else { + try { + user= ad.scopedUsers[authContext.scope].user; + delete ad.scopedUsers[authContext.scope].user; + } catch(error){ + throw new Error('ScopeError: there are no user credentials associated with the SCOPE requested (' + authContext.scope + ')'); + } + } + logoutHandler( authContext, user, middlewareCallback ); }; \ No newline at end of file From 83932fedf9e9703d04f97bf0db82f4230fabaae1 Mon Sep 17 00:00:00 2001 From: David K Roberts Date: Mon, 28 May 2012 20:24:07 -0700 Subject: [PATCH 2/4] Added an optional error callback to the middlewareCallBack for scope erroring --- lib/auth_middleware.js | 4 ++-- lib/requestMethods.js | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/auth_middleware.js b/lib/auth_middleware.js index 6f7e32b..08fbf9d 100644 --- a/lib/auth_middleware.js +++ b/lib/auth_middleware.js @@ -81,7 +81,7 @@ module.exports = function(optionsOrStrategy) { middlewareCallback= scope; scope= undefined; } - RequestMethods.logout.call( this, {scope:scope, request:req, response:res}, logoutHandler, function() { + RequestMethods.logout.call( this, {scope:scope, request:req, response:res}, logoutHandler, function(err) { //Clear out the saved auth details //TODO: this should be scope-aware. createAuthDetails( req ); @@ -90,7 +90,7 @@ module.exports = function(optionsOrStrategy) { traceFunction( message, {scope:scope, request:req, response:res}, linePrefix ); }; - if( middlewareCallback) middlewareCallback(); + if( middlewareCallback) middlewareCallback(err); }) }; diff --git a/lib/requestMethods.js b/lib/requestMethods.js index 7b63d6d..3d470ed 100644 --- a/lib/requestMethods.js +++ b/lib/requestMethods.js @@ -1,3 +1,4 @@ + /*! * Copyright(c) 2010 Ciaran Jessup * MIT Licensed @@ -156,6 +157,7 @@ module.exports.isUnAuthenticated= function(scope) { module.exports.logout= function( authContext, logoutHandler, middlewareCallback ) { var ad= this.getAuthDetails(); + var err = null; ad.trace( "Logout", authContext.scope, "!!!" ); var user; if( authContext.scope === undefined) { @@ -168,8 +170,8 @@ module.exports.logout= function( authContext, logoutHandler, middlewareCallback user= ad.scopedUsers[authContext.scope].user; delete ad.scopedUsers[authContext.scope].user; } catch(error){ - throw new Error('ScopeError: there are no user credentials associated with the SCOPE requested (' + authContext.scope + ')'); + err = new Error('There are no user credentials associated with the scope: "' + authContext.scope + '"', "sdfsdf"); } } - logoutHandler( authContext, user, middlewareCallback ); + logoutHandler( authContext, user, middlewareCallback(err)); }; \ No newline at end of file From 3abeabee0f457a93582e55b664918d93448b0756 Mon Sep 17 00:00:00 2001 From: David K Roberts Date: Mon, 28 May 2012 20:29:16 -0700 Subject: [PATCH 3/4] Code Cleanup --- lib/requestMethods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/requestMethods.js b/lib/requestMethods.js index 3d470ed..555d05f 100644 --- a/lib/requestMethods.js +++ b/lib/requestMethods.js @@ -170,7 +170,7 @@ module.exports.logout= function( authContext, logoutHandler, middlewareCallback user= ad.scopedUsers[authContext.scope].user; delete ad.scopedUsers[authContext.scope].user; } catch(error){ - err = new Error('There are no user credentials associated with the scope: "' + authContext.scope + '"', "sdfsdf"); + err = new Error('There are no user credentials associated with the scope: "' + authContext.scope + '"'); } } logoutHandler( authContext, user, middlewareCallback(err)); From 32a8cf131d3e753fad5535f2cce5c1103db721fa Mon Sep 17 00:00:00 2001 From: David K Roberts Date: Mon, 28 May 2012 20:53:42 -0700 Subject: [PATCH 4/4] More Code Cleanup --- lib/requestMethods.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/requestMethods.js b/lib/requestMethods.js index 555d05f..492fb1e 100644 --- a/lib/requestMethods.js +++ b/lib/requestMethods.js @@ -156,10 +156,9 @@ module.exports.isUnAuthenticated= function(scope) { }; module.exports.logout= function( authContext, logoutHandler, middlewareCallback ) { + var user, err; var ad= this.getAuthDetails(); - var err = null; ad.trace( "Logout", authContext.scope, "!!!" ); - var user; if( authContext.scope === undefined) { user= ad.user; delete ad.user; @@ -170,7 +169,7 @@ module.exports.logout= function( authContext, logoutHandler, middlewareCallback user= ad.scopedUsers[authContext.scope].user; delete ad.scopedUsers[authContext.scope].user; } catch(error){ - err = new Error('There are no user credentials associated with the scope: "' + authContext.scope + '"'); + err= new Error('There are no user credentials associated with the scope: "' + authContext.scope + '"'); } } logoutHandler( authContext, user, middlewareCallback(err));