Skip to content

Commit

Permalink
Addresses Issue 62 - Allows authentication scope knowledge to survive…
Browse files Browse the repository at this point in the history
… redirects
  • Loading branch information
ciaranj committed Sep 4, 2011
1 parent b8a5a04 commit 2a68422
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/requestMethods.js
Expand Up @@ -53,10 +53,17 @@ module.exports.authenticate= function(strategy, opts, callback, strategyExecutor
}
}

// Sometimes the authentication scope needs to passed between requests, we store this information
// transiently on the session.
if( scope === undefined && req.getAuthDetails().__performingAuthentication && req.getAuthDetails().__originalScope ) {
scope= req.getAuthDetails().__originalScope;
}

trace( "Authenticating ("+this.headers.host + this.url+")", scope, ">>>" );
if( req.isAuthenticated(scope) ) {
delete req.getAuthDetails().__performingAuthentication;
delete req.getAuthDetails().__originalUrl;
delete req.getAuthDetails().__originalScope;
trace( "Authentication successful (Already Authenticated)", scope, "<<<" );
callback(null, true);
}
Expand All @@ -75,6 +82,7 @@ module.exports.authenticate= function(strategy, opts, callback, strategyExecutor
if(error) {
delete req.getAuthDetails().__performingAuthentication;
delete req.getAuthDetails().__originalUrl;
delete req.getAuthDetails().__originalScope
trace( "Authentication error: "+ error, scope, "<<<" );
callback(error);
}
Expand All @@ -83,7 +91,8 @@ module.exports.authenticate= function(strategy, opts, callback, strategyExecutor
trace( "Authentication successful", scope, "<<<" );
executionResult.originalUrl= req.getAuthDetails().__originalUrl;
delete req.getAuthDetails().__originalUrl;

delete req.getAuthDetails().__originalScope

if( scope === undefined) {
req.getAuthDetails().user= executionResult.user;
}
Expand Down Expand Up @@ -111,12 +120,14 @@ module.exports.authenticate= function(strategy, opts, callback, strategyExecutor
else if( executionResult.authenticated === false ) {
delete req.getAuthDetails().__performingAuthentication;
delete req.getAuthDetails().__originalUrl;
delete req.getAuthDetails().__originalScope;
trace( "Authentication failed", scope, "<<<" );
callback(null, executionResult.authenticated)
}
else {
req.getAuthDetails().__performingAuthentication= true;
req.getAuthDetails().__originalUrl= req.url;
req.getAuthDetails().__originalScope= scope;
trace( "Authentication ongoing (Requires browser interaction)", scope, "<<<" );
callback(null, executionResult.authenticated)
}
Expand Down

0 comments on commit 2a68422

Please sign in to comment.