【问题标题】:Nodejs, authentication through https and redirect to httpNodejs,通过https认证并重定向到http
【发布时间】:2011-09-16 14:47:06
【问题描述】:
我(在 node.js 中)开发了一个简单的站点(例如:http://www.mydomain.com),我希望允许客户端通过 https 进行身份验证(例如:https://www.mydomain.com/login)。成功验证后,它们会被重定向到我的网站 http...(不安全)
我该怎么做?我创建了两个简单的文件(mydomain.js 和 mydomainsecure.js),我在两个不同的端口(http 为 80,https 为 443)上运行两个节点实例,但在 https 登录后(并重定向到 http)我不是登录(显然????)
实现这个的正确方法是什么?
【问题讨论】:
标签:
authentication
node.js
https
【解决方案2】:
您可以为此使用http-auth 模块:
// Authentication module.
var auth = require('http-auth');
var basic = auth.basic({
realm: "Simon Area.",
file: __dirname + "/../data/users.htpasswd" // gevorg:gpass, Sarah:testpass ...
});
// Creating new HTTP server.
http.createServer(basic, function(req, res) {
res.end("Welcome to private area - " + req.user + "!");
}).listen(1337);