Passport身份验证的应用程序sails.js不工作 [英] Passport authentication not working in sails.js application

查看:234
本文介绍了Passport身份验证的应用程序sails.js不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JS风帆应用。我使用Passport.js验证层帆生成-auth的试图设定验证。我已经按照其文档中给出​​的步骤配置的我的应用程序。

I have a Sails JS application. I am trying to setup authentication using Passport.js authentication layer sails-generate-auth. I have configured my app by following the steps given in their documentation.

但是,当我举起我的船帆的应用程序,认证不工作。我能够访问控制器,即使我不是(这不是重定向到我的登录页)记录。

But when I lift my sails app, authentication is not working. I am able to access the controllers, even when I am not logged in (It's not redirecting to my login page).

API /政策/ passport.js增加了一个的console.log 语句如下:

I added a console.log statement in api/policies/passport.js as follows:

module.exports = function (req, res, next) {
  passport.initialize()(req, res, function () {
    passport.session()(req, res, function () {
      res.locals.user = req.user;
      console.log(req.user); // added by me
      next(); 
    });
  });
};

现在,当我登录前或注销后访问控制器,它的印刷未定义。但是,当我登录时,其打印我的用户数据。任何想法,为什么它不检查验证?

Now, when I access controllers before login or after logout, its printing undefined. But when I am logged in, its printing my user data. Any idea why it is not checking for authentication?

我公司采用本地认证策略和我都注释掉了所有其他(推特,脸谱......)

I am using local authentication strategy and I have commented out all others (twitter, facebook...)

推荐答案

护照没有一个政策,拒绝访问控制器。对于这一点,你必须创建另一个策略。

Passport doesn't have a policy to deny access to a controller. For this, you have to create another policy.

有关详细信息,请参阅此链接

See this link for more details.

这篇关于Passport身份验证的应用程序sails.js不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