Actually my bad, but I am very new to node, connect and express. I
went through few examples in connect and the auth was just drop in "as-
is" in express.
Thanks a lot.
/**** Pasting code here as it may help someone else ***/
var express = require('express'),
auth= require('connect-auth');
var getPasswordForUserFunction= function(user, callback) {
var result;
if( user == 'foo' )
result= 'bar';
callback(null, result);
}
var app = express.createServer(
auth(
[auth.Basic({getPasswordForUser: getPasswordForUserFunction})]
),
//express.cookieDecoder(),
//express.session(),
//express.logger(),
express.staticProvider());
app.get('/', function(req, res) {
req.authenticate(['basic'], function(error, authenticated) {
console.log(JSON.stringify(error));
console.log(JSON.stringify(authenticated));
var obj = ["1","2","3","4"];
var body = JSON.stringify(obj);
res.writeHead(200, {
"Content-Type": "application/json",
});
res.end(body);
});
});
app.listen(3000);