All Questions
Tagged with node.js passport.js
5,451
questions
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....
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 ...
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....
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 ...
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 ...
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 ...
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?
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/...
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 ...
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 ...
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, & ...
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('...
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 ...
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?
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 ...
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 ...
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?
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 ...
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 ...
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
...
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 ...
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 ...
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 (...
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('...
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....
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:
...
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 ...
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 ...
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 ...
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 ...
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
...
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:...
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 ...
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://...
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 ...
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....
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 ...
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 ...
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 ...
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?
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 ...
31
votes
2
answers
20k
views
how do I redirect back to the originally-requested url after authentication with passport-saml?
Sorry if this is a bonehead question, but I'm having some trouble understanding how I might redirect the client browser back to whatever URL was originally requested after a successful authentication ...
30
votes
7
answers
26k
views
Payload error in jsonwebtoken
I am making a web application using nodejs and angular cli
I'm using JWT to authenticate my login function . But when I process it threw this error
Error: Expected "payload" to be a plain object.
...
30
votes
2
answers
29k
views
How does passport js stores user object in session?
I am using node/express with passport in my development. I came across an article which says:
Express loads the session data and attaches it to the req. As passport stores the serialised user in ...
28
votes
3
answers
28k
views
what is passport.initialize()? (nodejs express)
I'm now trying to apply passport module in my apps.
I'm reading some manuals, and there say,
app.use(passport.initialize());
app.use(passport.session());
what is app.use(passport.initialize()) ...
28
votes
5
answers
43k
views
Nodejs Passport display username
In nodeJS I am using the passport module for authentication. I would like to show the username of the currently logged in user.
I tried the following code:
passport.displayName
and
Localstrategy....
28
votes
5
answers
59k
views
Passport: Unknown authentication strategy "local"
I'm new to NodeJS and I try to build a login/registration system. Registration works fine but I'm currently unable to login.
I find a example app using passport and nodejs, so based on this example I ...
28
votes
3
answers
28k
views
How to add "Remember Me" to my app with passport
I need a "Remember Me" checkbox when logging in like this .
And I add a middleware before using passport
app.use(function(req, res, next) {
if (req.method == 'POST' && req.url == '/login') {...
28
votes
1
answer
11k
views
Using react-router and express with authentication via Passport.js - possible?
So I'm working on a project that incorporates React, Express.js+Passport and Webpack. I understand the concept of pushing everything to a 'master' React component via react-router, then letting it ...
27
votes
2
answers
39k
views
What is the attribute "done" in NodeJS?
I'm coding the local login in NodeJS following this tutorial:
https://scotch.io/tutorials/easy-node-authentication-setup-and-local
In the file config/passport.js
function(req, email, password, done)...