Tag: passport local

PassportJS重命名“用户”对象

我使用PassportJS作为我的loginfunction有没有办法改变请求中的“用户”对象名称? 这是现在它是如何工作的,默认情况下(req.user): function (req, res, next) { if (!req.user) { req.flash('error', 'Please sign in to access this page.'); res.redirect('/login'); } else { next(); } } 我想使用下面的代替(req.candidate): function (req, res, next) { if (!req.candidate) { req.flash('error', 'Please sign in to access this page.'); res.redirect('/login'); } else { next(); } }

快递/护照 – passport.authenticate不是一个function

我是passport.js的新手。 我一直在关注以下博客注册用户 https://scotch.io/tutorials/easy-node-authentication-setup-and-local 但每次我运行服务器,我加载/register页面显示上述错误 TypeError:passport.authenticate不是module.exports(/home/punit/Documents/****/routes/index.js:10:34)在Layer.handle [作为handle_request](/ home / punit /文件/ **** / node_modules / express / lib / router / layer.js:95:5)在trim_prefix(/home/punit/Documents/****/node_modules/express/lib/router/index.js: 312:13)at /home/punit/Documents/****/node_modules/express/lib/router/index.js:280:7 at Function.process_params(/ home / punit / Documents / **** / node_modules /express/lib/router/index.js:330:12)(/home/punit/Documents/****/node_modules/express/lib/router/index.js:271:10)在/ home /在Layer.handle [作为handle_request](/ home / punit / Documents / **** / node_modules / express / lib)处理文件/文件/ **** / node_modules / […]

节点JS +护照login

我试图configuration我的第一个节点的js应用程序使用护照login。 所以首先是第一件事。 我创build一个/app/config/express.js文件来configuration快速的东西。 所以我的app.js更简单: var app = require('./app/config/express')(); app.listen(3001, function(){ console.log("Servidor rodando"); }); 好,这很酷。 但! 我的express.js文件太大了。 也许你可以给我一些如何重构这个技巧? 我添加了一些问题的意见,我想让这个代码更好。 var express = require('express'); var load = require('express-load'); var expressValidator = require('express-validator'); var bodyParser = require('body-parser'); var passport = require('passport'); var Strategy = require('passport-local').Strategy; var session = require('express-session'); var flash = require("connect-flash"); module.exports = function() { // […]

isAuthenticated()函数不工作node.js护照

我正在创build在线课程应用程序,我只想要authentication的用户查看课程的详细信息和课程讲座。 我正在使用本地的护照authentication策略进行用户authentication。 我在我的路由中添加了isAuthenticated,但是,未经validation的用户仍然可以查看video讲座。 这是我的路线文件。 文件名: – courses.server.routes.js 'use strict'; /** * Module dependencies */ var coursesPolicy = require('../policies/courses.server.policy'), courses = require('../controllers/courses.server.controller'); var passport = require('passport'); var isAuthenticated = function(req, res, next) { // if user is authenticated in the session, call the next() to call the next request handler // Passport adds this method to […]

Passport在Node.js中使用express的本地策略会话

我是Node.js中的新手,并使用passport-local策略进行login会话。 我已经在我的networking应用程序中设置了所有的东西,但是会话中遇到了很大的问题。 我尝试了多个用户可以同时login到我的networking应用程序,但有一个问题。 用户之一(例如用户名是Paul)首先login,然后另一个用户(Chris)login,然后Paul的我的web应用程序的视图更改为Chris的视图。 我不知道你们明白我的意思,但这是我在Node.js中的一个代码 app.get('/location', isLoggedIn, function(req, res){ var user_temp = {user: ''}; user_temp.user = global_username; res.render('location/index1', user_temp); }); 下面的代码是Passport local-Strategy var LocalStrategy = require('passport-local').Strategy; passport.use('local-login', new LocalStrategy({ usernameField : 'email', passwordField : 'password', passReqToCallback : true }, function(req, email, password, done) { User.findOne({ 'email' : email }, function(err, user) { if (err) return […]

Node.js module.exports护照已authentication到路由

我想分开文件中的每一组路线。 我需要在大多数路由中使用isAuthenticated来限制访问。 当我把所有的路线放在同一个文件中, 当我在auth.js和order.js中使用module.exports = isAuthenticated ,我使用var auth = require('auth.js'); 当我进入http:// localhost:3000 /命令时,我会得到'isAuthenticated is not defined'的错误,在auth.js中定义的路由只是按预期工作。 我正在使用Express.js中间件“护照本地策略”(接下来来自tutsplus的教程和从这里下载的github库)。 我的项目结构: bin/www models/auth/init.js models/auth/user.js models/auth/signup.js models/auth/login.js models/order.js views/error.pug views/index.pug views/home.pug views/layout.pug views/order.pug views/register.pug routes/order.js routes/auth.js public/stylesheets/style.css app.js db.js ./routes/auth.js: var express = require('express'); var router = express.Router(); var isAuthenticated = function (req, res, next) { // if user […]

护照 – 本地 – mongoosechangePasswordfunction

我想要有用户可以更改密码的function。 我已经实现了这样一个路由( '/ resetPasswd' ): UserRouter.route('/resetPasswd') .post(function (req, res, next) { passport.authenticate('local', function (err, user, info) { user.changePassword(req.body.oldPassword, req.body.newPassword, function (err, user) { if (err) next(err); res.json('password changes successfully !'); }) })(req, res, next); }); 这是我发送的身体: { "oldpassword": "secret", "newPassword": "new" } 但是我得到这个错误作为回应: { "message": "user.changePassword is not a function", "error": {} } 这是我的模式的图片: 用户架构: […]

如何使用Passport.js获取当前会话的用户名?

如何在路由users.js使用Passport的{user}参数,我可以通过routes.js访问这些routes.js ? 这种情况是我需要在多个新的路由文件中访问Passport参数,所以我不需要使用routes.js作为包含所有应用程序路由的唯一文件。 app.js – 我只隔离感兴趣的部分 const express = require('express') const session = require('express-session') const cookieParser = require('cookie-parser') const bodyParser = require('body-parser') const passport = require('passport') const flash = require('connect-flash') const app = express() app.use(session({ secret: 'stackoverflow', resave: true, saveUninitialized: true, })) app.use(passport.initialize()) app.use(passport.session()) app.use(flash()) const index = require('./routes/index') const users = require('./routes/users') require('./config/passport')(passport) // […]

Passport-saml实现

我试图让任何战略的护照工作,但最终我想得到它与SAML实施工作。 现在看来,只要策略被调用,它总是失败。 我想知道如果也许我的服务器处理链设置错了? ` 'use strict'; // ———————————- BEGIN MODULE SCOPE VARIABLES ———————————- var http = require('http'), express = require('express'), session = require('express-session'), path = require("path"), samlStrategy = require('passport-saml').Strategy, passport = require('passport'), //flash = require('connect-flash'), morgan = require('morgan'), app = express(), server = http.createServer(app); // ———————————- END MODULE SCOPE VARIABLES ———————————— // ———————————- BEGIN SERVER […]

当Cookie被禁用时,护照会话pipe理

我正在制作一个Web应用程序,将AgularJS作为我的前端,Sails(NodeJS + Express)作为我的后端。 我正在使用护照(护照本地)进行身份validation,这似乎工作很好,直到我在safari中进行testing。 我注意到会话总是会返回null。 我使用护照会话授权,我无法使用req.session.passport获取会话variables,因为它是空的。 我发现我在Safari中禁用了Cookie。 这会破坏我的应用程序的授权。 有没有一种方法可以使会议pipe理,即使在浏览器中禁用cookie,也能正常工作?