Tag: passport.js

login后,在离子应用程序中保持用户会话的身份validation

我有一个Web应用程序,后端的所有获取和发布请求都是用nodejs编写的,用户login护照后会存储会话,每当用户发出请求时,我都可以检查用户是否login或不使用req.isAuthenticated() , 现在我正在开发Android平台的应用程序,以及使用ionic framework, 我面对的问题是用户login成功后,并尝试访问他的个人资料页面,其中isLoggedIn()检查完成,因为会话不保存,再次导致我重新回到login页面。 我的问题是我怎样才能保存在我的离子应用程序在cookie中的会话,以便我可以访问我的API,我知道我可以使用passport-jwt但那么我将不得不改变所有的login策略,是否有任何其他方式通过发送jwt令牌,我可以在我的isLoggein()函数中检查它。 我应该在后端保存我login的用户会话中进行哪些更改。

使用LDAP的Node.js身份validation机制

我希望实现一个login机制到我的应用程序,因为用户正在坐在LDAP服务器,而不是在本地数据库。 我一直在考虑实施passport.js,但我想弄清楚解决scheme的其他部分 – 我可以selectpassport-ldap ,或者我可以尝试…以“本地”策略实施解决scheme: 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); } if (!user.verifyPassword(password)) { return done(null, false); } return done(null, user); }); } )); 作为function(user, password, done)可能被植入ldapjs 。 我不确定哪个选项会更好。 我认为第二个可能会给我更多的login过程控制,但使用LDAP策略可能会更有意义。 有什么build议么?

jsonnetworking令牌,passport-jwt及其validationfunction

