Questions tagged [passport.js]

Passport.js is authentication middleware for Node.js. Extremely flexible and modular, Passport can be unobtrusively dropped into any Express-based web application. A comprehensive set of strategies support authentication using a username and password, Facebook, Twitter and more.

Filter by
Sorted by
Tagged with
485 votes
7 answers
198k views

Understanding passport serialize deserialize

How would you explain the workflow of Passport's serialize and deserialize methods to a layman. Where does user.id go after passport.serializeUser has been called? We are calling passport....
Anubhav's user avatar
  • 7,188
219 votes
11 answers
133k views

Passport.js - Error: failed to serialize user into session

I got a problem with the Passport.js module and Express.js. This is my code and I just want to use a hardcoded login for the first try. I always get the message: I searched a lot and found some ...
user2244925's user avatar
  • 2,344
217 votes
6 answers
121k views

How to implement a secure REST API with node.js

I start planning a REST API with node.js ,express and mongodb. The API provides data for a website (public and private area) and maybe later a mobile app. The frontend will be developed with AngularJS....
tschiela's user avatar
  • 5,271
162 votes
4 answers
116k views

What does passport.session() middleware do?

I am building an authentication system using Passport.js using Easy Node Authentication: Setup and Local tutorial. I am confused about what passport.session() does. After playing around with the ...
Georges Krinker's user avatar
158 votes
3 answers
50k views

passport.js RESTful auth

How does one handle authentication (local and Facebook, for example) using passport.js, through a RESTful API instead of through a web interface? Specific concerns are handling the passing of data ...
ryanrhee's user avatar
  • 2,560
130 votes
17 answers
295k views

ERR_HTTP_HEADERS_SENT: Cannot set headers after they are sent to the client

I'm facing this weird issue in NodeJS when using with Passport.js, Express and Mongoose. Basically, I get an error saying "Cannot set headers after they are sent to the client" even though I don't ...
lourdesr's user avatar
  • 1,411
125 votes
7 answers
44k views

Everyauth vs Passport.js? [closed]

Everyauth and Passport.js seem to have very similar feature sets. What are some of the positive and negative comparisons between the two that would make me want to use one over the other?
EhevuTov's user avatar
  • 20.4k
117 votes
8 answers
92k views

passport.js passport.initialize() middleware not in use

I am using node with express + mongoose and trying to use passport.js with restful api. I keep getting this exception after authentication success (I see the callback url on the browser): /Users/...
Naor's user avatar
  • 23.7k
117 votes
7 answers
104k views

Redirecting to previous page after authentication in node.js using passport.js

I'm trying to establish a login mechanism using node.js, express and passport.js. The Login itself works quite nice, also sessions are stored nicely with redis but I do have some troubles with ...
Alx's user avatar
  • 6,285
115 votes
6 answers
100k views

How to know if user is logged in with passport.js?

I've been reading passport.js info and samples for two days, but I'm not sure after that I did all the process of authenticating. How do I know if I'm logged in, for example, I'll have a navigation ...
RMontes13's user avatar
  • 2,148
108 votes
2 answers
48k views

Using PassportJS, how does one pass additional form fields to the local authentication strategy?

I'm using passportJS and I'm wanting to supply more than just req.body.username and req.body.password to my authentication strategy (passport-local). I have 3 form fields: username, password, & ...
k00k's user avatar
  • 17.5k
92 votes
3 answers
39k views

passport-local with node-jwt-simple

