Adds Flatiron/union support to Passport #24

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants

Fixes the following issue:

  ],
  "stack": [
    "TypeError: Object [object Object] has no method 'logIn'",
    "    at /Users/zeus.lalkaka/Soapbox/app.js:137:21",
    "    at Context.<anonymous> (/Users/zeus.lalkaka/Soapbox/node_modules/passport/lib/passport/middleware/authenticate.js:71:16)",
    "    at Context.<anonymous> (/Users/zeus.lalkaka/Soapbox/node_modules/passport/lib/passport/context/http/actions.js:21:25)",
    "    at Strategy.success (native)",
    "    at /Users/zeus.lalkaka/Soapbox/node_modules/passport-local/lib/passport-local/strategy.js:79:10",
    "    at /Users/zeus.lalkaka/Soapbox/app.js:51:16",
    "    at findByUsername (/Users/zeus.lalkaka/Soapbox/app.js:32:14)",
    "    at Array.0 (/Users/zeus.lalkaka/Soapbox/app.js:47:7)",
    "    at EventEmitter._tickCallback (node.js:192:40)"
  ],
  "level": "error",
  "message": "uncaughtException"
}
Owner

jaredhanson commented May 29, 2012

FYI: This is merged into a branch: https://github.com/jaredhanson/passport/tree/flatiron

Will make its way to master in some form soon...

Is there something going on about this one?

Yes, there is a branch that has this change merged into it:

https://github.com/jaredhanson/passport/tree/flatiron

However, if your just doing basic auth, I suggest you simply write your own tiny function (with the help of the http-auth module) to handle this, and then insert it into your "before" property when initializing the HTTP Flatiron module.

Example below:

var   flatiron = require('flatiron')
    , connect = require('connect')
    , auth = require('http-auth')
    , App = flatiron.app;

var basic = auth({
    authRealm : "Enter your Credentials", 
   // [username] : [encrypted password]
    authList : ['user:{SHA}oZAxaxasd2bmaacQjfGfYgskgvSehA=']
});


process.env.HOSTNAME = process.env.HOSTNAME || "localhost";

App.use(flatiron.plugins.http, {
    before: [                       
        function(req, res) {
            if (req.request.url.indexOf('admn') > -1) { 
                       // You can ignore this little bit of logic, this is just something I put together to redirect users from HTTP to HTTPS
                if (req.headers['x-forwarded-proto'] !== 'https' && process.env.HOSTNAME !== 'localhost:8000') {
                    res.writeHead(200, {'Content-Type': 'text/html'});
                    var targetURL = 'https://' + process.env.HOSTNAME + req.url;
                    // res.end('Please use <a href=' + targetURL + '>' + targetURL + '</a>');
                    res.writeHead(302, {'Location': targetURL});
                    res.end();
                } else {        
                    basic.apply(req,res,function(username) {            
                        res.emit('next');
                        console.log(username + " Authenticated");
                    });
                }
                // console.log(username + " FAILED AUTHENTICATION");
                // res.end(404);
            } else {
                res.emit('next');
            }

        },  
                // All other middleware... you can ignore this for the most part as it has nothing to do with auth, but
                // but simply gives you some context.
        connect.static(__dirname + '/static'),
        connect.methodOverride()        
    ],

    after: []
});

Yes, I am aware of the branch, but is there any chance on this going into master?

Also, thanks for the snippet, I'll have a look at it later.

Owner

jaredhanson commented Jul 15, 2012

Yes, I intend to get this to master.

For the sake of maintainability, I'd like to find a better solution than try/catch'ing a bunch of different frameworks. I have some ideas for another plugin-style hook for framework support, but haven't had time to actually implement it.

Now that API support completed (and related OAuth server middleware implemented), I'm hopeful that I'll get the time to focus on this in the next week or two.

Glad to hear it!
For now I'm stick to #flatiron branch.

Owner

jaredhanson commented Feb 9, 2013

Related: passport-twitter issue #6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment