Browse files

Fix openid

  • Loading branch information...
1 parent 476fb45 commit 19acf94dfaf51272981edce46ff5fabba8864243 @ciaranj committed Feb 29, 2012
Showing with 11 additions and 9 deletions.
  1. +2 −2 examples/app.js
  2. +1 −1 examples/mac/app.js
  3. +8 −6 lib/auth.strategies/openid.js
View
4 examples/app.js
@@ -45,7 +45,7 @@ var unAuthenticatedContent= fs.readFileSync( __dirname+"/public/unauthenticated.
// This middleware detects login requests (in this case requests with a query param of ?login_with=xxx where xxx is a known strategy)
var example_auth_middleware= function() {
return function(req, res, next) {
- var urlp= url.parse(req.url, true)
+ var urlp= url.parse(req.originalUrl, true)
if( urlp.query.login_with ) {
req.authenticate([urlp.query.login_with], function(error, authenticated) {
if( error ) {
@@ -106,7 +106,7 @@ app.use(connect.static(__dirname + '/public'))
res.end( authenticatedContent.replace("#USER#", JSON.stringify( req.getAuthDetails().user ) ) );
}
else {
- res.end( unAuthenticatedContent.replace("#PAGE#", req.url) );
+ res.end( unAuthenticatedContent.replace("#PAGE#", req.originalUrl) );
}
})
.listen(80);
View
2 examples/mac/app.js
@@ -70,7 +70,7 @@ function logConsole() {
return function (req, res, next) {
- console.log('Received request: ' + req.method + ' ' + req.url);
+ console.log('Received request: ' + req.method + ' ' + req.originalUrl);
next();
};
View
14 lib/auth.strategies/openid.js
@@ -41,23 +41,25 @@ module.exports= function(options) {
that.authenticate= function(request, response, callback) {
var self= this;
- var parsedUrl= url.parse(request.url, true);
+ var parsedUrl= url.parse(request.originalUrl, true);
if( request.getAuthDetails()['openid_login_attempt_failed'] === true ) {
// Because we bounce through authentication calls across multiple requests
// we use this to keep track of the fact we *Really* have failed to authenticate
// so that we don't keep re-trying to authenticate forever.
delete request.getAuthDetails()['openid_login_attempt_failed'];
self.fail( callback );
}
- else if( request.session['openid_redirect_url'] ) {
+ else if( parsedUrl.pathname == that.verifyPath ) {
self.trace( 'Phase 2/2 - Verifying OpenId' )
- var result = relyingParty.verifyAssertion(request, function( error, result ) {
- if( error === undefined && result.authenticated ) {
+ var result = relyingParty.verifyAssertion(request.originalUrl, function( error, result ) {
+ console.log( error)
+ if( result && result.authenticated ) {
var user= {user_id: result.claimedIdentifier };
self.success( user, callback );
}
else {
- self.trace( 'Problem Verifying OpenId - ' + JSON.stringify(error) )
+ if( error ) self.trace( 'Error Verifying OpenId - ' + JSON.stringify(error) )
+ else self.trace( 'Verifying OpenId Failed - ' + JSON.stringify(result) )
request.getAuthDetails()['openid_login_attempt_failed'] = true;
self.fail( callback );
}
@@ -79,7 +81,7 @@ module.exports= function(options) {
}
else {
delete request.getAuthDetails()['openid_login_attempt_failed'];
- request.session['openid_redirect_url']= request.url;
+ request.session['openid_redirect_url']= request.originalUrl;
self.redirect(response, authUrl, callback);
}
});

0 comments on commit 19acf94

Please sign in to comment.