passport.js

Serialize / deserialize with multiple LocalStrategy PassportJs / ExpressJs

99封情书 提交于 2019-12-11 03:10:02
问题 I am starting with PassportJs/ExpressJs application for authentication i have two different model for User and Admin Here is passport.js code passport.use('admin', new LocalStrategy({ usernameField: 'email', passwordField: 'password' }, function(email, password, done) { var adminflag = 'admin'; console.log('---------------------in admin') db.adminUser.find({ where: { email: email }}).success(function(user) { if (!user) { done(null, false, { message: 'Unknown user' }); } else if (!user

Getting “error”: “Unknown authentication strategy \”jwt\“”

瘦欲@ 提交于 2019-12-11 02:27:06
问题 I'm implementing an authorization feature using Express, Mongoose, Passport and JWT. I'm able to register a user ok. I'm able to authenticate and generate a JWT, which I can parse on the JWT site, but for some reason, I'm getting an Unknown authentication strategy error message. I have all my code blocks laid out on a Plunker instance at: https://plnkr.co/edit/ZNjQwcZ4rMymzBXNy5nX?p=catalogue Here is my passport.js file, which contains my strategy: var JwtStrategy = require('passport-jwt')

passport.js not working with manual form-data post request angular

柔情痞子 提交于 2019-12-11 02:16:27
问题 I have created a form in angular, On click of submit button I am hitting a post request with Content-Type header with value application/x-www-form-urlencoded . onSubmit(user:User) { let headers = new Headers(); // to send data as form data as passport library want it as a form data headers.append('Content-Type', 'application/x-www-form-urlencoded'); return this.http.post('/login', user, { headers: headers }).subscribe((data) => { console.log("Data : ", data); }); } and the model user is of

PassportJs Authentication Infinite Loop and Execute(default) query

寵の児 提交于 2019-12-11 01:43:17
问题 I am trying to build the authentication system using PassportJs and Sequelize. I made the registration system by myself, using Sequelize. I want to use PassportJS only for Login. It does not redirect me to the failureRedirect route, neither to the SuccessRedirect one, but when submitting the form it enters into an endless loop and in my console, the following message appears: Executing (default): SELECT `id`, `username`, `lastName`, `password`, `email`, `phone`, `createdAt`, `updatedAt` FROM

Send data back with the Passport js failureRedirect method

你。 提交于 2019-12-11 01:35:09
问题 I have a Passport js local signup strategy that makes use of the successRedirect and failureRedirect methods. The problem is, if there is an error with the signup process, Passport will simply redirect back to the signup form, with no data in the form. app.post('/signup', passport.authenticate('local-signup', { successRedirect: '/signup/avatar', // redirect to the secure profile section failureRedirect: '/signup', // redirect back to the signup page if there is an error failureFlash: true //

How to diagnose passport.authenticate?

匆匆过客 提交于 2019-12-11 00:27:48
问题 Since the function has no return value - how can I identify what's causing the function to fail. I have the following code: function test(req : IncomingMessage, res :ServerResponse, next:(err:any)=>void) { passport.authenticate('google', {scope:['https://www.googleapis.com/auth/userinfo.email']})(req, res,next); //how do I get details here } I mean I know it's failing since the next handler in line is not called but how do I get more detailed information? This function is instanced like

Testing authenticated routes with JWT fails using Mocha + supertest + passport

白昼怎懂夜的黑 提交于 2019-12-11 00:24:56
问题 I'm trying to test authenticated routes in Mocha but the user created in before or beforeEach hooks does not persist. In test.js const should = require('chai').should(), mongoose = require('mongoose'), request = require('supertest'), app = require('../../../../server'), agent = request.agent(app), AdminUser = require('../../../models/AdminUser'); var credentials = { username: 'admin', password: 'password' }; var admin = new AdminUser(credentials); describe('authenticated routes', function() {

mongodb and authenticate and passport in node.js

纵饮孤独 提交于 2019-12-10 21:32:34
问题 i have a collection like this in mongodb { username:silver, Email:sil@gmail.com, password:silvester, } so to authenticate i will fetch data from database and then i will check given email is exist or not with if statement like this app.post("/login",function(req,res){ var email=req.body['emailid']; collection.find({email:sil@gmail.com}).toArray(function(err,res) { if(res.length==0){ console.log("name is not exist"); }else{ if(res.email==email){ console.log("email is exist"); }else{ console

NodeJS express-validator with passport

若如初见. 提交于 2019-12-10 20:54:08
问题 I write a signup form table, and I use passport-local is work, but I want add express-validator to validate my form data. I add validation on the router, this is my router/index.js code: /* Handle Registration POST */ router.post('/signup', function(req, res) { req.assert('email', 'A valid email is required').isEmail(); var errors = req.validationErrors(); if(errors){ //No errors were found. Passed Validation! res.render('register', { message: 'Mail type fault', errors: errors }); } else {

node.js passport session cookie domain

↘锁芯ラ 提交于 2019-12-10 19:57:21
问题 I'm using node.js + passport and trying to figure out how the set the cookie on the parent domain so that it's available to sub domains. User logs into Domain.com User then goes to Sub.Domain.com ... he should still be logged in. how does one set the cookie on the parent domain? Here's what I currently have. app.use(express.session({ secret: 'XXXXX', store: new mongoStore({ url: app.get('mongodb-uri') }) })); app.use(passport.initialize()); app.use(passport.session()); 回答1: What you need to