Reputation: 131
I have problem with creating node.js application based on express with http-auth module.
It's a possible create Middleware for this http-auth library I have this code:
//Configure Middlewares
logger.configure(function() {
//All output has content type json
logger.use(function(req, res, next) {
res.contentType('application/json');
next();
});
//Create digest auth middleware
logger.use(function(req, res, next){
digest.apply();
next();
});
});
After applying this, when I connect to site I get this error:
TypeError: Cannot read property 'headers' of undefined
Is there any solution for this problem or use another method?
I need digest auth for the whole application.
Upvotes: 1
Views: 1137
Reputation: 5055
You should just use it with correct pattern:
// Authentication module.
var auth = require('http-auth');
var digest = auth.digest({
realm: "Simon Area.",
file: __dirname + "/../data/users.htdigest"
});
// Configure Middlewares
logger.configure(function() {
// Create digest auth middleware
logger.use(auth.connect(digest));
// All output has content type json.
logger.use(function(req, res, next) {
res.contentType('application/json');
next();
});
});
Upvotes: 0
Reputation: 32391
I think apply() is expecting the request object (hence it can't read the headers);
try this syntax:
digest.apply(req, res, function(username) {
});
Upvotes: 1