authentication - Persistant Login with connect-auth -
i'm building node.js , using connect-auth user/pass authentication, , i'd allow users logged in long periods of time. playing around , looking through source seems connect-auth depends on connect sessions maintain authenticated state, once session cookie expires (default 4 hrs) user gets logged out.
one option fork connect-auth , refactor not dependent on req.session, that's non-trivial. option change default age on session cookie high, want session object able die session.
anyone have suggestions? overlooking existing solution?
thanks!
i wouldn't use/fork connect-auth. plugin of connect breaks onion ring idea/architecture of connect , makes (imho) code unreadable/brings unnecessary complexity.
authentification simple library. (if talking simple user login)
i'm using self written auth. can find simplified version below. depends on session-cookies can replaced persistant cookies.
a simple authentication connect
(it's complete. execute testing)
var connect = require('connect'); var urlpaser = require('url'); var authcheck = function (req, res, next) { url = req.urlp = urlpaser.parse(req.url, true); // #### // logout if ( url.pathname == "/logout" ) { req.session.destroy(); } // #### // user validated? if (req.session && req.session.auth == true) { next(); // stop here , pass next onion ring of connect return; } // ######## // auth - replace simple if database or file or whatever... // if database, need async callback... if ( url.pathname == "/login" && url.query.name == "max" && url.query.pwd == "herewego" ) { req.session.auth = true; next(); return; } // #### // user not unauthorized. stop talking him. res.writehead(403); res.end('sorry unauthorized.\n\nfor login use: /login?name=max&pwd=herewego'); return; } var helloworldcontent = function (req, res, next) { res.writehead(200, { 'content-type': 'text/plain' }); res.end('authorized. walk around :) or use /logout leave\n\nyou @ '+req.urlp.pathname); } var server = connect.createserver( connect.logger({ format: ':method :url' }), connect.cookieparser(), connect.session({ secret: 'foobar' }), connect.bodyparser(), authcheck, helloworldcontent ); server.listen(3000);
Comments
Post a Comment