How can I combine passport-local to return a JWT token on successful authentication? I want to use node-jwt-simple and looking at passport.js I am not sure how to go about. var passport = require('...
cgiacomi's user avatar
  • 4,659
90 votes
29 answers
122k views

Node + Express + Passport: req.user Undefined

My question is similar to this one, but there was no insight into his solution. I'm using Passport to auth using Instagram. After successful auth, users are directed to "/". At this point, the ...
gojohnnygo's user avatar
  • 1,148
83 votes
1 answer
89k views

How is req.isAuthenticated() in Passport JS implemented? [closed]

In passportJS Documentation, I think passport isAuthenticated function not documented well. How is req.isAuthenticated() in PassportJS implemented?
Kim's user avatar
  • 1,081
78 votes
30 answers
83k views

Why is PassportJS in Node not removing session on logout

I am having trouble getting my system to log out with PassportJS. It seems the logout route is being called, but its not removing the session. I want it to return 401, if the user is not logged in in ...
Jeffrey Chen's user avatar
  • 1,049
76 votes
6 answers
88k views

Express Passport (node.js) error handling

I've looked at how error handling should work in node via this question Error handling principles for Node.js + Express.js applications?, but I'm not sure what passport's doing when it fails ...
Omid Ahourai's user avatar
  • 1,409
76 votes
8 answers
44k views

How to authenticate Supertest requests with Passport?

I'm using Passport.js for authentication (local strategy) and testing with Mocha and Supertest. How can I create a session and make authenticated requests with Supertest?
Gal Ben-Haim's user avatar
  • 17.6k
76 votes
2 answers
22k views

Authentication with React Native and API backend

I'm trying to wrap my head around oauth with a React Native app and a separate NodeJS/Express API backend. I understand https://github.com/adamjmcgrath/react-native-simple-auth offers authentication ...
wwwuser's user avatar
  • 6,332
72 votes
3 answers
47k views

nodejs passport authentication token

I am writing a nodejs application that I would like to use as both a web application, as well as an API provider. Once a user is authenticated, I want to assign that user a token to be used for ...
Austin's user avatar
  • 1,129
69 votes
6 answers
61k views

Sending back a JSON response when failing Passport.js authentication

I'm using Node.js as a backend API server for an iPhone client. I'm using Passport.js to authenticate with a local strategy. The relevant code is below: // This is in user.js, my user model ...
kurisukun's user avatar
  • 3,149
66 votes
1 answer
46k views

passport.js with multiple authentication providers?

Using Passport.js is there a way for me to specify multiple authentication providers for the same route? For example (from passport's guide) can I use local and facebook and twitter strategies on the ...
cgiacomi's user avatar
  • 4,659
65 votes
1 answer
3k views

Express-mysql-session preventing passport deserializeUser from running

I have an app using passport.js to log in users through facebook, and am attempting to use express-mysql-session to persist their login states. If I don't include the express-mysql-session code, the ...
user2796352's user avatar
61 votes
20 answers
61k views

passport's req.isAuthenticated always returning false, even when I hardcode done(null, true)

I'm trying to get my Passport local strategy working. I've got this middleware set up: passport.use(new LocalStrategy(function(username, password, done) { //return done(null, user); if (...
CodyBugstein's user avatar
  • 22.7k
61 votes
2 answers
89k views

How to store a JWT token inside an HTTP only cookie?

I have created an app that simply uses a JWT sent by the server upon correct login credentials, and authorizes against any /api route on my backend Express.js server. AngularJS, on the other hand, ...
user avatar
60 votes
2 answers
121k views

JavaScript wait for asynchronous function in if statement [duplicate]

I have a function inside an if statement isLoggedin() has an async call. router.get('/', function(req, res, next) { if(req.isLoggedin()){ <- never returns true console.log('...
pfMusk's user avatar
  • 789
59 votes
3 answers
51k views

How to use passport with express and socket.io?

I am currently trying to set up a basic authentication system for my node.js app. For now I am using express (3.0.0rc5), passport (0.1.12) and socket.io (0.9.10) with Mongoose as Store for session ...
Patrick's user avatar
  • 1,245
57 votes
7 answers
31k views

Passport-Facebook authentication is not providing email for all Facebook accounts

I am using Passport-Facebook authentication. passport.use(new FacebookStrategy({ clientID: 'CLIENT_ID', clientSecret: 'CLIENT_SECRET', callbackURL: "http://www....
AMT's user avatar
  • 721
55 votes
16 answers
45k views

passport local strategy not getting called

I'm sure I'm missing something really obvious here, but I can't figure this out. The function I've passed to the LocalStrategy constructor doesn't get called when the login form gets submitted. Code: ...
Oliver Dain's user avatar
  • 9,785
54 votes
2 answers
16k views

What does passport.js do and why we need it?

I am not familiar with user authentication in Node.js, now I am trying to create a website with a login system. I have managed to make it work using the code snippets from the website, but I don't ...
Leonard Ge's user avatar
53 votes
2 answers
42k views

What is function User.findOrCreate doing and when is it called in passport?

I can't find documentation on this function and therefor I can't make it work right. When is that function being called, what is it doing and what is it taking as first parameters? I'm trying to get ...
Tommz's user avatar
  • 3,423
51 votes
5 answers
31k views

Use multiple local strategies in PassportJS

I'm trying to use multiple LOCAL strategies with PassportJS. I'm not trying to use local, facebook, and gmail, etc. I have two sets of users stored in separate objects and I want to use a local ...
Plattaz's user avatar
  • 525
51 votes
5 answers
42k views

Error: req#logout requires a callback function

can't able to find solution of this tried everything, i am just new in using passport. Error: req#logout requires a callback function i have coded this before but that time i have not received any ...
Harsh Gupta's user avatar
51 votes
13 answers
25k views

PassportJS deserializeUser never called

I've got Passport setup to authenticate users stored in mongodb. Seems to work fine: authentication succeeds/fails appropriately and session variables get set. However, getting Passport to check for a ...
Alex Westholm's user avatar
51 votes
4 answers
51k views

Passport login and persisting session

Background I have a MEAN application with CRUD capabilities fully tested with postman. I have been trying to persist login for quite some time now with no luck. I have read and tried the following ...
Joe Lloyd's user avatar
  • 21.1k
48 votes
3 answers
25k views

Get request object in Passport strategy callback

So here is my configuration for passport-facebook strategy: passport.use(new FacebookStrategy({ clientID: ".....", clientSecret: ".....", callbackURL: "http://localhost:...
Élodie Petit's user avatar
44 votes
2 answers
38k views

Documentation for "ensureAuthentication" "isAuthenticated" passport's functions?

I've been looking for a while, and can't see to find a definitive documentation source. When I search for these, the first Google results are to StackOverflow. Are there any more middleware functions ...
az_'s user avatar
  • 1,493
42 votes
3 answers
57k views

How do I store JWT and send them with every request using react

So happy right know because I got my basic registration/authentication system going on. so basically I got this : app.post('/login', function(req,res) { Users.findOne({ email: req.body.email }, ...
MaieonBrix's user avatar
  • 1,594
41 votes
2 answers
41k views

What is "done" callback function in Passport Strategy Configure "use" function

I'm an node.js and express.js noob. This question may seems silly but I'm really in confusion. I'm trying to configure Local Strategry authentication by using passport. As shown in the official ...
Steve.NayLinAung's user avatar
40 votes
2 answers
14k views

What are the differences between local Basic and Digest strategy in passportjs

I understand the difference between Passport.js' Basic and Digest authentication, but what is the difference between the local strategy and Basic or Digest? In all three, you enter a username and ...
mathlearner's user avatar
  • 7,589
39 votes
2 answers
22k views

MongoDB schema design for multiple auth user accounts

I am about to build my node.js / express / mongoose / passport application and I am thinking about the right schema design for users and accounts. There will be users loging in from twitter and ...
Sven's user avatar
  • 6,308
36 votes
6 answers
41k views

How to protect static folder in express with passport

I have a project based on express with a required authentication based on passport. The backoffice is an angularjs app served as static files. My authentication code is completly based on https://...
toutpt's user avatar
  • 5,190
36 votes
3 answers
27k views

Passport + Node.js / Automatic login after adding user

I am using passport for authentication and session handling. Everything works fine so far. I implemented a "Sign in" form to add new users to the app. After a user is added I would like to log him/her ...
user937284's user avatar
  • 2,554
35 votes
6 answers
20k views

TypeError: req.session.regenerate is not a function using Passport

Hello I'm following the course Node with React full web stack, and I got a big issue, I don't know why it's showing up, or from what is showing up. my terminal shows this error : req.session....
CodyKolby's user avatar
  • 351
35 votes
8 answers
48k views

JWT Verify client-side?

I have a nodejs api with an angular frontend. The API is successfully using JWT with passport to secure it's endpoints. I am now conscious that after the tokens have expired, my front end will still ...
George Edwards's user avatar
35 votes
1 answer
7k views

Optional authentication in Nest.js with @nestjs/passport

I have a route that needs to be used by authenticated and unauthenticated users. I use @UseGuards(AuthGuard('jwt')) to enable authentication but it prevents any unauthenticated user to access the ...
Hugo Da Roit's user avatar
34 votes
3 answers
10k views

Facebook-passport with JWT

I've been using Passport on my server for user authentication. When a user is signing in locally (using a username and password), the server sends them a JWT which is stored in localstorage, and is ...
Bar Kedem's user avatar
  • 595
33 votes
4 answers
9k views

Sails.js + Passport.js authentication through websockets

When I use Sails.js with Passport.js, the isAuthenticated method does not exist on the req object when requested through websocket. Could anyone tell me why this happens?
Elliot Lings's user avatar
  • 1,086
32 votes
6 answers
59k views

Javascript: %s or %d represents string?

Can someone please explain what's happening here? I see %d and %s but I don't see these declared or written anywhere else in the code. What the heck does this mean/ do in javascript? I'm assuming it's ...
Turnipdabeets's user avatar
32 votes
1 answer
17k views

Verify access/group in Passport.js

I would like to use passport.js to verify that when users hit certain endpoints that they not only have the correct password but are a member of a specific group or have a certain access. For ...
lostintranslation's user avatar
32 votes
2 answers
15k views

How can I access OAuth's state parameter using Passport.js?

I'm using Passport.js to do authentication, and per Google's OAuth2 documentation, I'm passing in a state variable: app.get('/authenticate/googleOAuth', function(request, response) { passport....
Mike Pateras's user avatar
  • 14.9k

1
2 3 4 5
140