NodeJS + Express + Passport + IIS [英] NodeJS + Express + Passport + IIS
问题描述
我正在部署使用Windows身份验证的node + express应用程序.为此,我遵循了PassportJS Windows-auth文档.但是我面临错误=>
I am deploying my node+express application which uses windows authentication. I followed the PassportJS windows-auth documentation for this. But I am facing error =>
iisnode在处理请求时遇到错误.
iisnode encountered an error when processing the request.
HRESULT:0x2HTTP状态:500HTTP子状态:1002HTTP原因:内部服务器错误您正在收到此HTTP 200响应,因为system.webServer/iisnode/@devErrorsEnabled配置设置为'true'.
HRESULT: 0x2 HTTP status: 500 HTTP subStatus: 1002 HTTP reason: Internal Server Error You are receiving this HTTP 200 response because system.webServer/iisnode/@devErrorsEnabled configuration setting is 'true'.
除了node.exe进程的stdout和stderr日志外,还考虑使用调试和ETW跟踪进一步诊断问题.
In addition to the log of stdout and stderr of the node.exe process, consider using debugging and ETW traces to further diagnose the problem.
node.exe进程生成的输出到stderr的最后64k如下所示:
The last 64k of the output generated by the node.exe process to stderr is shown below:
应用程序引发了未捕获的异常并被终止:错误:身份验证策略必须具有名称在Passport.use(C:\ Workspace \ Trial \ node_modules \ passport \ lib \ passport \ index.js:51:20)在对象.(C:\ Workspace \ Trial \ server.js:7:10)在Module._compile(内部/模块/cjs/loader.js:689:30)在Object.Module._extensions..js(内部/模块/cjs/loader.js:700:10)在Module.load(internal/modules/cjs/loader.js:599:32)在tryModuleLoad(内部/模块/cjs/loader.js:538:12)在Function.Module._load(internal/modules/cjs/loader.js:530:3)在Module.require(internal/modules/cjs/loader.js:637:17)在要求时(内部/模块/cjs/helpers.js:22:18)在对象.(C:\ Program Files(x86)\ iisnode \ interceptor.js:210:1)
Application has thrown an uncaught exception and is terminated: Error: authentication strategies must have a name at Passport.use (C:\Workspace\Trial\node_modules\passport\lib\passport\index.js:51:20) at Object. (C:\Workspace\Trial\server.js:7:10) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18) at Object. (C:\Program Files (x86)\iisnode\interceptor.js:210:1)
server.js
server.js
<configuration>
<system.webServer>
<iisnode promoteServerVars="LOGON_USER" />
<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>
</system.webServer>
<system.web>
<authentication mode="Windows" />
</system.web>
</configuration>
web.config
web.config
var express = require('express');
var app = express();
var passport = require('passport');
var WindowsStrategy = require('passport-windowsauth');
passport.use(function(profile, done){
User.findOrCreate({ waId: profile.id }, function (err, user) {
done(err, user);
});
});
app.get('/NodeTrialLogon/', function (req, res) {
res.send('Express is workin on IISNode!');
});
app.get('/NodeTrialLogon/express-passport',
passport.authenticate('WindowsAuthentication'),
function (req, res){
res.json(req.user);
});
app.listen(process.env.PORT);
请帮助.我已在IIS中启用Windows身份验证,并禁用了所有其他形式的身份验证.
Please help. I have enabled windows authentication in IIS and disabled all other forms of authentication.
推荐答案
似乎您导入WindowsStrategy但从未使用过.您可以尝试以下操作(如此GitHub问题中的建议)
It seems like you import WindowsStrategy but never use it. You could try the following (as suggested in this GitHub issue)
passport.use(new WindowsStrategy({
integrated: true
},
function(profile, done) {
User.findOrCreate({ waId: profile.id }, function (err, user) {
done(err, user);
});
}
));
然后,您还可以为策略命名,作为 passport.use()
You could also then give a name to your strategy as the first argument of passport.use()
passport.use('MyAuthStrategy', new WindowsStrategy(
// ...
));
然后在经过身份验证的路由中指定此名称
And then specify this name in your authenticated routes
passport.authenticate('MyAuthStrategy')
这篇关于NodeJS + Express + Passport + IIS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!