我最近在做jsonnetworking令牌的研究。 从我所收集的资料来看,它的一大优势就是它的无国籍。 一切你需要authentication的用户来与请求,因此你不需要“击中每个请求的数据库”,许多文章说。 但是,如果我没有弄错,那么passport-jwt的文档就是这么做的,他们在每个请求中都打了数据库。 也就是说,对于每个需要通行证authentication的请求。 passport.use(new JwtStrategy(opts, function(jwt_payload, done) { //this is a database call User.findOne({id: jwt_payload.sub}, function(err, user) { if (err) { return done(err, false); } if (user) { done(null, user); } else { done(null, false); // or you could create a new account } }); })); 我的印象是,当这个函数被调用的时候, 令牌已经被validation ,否则这个函数将不会被调用,并且用户被401 unauthorized为401 unauthorized 。 那为什么要检查用户的数据库? […]

Angular JWT Profile用户(获得JSON领域)

我有一个gettProfile()方法,其中包括以下代码: gettProfile(){ var headers = new Headers(); this.loadToken(); headers.append('Authorization', this.authToken); headers.append('Content-Type','application/json'); let options = new RequestOptions({headers: headers}); return this.http.get('http://localhost:3000/api/profile', options) .map(res => res.json()); //res.json() localStorage.getItem('students') } 在这段代码中,当我写console.log(this.authToken); 它显示正确的JWT令牌。 但是,当我将这些数据传递给我的ProfileComponent它说: 错误TypeError:无法读取未定义的属性“名称” Profile.component.ts代码如下: export class ProfileComponent implements OnInit { students: Object; constructor(private authService:AuthService, private router:Router) { } ngOnInit() { this.authService.gettProfile().subscribe(profile => { this.students= profile.students; }, err => […]

使用Angularfire,Passport和Express / Nodejspipe理会话

我有一个NodeJS / AngularJS应用程序,我想使用angularfire来pipe理我的用户在客户端的login/注册。 例如 $firebaseAuth.$signInWithEmailAndPassword(email, password).then(function(auth) { // communicate with backend server and redirect to secure site using auth obj }, function(error) {}); 在客户端成功login后,我想将auth对象发布到后端服务器,以使用Firebasevalidation用户。 然后在我的NodeJS / Express应用程序中创build一个会话,然后将用户redirect到一个安全页面。 以前我使用passport从电子邮件和密码创build会话,但我不知道如何适应passport使用angularfire检索的auth对象。 尽pipeFirebase有一个护照模块 ,但没有工作示例代码。 任何人都可以提供有关如何使用Firebasevalidation用户的工作代码或说明,并在我的NodeJS \ Express应用程序中build立安全会话,最好使用护照?

Mongoose bcryptjs比较密码不参考文件(这个)

我有像这样的mongoose模式 var mongoose = require ('mongoose'); var bcrypt = require('bcryptjs'); var Schema = mongoose.Schema; var SALT_WORK_FACTOR = 10; var touristSchema = new Schema ({ local: { email: String, password: String }, facebook: { id: String, token: String, email: String, name: String, } }); touristSchema.pre('save', function(next) { var user = this; console.log('bcrypt called by strategy', user); […]

Passport JS无法检索用户

以下是我在护照​​JS的注册策略。 大部分的代码运行正常,直到在res.send用户参数的底部,在passport.authenticate方法成功validation策略之后发送用户参数。 然而,无论何时我发回回应,我都会收到一个带有“假”消息的页面。 而不是发送给我的用户的详细信息,我发送“虚假”,而不是。 app.use(passport.initialize()); app.use(passport.session()); passport.serializeUser(function(user, done) { return done(null, user.id); }); passport.deserializeUser(function(id, done) { User.findById(id, function(err, user) { done(err, user); }); }); passport.use("registerUser", new LocalStrategy({ passReqToCallback: true }, function(req, username, password, done) { var newUser = new User({ name: username, email: req.body.email, password: password }); newUser.save(function(err) { if (err) { return done(err); } […]

access_token不存在于passport-github2请求中

我已经通过我的Github帐户注册了一个OAuth应用程序。 我基本上试图授权我的node请求(通过发送access_token作为请求cookie的一部分),所以我可以访问另一台服务器上的几个API。 因此我使用github-passport2软件包。 我已经设置了Github策略等等,似乎都是根据文档。 stream程也运作良好。 我的问题 login到Github(授权)并redirect回到我的/auth/github/callback , 理想情况下应该被授权,并且在req应该有一个access_token 。 但我没有! 因此,我无法使用access_token来授权我未来的请求。 需要注意的是,当从浏览器/客户端(使用withCredentials: true参数)发起请求时,此access_token自动附加。 通过节点相同的access_token似乎不可检索。 passport.use(new GitHubStrategy({ clientID: GITHUB_CLIENT_ID, clientSecret: GITHUB_CLIENT_SECRET, callbackURL: "http://localhost:8080/auth/github/callback", }, function(accessToken, refreshToken, profile, done) { // asynchronous verification, for effect… process.nextTick(function () { return done(null, profile); }); } )); app.get('/auth/github', passport.authenticate('github', { scope: [ 'user:email' ] }), function(req, res){ // The […]

节点js重置用户的密码

早上好,我正在实现一个NodeJs函数来重置一个特定用户的密码。 我将所有用户保存在一个名为Account的本地MongoDb集合中,并使用以下模式: var Account = new Schema({ username: { type: String, trim: true, unique: true, index: true, lowercase: true, "default": "", validate: [validateLocalStrategyProperty, "Please fill in your email"], match: [/.+\@.+\..+/, "Please fill a valid email address"] }, password: { type: String, "default": "", validate: [validateLocalStrategyPassword, "Password should be longer"] }, role: { type: [ { […]

如何在nodejs-Express-passport应用程序中将令牌从服务器传递到客户端

我正在使用Nodejs + Express + passport.js。 我已经完成了authentication,并有令牌服务器端。 现在我想调用客户端JavaScript文件(填充HTML页面上的列表)的一些API,并希望在那里使用该标记。 什么最好的办法做到这一点? 我是否应该将令牌存储在用户对象中,并将其沿着路由传递,以便它可以在jade / ejs文件中使用并从那里使用它?