问题描述
我已经尝试了几周来使Node.js Web API正常工作,但是现在我不得不承认,我不知道我还能尝试什么。我是IIS / Active Directory的新手,对Node.js也没有太多的经验,请原谅我,如果这是一个愚蠢的问题。
我有一个非常基本的Express应用程序,它在IIS服务器上运行,一切正常,直到我尝试获取有关使用诸如node-expose-sspi或node-sspi之类的用户登录的Active Directory的一些信息(主要是组)。 如果我从命令行运行我的应用程序,那么一切都很好,并且我得到了我需要的所有数据(通过浏览器和Postman查询localhost:3000 / api / test),但是在IIS上运行并通过浏览器查询url的相同代码要求在不接受凭据的情况下继续使用凭据,并将结果取消给未经授权的401。将邮递员与NTLM身份验证一起使用会立即导致401。这使我认为,可能是IIS上的某些设置,我只是没有得到,所以非常感谢您的帮助。
在我当前的server.js下面,该注释在行app.use(sso.auth());
处一直起作用:
"use strict";
const express = require('express');
const app = express();
const { sso } = require('node-expose-sspi');
const port = process.env.PORT || 3000;
//app.use(sso.auth());
app.get('/api/test',(req,res) => {
var authuser = req.headers['x-iisnode-auth_user'];
var logonuser = req.headers['x-iisnode-logon_user'];
var authtype = req.headers['x-iisnode-auth_type'];
//res.status(200).json({"status": "OK","requestUrl": req.headers.host + req.url,"user": req.sso});
res.status(200).json({"status": "OK","auth_user": authuser,"logon_user": logonuser,"auth_type": authtype});
});
app.listen(port,() => {
console.log(`API running at port: ${port}/`);
});
这是我的web.config:
<configuration>
<system.webServer>
<!-- indicates that the server.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="sendToNode">
<match url="/*" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
<iisnode promoteServerVars="logoN_USER,AUTH_USER,AUTH_TYPE" />
</system.webServer>
<system.web>
<authentication mode="Windows" />
</system.web>
</configuration>
在IIS上,我仅启用Windows身份验证,在.NET授权规则中允许所有用户使用,并且对应用程序所在目录中的IIS_IUSRS具有完全控制权。到底该怎么做?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)