Tag: passport.js

OAuth范围在同一应用程序中的不同stream量?

上下文 我有一个Node.js应用程序,它具有一套“复杂”的OAuthstream程,以使UX更简单。 我有通常的login和注册stream程,您可以使用OAuth提供程序进行身份validation。 这里我不需要任何特殊的scope ,因为OAuth纯粹用于身份validation,用户没有理由要给我提升权限(比如私人的GitHub仓库),甚至可能认为这是一个可疑的事情,所以他离开了,再也不会访问我的产品。 所以,没有纯粹的authenticationstream程的scope 。 该应用程序还具有导入function,您可以从OAuth提供程序(例如GitHub存储库)导入实体列表。 默认情况下,你不会在这里要求任何scope 。 点击“寻找你的私人存储库?” button再次validation你对GitHub,要求repo范围。 这一切都很好。 问题 当用户尝试再次login或以其他方式进行身份validation但不明确请求repo作用域时,GitHub认为这是明确的降级请求。 问题是用户在login过程中不会因为没有特殊原因而降级 。 同样, 我不想在login时要求比我需要更多的权限 。 离开这个状态的东西比在login时要求repo更糟糕,但这也是一个非常糟糕的select。 潜在的解决scheme 除了两个非解决scheme,我提出的潜在解决scheme是: 根据请求的scope明确地询问GitHub的唯一访问令牌 ,分别存储令牌,然后根据需要使用它们 那真是太好了,除非它是有状态的,我还没有find办法去做; 他们似乎给每个应用程序用户一个单一的令牌,我怀疑OAuth是如何工作的,但我几乎不是这方面的专家。 如果GitHub拥有比所要求的更多的特权,请明确告知GitHub 不要降级它。 这听起来应该是默认的行为。 无论如何, 有什么办法可以告诉GitHub不要降级令牌吗? 如果没有,有没有其他办法可以解决这个问题,而不是在整个应用程序中要求相同的范围? 这首先会部分地破坏示波器的目的。 另外,这是一个GitHub的具体问题? 我是否需要按提供者的方式处理这个问题? 有没有协议级别的解决scheme奇迹般地让问题消失? 还是OAuth只是不考虑用户体验? FWIW我正在使用iojs和passportjs ,但我认为这与问题没有任何关系。

使用google-passport-oauthlogin后,req.user未定义

