Tag: passport.js

PassportJS反序列化用户从未调用过

我有Passport安装程序来validation存储在mongodb中的用户。 似乎工作正常:身份validation成功/失败适当和会话variables设置。 但是,获得护照检查会话失败。 一些东西似乎是相当错误的,我添加到deserializeUsercallback的console.log语句永远不会看到白天的光芒。 我认为我的问题是关系到deserializeUser永远不会被调用。 任何人都可以诊断我的失误? // Passport configuration passport.serializeUser(function(user, cb){ cb(null, user.id) }); passport.deserializeUser(function(uid, cb){ console.log("Trying to deserialize user: "+uid); User.findById(uid, function(err, user){ cb(err, user); }); }); // auth strategy function passport.use(new LocalStrategy({usernameField: 'email'}, function(email, pass, done){ User.findOne({email: email}, function (err, user) { if (err) return done(err); if (!user) return done(null, false, {message: "Couldn't […]

护照的req.isAuthenticated总是返回false,即使我硬编码完成(null,true)

我试图让我的护照本地策略工作。 我有这个中间件设置: passport.use(new LocalStrategy(function(username, password, done) { //return done(null, user); if (username=='ben' && password=='benny'){ console.log("Password correct"); return done(null, true); } else return done(null, false, {message: "Incorrect Login"}); })); 但在这里 app.use('/admin', adminIsLoggedIn, admin); function adminIsLoggedIn(req, res, next) { // if user is authenticated in the session, carry on if (req.isAuthenticated()) return next(); // if they aren't […]

什么是函数User.findOrCreate做什么,什么时候在护照中调用?

我无法find关于此function的文档,因此我无法使其正确工作。 什么时候该函数被调用,它在做什么,作为第一个参数是什么? 我试图从护照获取访问令牌,但无法以任何方式达到它。 passport.use(new FacebookStrategy({ clientID: APP_ID, clientSecret: APP_SECRET, callbackURL: "http://localhost:3000/", }, function(accessToken, refreshToken, profile, done) { User.findOrCreate({// what are these parameters?}, function (err, user) { // when is this function called and what is it doing? }); } )); 我怎样才能从护照获得访问令牌?

passport.js与多个身份validation提供程序?

使用Passport.js有没有办法让我为相同的路由指定多个身份validation提供程序? 例如(从护照指南)我可以在下面的示例路线上使用本地和Facebook和Twitter策略? app.post('/login', passport.authenticate('local'), /* how can I add other strategies here? */ function(req, res) { // If this function gets called, authentication was successful. // `req.user` contains the authenticated user. res.redirect('/users/' + req.user.username); });

护照本地策略没有被调用

我确定我在这里错过了一些非常明显的东西,但我无法弄清楚这一点。 当传递login表单时,我传递给LocalStrategy构造函数的函数不会被调用。 码: var express = require('express'); var http = require('http'); var path = require('path'); var swig = require('swig'); var passport = require('passport'); var LocalStrategy = require('passport-local').Strategy; passport.serializeUser(function(user, done) { console.log('Serialize user called.'); done(null, user.name); }); passport.deserializeUser(function(id, done) { console.log('Deserialize user called.'); return done(null, {name: 'Oliver'}); }); passport.use(new LocalStrategy( function(username, password, done) { console.log('local strategy […]

在Passport策略callback中获取请求对象

所以这里是我的passport-facebook策略configuration: passport.use(new FacebookStrategy({ clientID: "…..", clientSecret: "…..", callbackURL: "http://localhost:1337/register/facebook/callback", }, facebookVerificationHandler )); 这里是facebookVerificationHandler: var facebookVerificationHandler = function (accessToken, refreshToken, profile, done) { process.nextTick(function () { ……. }); }; 有没有办法访问facebookVerificationHandler中的请求对象? 用户通过LocalStrategy注册到我的网站,然后他们将能够添加他们的社交帐户,并将这些帐户与他们的本地帐户相关联。 当上面的callback被调用时,当前login的用户在req.user中已经可用,所以我需要访问req来将用户和facebook账户关联起来。 这是实施它的正确方法,还是应该考虑另一种方法? 谢谢。

validationPassport.js中的访问/组

我想使用passport.js来validation,当用户碰到某些端点时,他们不仅拥有正确的密码,而且是特定组的成员或具有一定的访问权限。 为了简单起见,如果我有访问级别的用户和pipe理员。 我可以使用护照来validation密码: passport.use(new LocalStrategy( function(username, password, done) { User.findOne({ username: username }, function(err, user) { if (err) { return done(err); } if (!user) { return done(null, false, { message: 'Incorrect username.' }); } if (!user.validPassword(password)) { return done(null, false, { message: 'Incorrect password.' }); } return done(null, user); }); } )); 然后用一个路线,我可以确保用户通过身份validation: app.get('/api/users', passport.authenticate('local'), […]

Sails.js + Passport.jsauthentication通过websockets

当我用Passport.js使用Sails.js时,当通过websocket请求req对象时,isAuthenticated方法不存在。 谁能告诉我为什么会发生这种情况?

Passport-Facebook身份validation不提供所有Facebook帐户的电子邮件

我正在使用Passport-Facebook身份validation。 passport.use(新FacebookStrategy({ clientID:'CLIENT_ID', clientSecret:'CLIENT_SECRET', callbackURL:“http://www.example.com/auth/facebook/callback” }, 函数(accessToken,refreshToken,profile,done){ process.nextTick(function(){ 执行console.log(configuration文件) }); } )); 对于一些Facebook帐户,我没有得到email_id,我甚至尝试通过使用一个范围variables如下,但我仍然无法得到email_id。 profileUrl:“”和ProfileFields:['','']

使用passport.js在node.js中进行身份validation后,redirect到上一页

我试图build立一个使用node.js,express和passport.js的login机制。 login本身工作得相当不错,会话也很好地存储在redis中,但是在提示用户进行身份validation之前,将用户redirect到他所在的位置时遇到了一些麻烦。 例如,用户链接http://localhost:3000/hidden然后被redirect到http://localhost:3000/login但是我希望他再次被redirect到http://localhost:3000/hidden 。 这样做的目的是,如果用户随机访问一个页面,他需要首先login,他应该被redirect到/ login站点提供他的凭据,然后被redirect到他以前试图访问的网站。 这是我的login信息 app.post('/login', function (req, res, next) { passport.authenticate('local', function (err, user, info) { if (err) { return next(err) } else if (!user) { console.log('message: ' + info.message); return res.redirect('/login') } else { req.logIn(user, function (err) { if (err) { return next(err); } return next(); // <-? Is this line […]