Tag: passport.js

如何区分经过身份validation的用户在客户端与Passport和node.js?

我使用Passport.js与MongoStore进行身份validation,我使用express作为Web框架。 一旦用户login,他就可以访问某个路线上的内容。 我想提供不同的内容,取决于哪个用户已authentication 。 比方说,在Mongo的members集合中,每个members都拥有一个category或privileges属性,然后我将决定向他展示什么。 我将使用AngularJS来绑定和呈现HTML。 这是我的路线pipe理: app.get('/',function (request, response) { if(request.isAuthenticated()) response.redirect('/admin') else response.sendfile("public/index.html") }) app.get('/admin',function (request, response) { if(request.isAuthenticated()) response.sendfile("views/admin.html") else response.redirect('/') }) app.post('/login', passport.authenticate('local', { successRedirect: '/admin', failureRedirect: '/' }) ) app.get('/logout', function (request, response){ request.session.destroy(function (err) { response.redirect('/'); //Inside a callback… bulletproof! }) }) app.get('*',function (request, response) { response.redirect('/') }) 这是我的Passport.js代码: […]

Expressredirect和本地人

我正在使用passportjs为了login用户,我尝试在用angularjs完成密码validation之后redirect它们。 但是,当我尝试在另一页上获取用户数据时,我总是收到“无法读取未定义的属性名”片段: app.post('/login', function(req, res, next) { passport.authenticate('local', function(err, usr, info) { res.locals.user = req.usr; res.json({msg:true}); return next(); })(req, res, next); }); 而在别的地方,我试图做这样的事情: user.find({name: req.user.name },function(err,q){ 哪个启动错误“无法读取未定义的属性'名称'

Google OAuth2.0需要“个人资料”范围吗?

我目前正在尝试允许我的应用程序的用户授权我的应用程序访问他们的Doubleclick for Advertisers API。 我使用Passport.js来处理这个授权。 当我包含这样的configuration文件作用域和DFA作用域时: app.get '/requestAccess', passport.authenticate 'dfa', scope: [ 'https://www.googleapis.com/auth/dfatrafficking', 'profile' ] 这工作正常。 不过,我只关心DFA api,而实际上我并不打算使用configuration文件范围中的任何内容,所以我想删除它: app.get '/requestAccess', passport.authenticate 'dfa', scope: [ 'https://www.googleapis.com/auth/dfatrafficking', ] 当我现在批准使用这条路线时,我得到: "error": { "errors": [ { "domain": "global", "reason": "insufficientPermissions", "message": "Insufficient Permission" } ], "code": 403, "message": "Insufficient Permission" } } 这来自Google,这意味着我要求的范围是不够的。 是否需要configuration文件范围才能进行任何其他访问? 为什么我不能只请求DFA范围?

了解Passport.js – 篡改serializedUser

我试图绕过passport.js ,并确定我没有正确使用它。 特别是使用serializeUser()和deserializeUser()函数。 我的function看起来类似于下面的两个。 我本质上推动我的数据库user._id进入会议(我不喜欢做),并可以在浏览器中用cookie查看器轻松查看它。 passport.serializeUser(function(user, done) { done(null, user._id); }); passport.deserializeUser(function(id, done) { done(null, id); }); 因此,对于每一个安全的请求,我运行一个isAuthenticated()函数来检查用户是否使用Passport进行身份validation,然后使用req.user的反序列化ID来对数据库执行各种CRUD操作。 我想知道的是什么会阻止已authentication的用户将其自己的user._idreplace为会话中的其他用户的user._id,并获得所有这些不同用户的CRUD数据库操作的访问权限。 护照是否有某种哈希algorithm来检查序列化数据是否被篡改? 我不应该使用我的数据库CRUD操作返回的ID? 有没有其他的方法来避免将user._id发送到浏览器?

Passport.js和Facebook Graph API

我有一些与Passport.js和FacebookgraphicsAPI 2.0的问题。 我不能得到我自己的朋友列表(返回空数组,但工作正常,如果我请求自己的饲料),如果使用从Passport获得的访问令牌,但它工作正常,如果我复制我从Facebook图探险家。 任何人都有遇到这个问题? 我需要你的帮助。 所以,这里是我的一些代码: 路线和范围: app.get('/auth/facebook', passport.authenticate('facebook', { scope: ['user_friends', 'user_status', 'read_stream'] })); 对facebookgraphicsAPI的请求(使用Node.js标准模块): var fbReq = https.request({ hostname: 'graph.facebook.com', method: 'GET', path: '/v2.0/me/friends?access_token=' + accessToken }, function(fbRes) { var output = ''; fbRes.setEncoding('utf8'); console.log("log the data"); fbRes.on('data', function(chunk) { console.log(chunk.length); output += chunk; }); fbRes.on('end', function() { return res.render('home/postLogin', { data: output […]

ldapjs(使用node-express)client.search很慢

我使用node.js expressjs ldapjs来实现身份validation。 我有一个要求如下: validation用户 查找用户所属的所有组名称 通过configuration的深度级别(最多3次)查找用户组所属的父组名称; 这意味着find用户 – >find用户的组(#)—>find组的父母组多达三个级别。 为了在node-express环境中实现上述function,我使用了passportjs的ldapjs(编写一个自定义的策略来适应我们的需求)。 我的观察是,throgh ldapClient所做的每个search请求大约需要70ms,这对于完成我所需要的所有search请求(在身份validation过程中需要执行多达60-80个search请求)非常缓慢。 我上面实现了串行请求(我现在做完当前的下一个请求)。 在这种情况下,我该如何提高性能呢? 我可以查看哪些可用的选项?

错误:未能在会话中为passport-twitterfind请求令牌

以下是我使用passport-twitter时得到的错误 – Error: Failed to find request token in session at Strategy.OAuthStrategy.authenticate (/MYPROJECT/node_modules/passport-twitter/node_modules/passport-oauth1/lib/strategy.js:142:54) at Strategy.authenticate (/MYPROJECT/node_modules/passport-twitter/lib/strategy.js:85:40) at attempt (/MYPROJECT/node_modules/passport/lib/middleware/authenticate.js:337:16) at Object.authenticate [as handle] (/MYPROJECT/node_modules/passport/lib/middleware/authenticate.js:338:7) at next_layer (/MYPROJECT/node_modules/express/lib/router/route.js:103:13) at Route.dispatch (/MYPROJECT/node_modules/express/lib/router/route.js:107:5) at /MYPROJECT/node_modules/express/lib/router/index.js:205:24 at Function.proto.process_params (/MYPROJECT/node_modules/express/lib/router/index.js:269:12) at next (/MYPROJECT/node_modules/express/lib/router/index.js:199:19) at next (/MYPROJECT/node_modules/express/lib/router/index.js:176:38) 以下是我执行的苏格兰Twitter注册教程, FB signup工作正常。 供参考 – 我在twitter上多次检查过configuration,对我来说一切都好(callbackURL,key,secret等) 我检查了下面的url,但没有运气。 我的开发url就像 – http://192.XXX.XXX.XX:PORT_NUMBER 以下是我的app.js app.js 以下是我的passport.js passport.js […]

护照本地types错误

我正在尝试在我的Sails项目中使用passport-local进行身份validation。 在我的控制器中: passport.authenticate('local', function(err, user, info) { if ((err) || (!user)) { res.json({message: 'Unable to authenticate'}); return; } req.login(user, function(err) { if (err) { res.json({message: 'Unable to login'}); console.log(err); return; } res.json({message: 'logging in'}); }); })(req, res); 在configuration文件中: passport.use(new LocalStrategy(function(username, password, done) { User.findOneByUsername(username).done(function(err, user) { if (err) { return done(null, err); } if (!user) […]

如何将令牌从中间件传递到路由

这是我的Passport中间件。 我正在自动Instagram的,你可以看到: // Use the InstagramStrategy within Passport. // Strategies in Passport require a `verify` function, which accept // credentials (in this case, an accessToken, refreshToken, and Instagram // profile), and invoke a callback with a user object. passport.use(new InstagramStrategy({ clientID: INSTAGRAM_CLIENT_ID, clientSecret: INSTAGRAM_CLIENT_SECRET, callbackURL: INSTAGRAM_CALLBACK_URL }, function(accessToken, refreshToken, profile, done) { // asynchronous verification, […]

函数中的这些节点jsvariables是什么?

我正在用NodeJS,Express和PassportJS创build一个API,但我认为这是一个JavaScript问题。 app.get('/test', function (req, res, next) { passport.authenticate('bearer', { session: false }, function (err, user, info) { if (user === false) { res.send('ko'); } else { res.send('ok'); } })(req, res, next); }); 我的问题是: 为什么在validationfunction之后(req, res, next) ? 它与范围有关吗?