passport.js

NodeJS/Passport - Testing user login with mocha and superagent

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 07:33:07
问题 I have built a login process with a basic MEAN stack and using passport for the authentication process. I am trying to set up a test to make sure the login process is working. To do the login part here is the code I used: it ('login', function(done) { agent.post(config.web.vhost + '/login') .send({ email: 'bruce@wayne.inc', password: 'batman' }) .end(function(err, res) { if (err) console.log('error' + err.message); res.should.have.status(200); done(); }); }); I get the following error: no

passport match username and password in a sub document if the “parent” document doesn't have any matching username and passwords

巧了我就是萌 提交于 2019-12-25 04:33:32
问题 I was thinking of setting up an like the following. There will be a login page that an admin can access and a worker can access. the admin can make it so that the workers could see certain data(the admin can create workers). The main problem right now is hooking this up with passport. I think the user document look something like this {username: "user1", password : "pass1", role : "admin", workers :[ {username : "worker1", password : "workerpass1"}, {username : "worker2", password :

req.user undefined after twitter authentication using express sever, passport.js

喜你入骨 提交于 2019-12-25 04:30:36
问题 There are many questions relating to getting a req.user undefined after social authentication, but I found none which could help me. I have been able to successfully use the example for using passport for twitter authentication: https://github.com/passport/express-4.x-twitter-example. I tried to follow this pattern as closely as possible but cannot seem to get it to work. Specifically, I am able to successfully authenticate, but the req.user is undefined. This makes no sense to me as my user

Bcrypt node.js returns false on compare

╄→гoц情女王★ 提交于 2019-12-25 04:26:14
问题 i got a problem with bcrypt on node.js -> the bcrypt compare method returns false while comparing the passwords from a mongoDB and a user entry. I have no idea why and i tried to debug it since 3 days but i really need some extern help... UserShema: var userSchema = new Schema({ name: { type: String, required: true }, password: { type: String, required: true } }); hash and salt: userSchema.pre('save', function (next) { var user = this; if (this.isModified('password') || this.isNew) { bcrypt

How to issue tokens from Azure AD in a Node.js App/API?

耗尽温柔 提交于 2019-12-25 04:14:06
问题 I am building a node app with a express backend. One of the requirements is using Azure AD for authentication. I've installed the passport-azure-ad module and have set it up as the following: import * as passportAD from "passport-azure-ad"; // ... <snip> .... const tenantName = "<MY_TENANT_NAME>""; const clientID = "<MY_CLIENT_ID>"; app.use(passport.initialize()); app.use(passport.session()); const bearerStrategy = new passportAD.BearerStrategy( { identityMetadata: `https://login

Why fetching a server API which triggers Oauth2 Google authentication results in `No 'Access-Control-Allow-Origin'` error?

倾然丶 夕夏残阳落幕 提交于 2019-12-25 04:02:45
问题 I want to authenticate a user using Google's Oauth2 mechanism. I have a React component with a button. The button's click handler makes an AJAX request to my server: import React from 'react'; import { connect } from 'react-redux'; import { withRouter } from 'react-router-dom'; import PropTypes from 'prop-types'; import Button from '@material-ui/core/es/Button/Button'; import LinearProgress from '@material-ui/core/es/LinearProgress/LinearProgress'; import constants from '../../constants.js';

Automatically logging in a user with KoaJS and PassportJS

丶灬走出姿态 提交于 2019-12-25 03:34:52
问题 I'm trying to automatically log in a user with PassportJS. This is my current code: myRouter.get('/signin', function* (next) { user = {...}; var res = this.res; // needed for the function below this.req.login(user, function(err) { if (err) console.log('error logging in user - '+err); return res.redirect('/'); // <--- line 439 }); }); But when I run it, I get the error: error logging in user - TypeError: undefined is not a function TypeError: undefined is not a function at /srv/www/domain.com

Passport middleware for Node.js

这一生的挚爱 提交于 2019-12-25 02:04:05
问题 I am using Passport authentication middleware for Node.js. I would like to use it from within my own objects (rather than inline in a route definition). The reason for this that the auth mechanism will change depending on application settings and I would like to maintain separation of concerns and testability. An example of use from the documentation: app.post('/session/create', passport.authenticate('local', { failureRedirect: '/login' }), function(req, res) { res.redirect('/'); }); I would

Local and social authorization with node.js on mobile app

浪子不回头ぞ 提交于 2019-12-25 01:54:08
问题 Im running node.js server with mongodb as a DB, for local and FB auth from browser I use passport.js How can I use both from mobile phone app? Can someone describe the flow precisely? Cause I couldnt really find precise explanation of such flow few points that I dont get in the flow right away: How req.isAuthenticated is working with iphone apps How fb strategies work for iphone app? 回答1: Try following scenario: You can use facebook-ios-sdk for login via iphone to get facebook access token

Share sessions with redis and passport on a subdomain?

醉酒当歌 提交于 2019-12-25 01:49:49
问题 I am using npm subdomain, inside my app I have routes that fake a subdomain // looks like app.localhost:3000 router.get('/subdomain/app', app.dashboard); So I have a login page on a subdomain and a login page on a non subdomain page. They don't share sessions, so I have to login twice. I want to setup redis, but I don't know how. // here is my session middleware, I tried using .localhost app.use(session({ secret: 'something', domain: '.localhost', })); I have seen where people are using redis