使用 HTTP-AUTH 的 Node.js Express

标签 node.js express http-authentication digest-authentication http-auth

我在使用http-auth创建基于express的node.js应用程序时遇到问题模块。

可以为这个 http-auth 库创建中间件,我有以下代码:

    //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();
  });
});

应用此后,当我连接到网站时,出现此错误:

TypeError: Cannot read property 'headers' of undefined

有没有办法解决这个问题或者使用其他方法?

我需要对整个应用程序进行摘要身份验证。

最佳答案

我认为 apply() 需要请求对象(因此它无法读取 header );

尝试这个语法:

digest.apply(req, res, function(username) {

});   

关于使用 HTTP-AUTH 的 Node.js Express,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15385819/

相关文章:

node.js - 缺少 node-v59-linux-x64/grpc_node.node

javascript - 使用 underscore.js 加载模板时再次调用 document.ready

javascript - 客户端通过 websocket 连接从后端服务器数据库表检索数据

node.js - Connect 和 Express 实用程序

apache-flex - Flex 3 - 如何支持 HTTP Authentication URLRequest?

javascript - 访问全局变量javascript

javascript - 获取类型错误 : FabricUserControllers is not a constructor which can not be catch

angularjs - 在不同的服务器上序列化多个数据库

java - HttpURLConnection认证方式

javascript - 抑制浏览器的身份验证对话框