在使用Google帐户成功login后,在callback请求中,将req.user设置为正确的用户,并且req.isAuthenticated()为true。 大! 但是,任何后续请求都会将req.user定义为undefined。 不pipe我做什么。 这个问题同时出现在passport-google-auth2和passport-google-auth中 。 这是我的index.js样子: app.set('views', './src/express/views'); app.set('view engine', 'jsx'); app.engine('jsx', expressReactViews.createEngine({ beautify: true })); app.use(express.static('./dist')); app.use(cookieParser()); app.use(bodyParser.json()); app.use( bodyParser.urlencoded({ extended: true })); app.use(session({ secret: 'keyboard cat', proxy: true, resave: true, saveUninitialized: true, cookie: { secure: true } })); app.use(passport.initialize()); app.use(passport.session()); passport.serializeUser(function(user, done) { // user is passed here correctly done(null, user.id); }); […]

如何踢用户会话?

我的系统使用passport.js进行身份validation。 用户可以根据本地策略进行login和注销。 我正在研究一个允许超级用户从我的系统踢用户的function。 我目前的做法是: 将用户configuration文件设置为禁用 删除用户会话 用户无法再次login,因为用户configuration文件被禁用(使用本地策略) 我怎样才能删除MongoStore中的用户会话? "express": "~4.13.1", "express-session": "~1.11.3", "mongoose": "~4.0.7", "passport": "~0.2.2", "passport-local": "~1.0.0",

我应该如何validation错误与续集和护照login

我已经设置在用户模型中validation。 我的路线代码是这样的,我想要validation。 var express = require('express'); var loginRouter = express.Router(); var passport = require('passport'); var User = require('../app/models/model')().User; module.exports = function() { var loginController = require('../controller/loginController')(); loginRouter.get('/login',loginController.getLogin); loginRouter.post('/login', function (req, res, next) { User.validate().success(function () { next(); // only call next if validation passes }).error(function (error) { console.log(error); res.redirect('/auth/login'); // or res.send({error: true}) or res.redner( […]

通过LinkedInloginauthentication用户的护照

我在护照上build立了一个login系统,工作得很好。 现在,我想在我的系统中集成LinkedInlogin。 我已经有clientID , clientSecret等需要login。 这是按下LinkedInloginbutton时调用的代码。 passport.use('linkedin', new OAuth2Strategy({ authorizationURL: 'https://www.linkedin.com/uas/oauth2/authorization', tokenURL: 'https://www.linkedin.com/uas/oauth2/accessToken', clientID: clientid, clientSecret: clientsecret, callbackURL: '/linkedinLogin/linkedinCallbackUrlLogin', passReqToCallback: true }, function(req,accessToken, refreshToken, profile, done) { console.log('authenticated'); console.log(accessToken); req.session.code = accessToken; process.nextTick(function () { done(null, { code : req.code }); }); })); callback函数中的console.log()调用都已成功触发,这意味着我已成功通过LinkedInlogin,并且收到我的访问令牌。 我连接LinkedIn的部分是正确的,我缺less的是我实际login用户的部分。 正如你所看到的, callbackURL指向/linkedinLogin/linkedinCallbackUrlLogin 。 这就是我在这条路上所做的: app.get('/linkedinLogin/linkedinCallbackUrlLogin', passport.authenticate('linkedin', { session: false, successRedirect:'/linkedinLogin/success', […]

无法在nodeJS中validation用户:TypeError:无法使用“in”运算符在fs中search“用户名”

我有一个简单的表单来注册/validation用户。 我能够成功注册一个用户,但无法进行身份validation。 我试图研究这个问题,但我还没有find任何可以帮助的东西。 这里是htmllogin表单: <form method="post" action="/login"> <input type="text" name="username" placeholder="username"> <input type="password" name="password" placeholder="password"> <input type="submit" name="submit" value="submit"> </form> 当用户按下submitbutton时,我的控制台上显示如下: TypeError: Cannot use 'in' operator to search for 'username' in fs at model.Document.$__buildDoc (/Users/userA/Desktop/loginapp/node_modules/mongoose/lib/document.js:207:39) at model.Document (/Users/userA/Desktop/loginapp/node_modules/mongoose/lib/document.js:61:20) at model.Model (/Users/userA/Desktop/loginapp/node_modules/mongoose/lib/model.js:45:12) at new model (/Users/userA/Desktop/loginapp/node_modules/mongoose/lib/model.js:2957:11) at Strategy.model [as _verify] (/Users/userA/Desktop/loginapp/node_modules/mongoose/lib/model.js:2956:14) at Strategy.authenticate (/Users/userA/Desktop/loginapp/node_modules/passport-local/lib/strategy.js:90:12) at attempt […]

在Node request.headers中设置授权

我试图发送一个Passport-Locallogin请求到客户端,由Satellizer进行分析,我希望从服务器端发送一个授权令牌。 不幸的是,在request.headers没有密钥authorization : { host: 'localhost:3000', connection: 'keep-alive', 'cache-control': 'max-age=0', accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' } loginfunction在这里redirect,这是调用ensureAuthenticated()地方。 app.get('/main', ensureAuthenticated, function(req, res, next){ res.render('main.ejs', { token: createSendToken(req.user, config.secret), id: req.user._id, username: req.user.username, authorization: req.user.authorization }); }); ensureAuthenticated()然后分析login请求,并确保令牌匹配: function ensureAuthenticated(req, res, next) { if (!req.headers.authorization) { return res.status(401).send({ message: 'Please make sure your request has an Authorization header' }); } […]

无法访问req.user的属性

我在使用passport.js进行身份validation的Node中编写代码。 console.log(req.user); 回报 { group: 'CuManager', password: 'password', username: 'administrator', cu_id: 2, _id: 569fd3f4328ef124be533caf } 但 console.log(req.user.cu_id); 回报 undefined 我在想,cu_id属性可能是不可用的,由于序列化/反序列化,但它在那里。 我只是无法访问它。 我怎样才能做到这一点? 我需要它 find({cu_id : req.user.cu_id}) 顺便说一句,我不禁想着passport.js是一点点过于复杂(也许我们只是不相处)。 还有什么我可以用来validation用户在节点(我使用快递)?

如何将jwtauthentication与ACL混合

我已经能够使用JWT策略实施护照,并且运作良好。 我的jwt保护路线看起来像这样… app.get('/thingThatRequiresLogin/:id', passport.authenticate('jwt', { session: false }), thingThatRequiresLogin.findById); 现在我需要限制某些东西的访问权限,只有属于某个angular色的login用户。 我希望我可以这样expression: app.get('/thingThatRequiresLogin/:id', MAGIC, thingThatRequiresLogin.findById); 其中MAGIC = require logged-in users, but only those with role x or y node_acl似乎是一个很好的解决scheme,我理解了一点,但是我发现这在文档中… 我们可以保护这样的资源: app.put('/blogs/:id', acl.middleware(), function(req, res, next){…} 中间件将保护由req.url命名的资源,从req.session.userId中select用户,并检查req.method的权限,所以上面的代码就是这样的: 我如何将这与我的jwt策略混合? 我唯一的想法是放弃node_acl middleware ,而是添加acl检查代码到我的jwt策略。 但那是我遇到麻烦的地方。 我的jwtfunction如下所示: passport.use(new JwtStrategy(jwtOptions, function(jwt_payload, done) { User.findOne({id: jwt_payload.sub}, function(err, user) { if (err) { return […]

使用paypal的战略护照:未能获得访问令牌

护照(Jared Hanson) 我如何使用贝宝与openID或OAuth? 我正在使用Passport-paypal-oauth策略( https://github.com/jaredhanson/passport-paypal-oauth ), 注意:我的路线以localhost:4000 / api / users开头 HTTP://本地主机:4000 / API /用户/登入/贝宝 HTTP://本地主机:4000 / API /用户/登入/贝宝/callback 我的PayPal终点: var passport_paypal = require('../middlewares/passport-paypal'); router.get('/signin/paypal', passport_paypal.authenticate('paypal-signin', { scope: 'openid profile email'})); router.get('/signin/paypal/callback', function(req, res, next){ passport_paypal.authenticate('paypal-signin', function(err, user, info){ // Handle cases //return res.status(xxx).json('.. }); 我的Paypal策略: var PaypalStrategy = require('passport-paypal-oauth').Strategy; passport.use('paypal-signin', new PaypalStrategy({ clientID : […]