使用express-ntlm进行ldap身份验证

时间:2019-09-10 16:27:01

标签: node.js reactjs express-ntlm

我尝试用React-js应用程序的express-ntlm实现一个sso系统

我使用了npm软件包网站中express-ntlm的提供示例 当我仅使用浏览器时,它可以正常工作,但是当我将其与react app一起使用时,出现错误504或401错误(已修复)

express-ntlm代码

http://localhost:3553/getAuthenticate上运行的应用

app.use(function(req, res, next) {
     res.header("Access-Control-Allow-Origin", "*");
     res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
     res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
     res.header("Access-Control-Request-Method", "POST,GET,*");
     next();
   });

 app.use(ntlm({
     debug: function() {
         var args = Array.prototype.slice.apply(arguments);
         console.log.apply(null, args);
     },
     domain: 'bridgebankgroup.com',
     domaincontroller: 'ldap://mydomaine.com:389',

 }));
 app.all('/getAuthenticate', function(request, response,next) {

     stringParam=request.ntlm.UserName;
     console.log(request);
     response.send({resp:stringParam}); 
   next(err,{
     function(){response.send({resp:stringParam})} 
 })

然后我使用了componentWillMount()内部的fetch来在挂载组件时(在react应用中)强制进行身份验证

componentDidMount(){
         fetch('/getAuthenticate',
        {
          method: 'GET',
          headers:
          {
            'Content-Type': 'application/json',
          }
        },
        ).then(res => res)
        .then(
        (result) => {
        console.log(result)
        },
        (error) => {
          console.log(error.status);
        });
}
./src/setupProxy.js中的

代理配置

module.exports = function(app) {
  app.use('/getAuthenticate', proxy({
    target: 'http://localhost:3553/',
    changeOrigin: true,
  }));
};

我想调用此应用以了解用户使用我的应用

0 个答案:

没有答案
相关问题