passport.js

Setting up connect-flash middleware for use by passport

橙三吉。 提交于 2019-12-07 07:56:55
问题 I want to access the message that my passport strategy specifies in its callback, like this: done(null, false, { message: 'No such user.' }); . I found out so far that these messages can be displayed by passing the option failureFlash: true into the passport.authenticate() function, the usage of which again requires connect-flash middleware to be installed. So I installed the module and added var flash = require('connect-flash); to my source, as well as app.use(flash()); to the configuration

NestJS Authentication with Auth0 via `passport-jwt`

寵の児 提交于 2019-12-07 07:44:50
问题 I'm trying to create a NestJS project that uses Auth0 for authentication, with the passport-jwt library (in conjunction with @nestjs/passport ), though I am unable to get it to work. I'm not sure where I'm going wrong. I've read the docs over and over again but still can't find the problem. Code /src/auth/jwt.strategy.ts import { Injectable, UnauthorizedException } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; import { ExtractJwt, Strategy } from 'passport-jwt';

Passport.js strategy with no field required

五迷三道 提交于 2019-12-07 07:36:19
问题 I'm surprised that it's so hard to find, or maybe something wrong with me. I need a passport.js strategy that requires no fields - to run authentication with it on simple user GET request to '/' and manipulate user session data to, for example, make a new 'guest' user. Maybe i can do this via passport local-strategy ? Or am i need to create a custom one? I saw this Configure Passport to accept request without body? question, yet i just simply can't figure out how the suggested in answer

passport.js - facebook strategy logout issue

牧云@^-^@ 提交于 2019-12-07 06:09:21
问题 I'm trying to set up facebook authentication using this login example. Example works but when I log out and try to log in again passport automatically lets me in without giving me an option to change facebook user. Any idea on how to change this behaviour? 回答1: By default, if you have already authorized login with Facebook, subsequent requests to authenticate will be automatic and won't prompt the user to authorize again. There are three options to change this behavior: 1. Log the user out of

Setting Up Postman for API Testing When Using Passport Authorization

孤人 提交于 2019-12-07 06:05:47
问题 I am a bit confused while trying to get Postman to work when testing the API of my application. Namely, I am using Passport authentication; however, I do not know which type it defaults to or uses in my code. How can I figure this out and which type should I choose in Postman? Here is the relevant Passport code: var login = require('./login'); var signup = require('./signup'); var User = require('../models/user'); module.exports = function(passport, path, nodemailer, sesTransport,

user is not defined: Nodejs/Express + Passport

半城伤御伤魂 提交于 2019-12-07 05:52:18
问题 My problem is very similar to this question however the answers seems to not work for me (I see that user never picked an answer also). I have a fresh install of Nodejs and Express. My setup: app.use(express.static(path.join(__dirname, 'public'))); app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false })); app.use(cookieParser('hithere')); app.use(session({ secret: 'hithere', resave: false, saveUninitialized: true })); app.use(passport.initialize(

How Passport Strategy works behind the Scene

◇◆丶佛笑我妖孽 提交于 2019-12-07 05:16:35
问题 I was trying to comprehend how passport strategy is working. Consider these api routes which I am using to authenticate. router.get("/google", passport.authenticate('google', { scope: ['profile', 'email'] })); router.get("/google/callback", passport.authenticate('google'), (req, res) => { res.redirect("http://localhost:3000/") }) And this is the passport strategy const passport = require('passport') const GoogleStratergy = require('passport-google-oauth20') const keys = require("./key.js")

Node.js one session per user

允我心安 提交于 2019-12-07 04:20:22
问题 How can I prevent my users to be logged in my system from two devices same time? So if user logged in from computer, when he logins from different computer, session on first automatically closes (don't need make it realtime). I use node.js, express.js, mongoose, passport, connect-mongo (to store sessions in database). 回答1: You can generate a token when user logs in and save it in your database against that user. Now with each request you will need to send this token to server. Consider the

Questions about how passport.js works. Specifically about user.id

冷暖自知 提交于 2019-12-07 04:05:31
I have no id field in my model , doc , or record or whatever you want to call it. So how come done(null, user.id) works. I have an _id but no id . It looks like a passport object is being added to my session with the _id of the user in the DB, but how did it get the _id is it done automatically? in the docs it says In this example, only the user ID is serialized to the session how did it get the id and how did it get the user? similar example in my code: passport.serializeUser(function(user, done){ done(null, user.id) }); passport.deserializeUser(function(id, done){ User.findById(id, function

Local and Google strategy in passport.js: issue when serializing user

你说的曾经没有我的故事 提交于 2019-12-07 03:30:32
I've been trying to understand why I couldn't keep an user logged in once authenticated even though authentication itself was working. I even posted a question here: Passport.js - Local strategy doesn't authenticate By trying to fix the issue, I finally worked out what's wrong. The issue is the following: I have two different passport strategy, so I am serializing and deserializing the user twice. If I serialize the user with the local strategy first, local strategy will work, but Google's won't. And vice versa. I put a comment to highlight the problem in app.js. Here's the files: app.js const