passport.js

Node + Express server not responding after OPTIONS preflight request

£可爱£侵袭症+ 提交于 2019-12-08 07:32:57
问题 I'm currently facing the following error, I'm developing an API in node js for let's say a virtual shop. An user, for getting its items in cart needs to be authenticated. The authentication is being handled via JWT, and im using passport module for that propose. For the routes that require authentication, when the API is consumed using the 'Authentication' header with its correspondent 'JWT ey...' token, the server is not handling any request. Just responds to the OPTIONS preflight request

Wrapping passport.authenticate inside a function doesn't work

老子叫甜甜 提交于 2019-12-08 07:09:10
问题 I am trying to authenticate user using Google OAuth2Strategy. I have below routes **server.get('/user/google', passport.authenticate('google', {scope: ['openid email profile']}); server.get('/user/google/callback', authenticate.authenticateGoogleCallback);** and this works completely fine. but when I wrap the first authenticate like how i have done for callback, it just hangs. It it a bug or i am doing something wrong? This is what i am trying. **server.get('/user/google', authenticate

How to passing data in TwitterStrategy, PassportJS?

女生的网名这么多〃 提交于 2019-12-08 07:06:35
问题 I have three kind of user: Viewer (link to sign in: auth/ v /twitter) Creator (link to sign in: auth/ c /twitter) Admin (link to sign in: auth/ a /twitter) And also I have 3 different db/collection c_viewer c_creator c_admin Where each kind of user have a different link to sign in. Now let's take a look at the codes var passport = require('passport') ,TwitterStrategy = require('passport-twitter').Strategy; passport.use(new TwitterStrategy({ consumerKey: config.development.tw.consumerKey,

Cannot read property 'connect.sid' of undefined at Layer.session - ExpressJS session

孤街醉人 提交于 2019-12-08 05:40:28
问题 I am having problems using sessions in ExpressJS 4. I have tried adding session both in server.js (where I set my app's configurations) and in routes.js (where I define my routes). This is what I keep getting: TypeError: Cannot read property 'connect.sid' of undefined at Layer.session [as handle] (/Users/larissaleite/Documents/Routing/node_modules/express-session/index.js:115:32) at trim_prefix (/Users/larissaleite/Documents/Routing/node_modules/express/lib/router/index.js:226:17) at c (

passport-azure-ad, does it parse & validate token?

て烟熏妆下的殇ゞ 提交于 2019-12-08 05:30:24
问题 My MEAN stack application is using Azure AD for authentication. I am using “passport-azure-ad” module for web api authentication. Based on post & reply here I understood that If user is already authenticated by client (UI) then for every API call, client will also send token to the server. And then on the server we can use bearer strategy to “Authorize” user’s access to API. Now in my scenario I just wanted to make sure user is authenticated, and if he is then allow him to access API.

Configure Passport to accept request without body?

徘徊边缘 提交于 2019-12-08 04:46:49
问题 I'm trying to set a LocalStrategy with the possibility to login without credentials given in request body app.post('/signin', passport.authenticate('local-signin', {failureFlash : true}), function (req, res) { res.send(req.user); }); Here's the strategy : passport .use('local-signin', new LocalStrategy({ usernameField : 'email', passwordField : 'password', passReqToCallback : true }, function (req, email, password, done) { if (email.length > 0 && password.legnth > 0) { /** Do some stuff with

How to use the same passport strategy for different routes?

a 夏天 提交于 2019-12-08 03:49:45
问题 Suppose I have the code like this: var api1 = require('api1'); var api2 = require('api2'); var app = express(); app.use('/api1', api1); app.use('/api2', api2); Here is the code for api1 module: var router = express.Router(); var options = { jwtFromRequest:ExtractJwt.fromAuthHeader(), secretOrKey:config.JWTSecret, algorithms:['HS256'] } passport.use(new JwtStrategy(options, function(jwt_payload, verify) { //here I look for the user in database No.1 })); router.post('/files', passport

passport local type error

谁说胖子不能爱 提交于 2019-12-08 03:22:35
问题 I'm trying to use passport-local for authentication in my Sails project. In my controller: passport.authenticate('local', function(err, user, info) { if ((err) || (!user)) { res.json({message: 'Unable to authenticate'}); return; } req.login(user, function(err) { if (err) { res.json({message: 'Unable to login'}); console.log(err); return; } res.json({message: 'logging in'}); }); })(req, res); In a config file: passport.use(new LocalStrategy(function(username, password, done) { User

Cannot set headers after they are sent to the client

半世苍凉 提交于 2019-12-08 03:13:00
问题 Cannot set headers after they are sent to the client. This is my back-end side error after authentication post request.It looks like problem with headers. I'm sorry for my dirty code for my project i need to do something else,so there some code in comment. This is my code const express = require("express"); const router = express.Router(); const Spec = require("../models/specialist"); const jwt = require("jsonwebtoken"); const config = require("../config/data"); const passport = require(

CORS/CORB issue with React/Node/Express and google OAuth

自作多情 提交于 2019-12-08 02:20:28
问题 I have a react app that I'm trying to add a Node/Express/MySQL backend to with OAuth. My React app is hosted on localhost:3000 and the express server is on localhost:4000. I added "proxy":"http://localhost:4000" to the react app's package.json file to send requests to the server. The Authorized Javascript Origin for the OAuth is http://localhost:4000. The Authorized redirect URI is http://localhost:4000/auth/google/redirect. These are the errors I get in the browser's console when I try to