You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to attach a passport strategy to express routes.
In js, it would look like this:
File auth.js:
var passport = require('passport');
var BasicStrategy = require('passport-http').BasicStrategy;
var User = require('../models/user');
passport.use(new BasicStrategy(
function(username, password, callback) {
User.findOne({ username: username }, function (err, user) {
if (err) { return callback(err); }
// No user found with that username
if (!user) { return callback(null, false); }
// Make sure the password is correct
user.verifyPassword(password, function(err, isMatch) {
if (err) { return callback(err); }
// Password did not match
if (!isMatch) { return callback(null, false); }
// Success
return callback(null, user);
});
});
}
));
exports.isAuthenticated = passport.authenticate('basic', { session : false });
Main.js:
var passport = require('passport');
var authController = require('./controllers/auth');
mongoose.connect('mongodb://localhost:27017/beerlocker');
var app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(passport.initialize());
var router = express.Router();
router.route('/beers')
.post(authController.isAuthenticated, beerController.postBeers)
.get(authController.isAuthenticated, beerController.getBeers);
Here is my try to do something similar with haxe:
expressSrv = new js.npm.Express();
function isAuthenticated(req : Request, res : Response) : Void {
trace('isAuthenticated triggered');
js.npm.Passport.authenticate('basic', { session : false });
}
function initExpressRoutes() : Void {
var r = new Router();
r.route('/beers')
.post(isAuthenticated, postBeerAction)
.get(isAuthenticated, getBeersAction);
js.npm.Passport.use(new js.npm.passport.BasicStrategy(
function(email, password, cb) {
trace('basic strategy triggered!');
app.userDao.md.findOne({ email: email },
function (err, user) {
if (err != null) {
cb(err);
return;
}
if (user == null) {
cb(null, false);
return;
}
user.verifyPassword(password,
function(err, isMatch) {
if (err != null) {
cb(err);
return;
}
if (!isMatch) {
cb(null, false);
return;
}
cb(null, user);
});
});
}
));
r.use(js.npm.Passport.initialize());
r.use(BodyParser.json());
expressSrv.use(r);
}
And it might not be the right way to do it as calls hangs on the isAuthenticated method...
What am I doing wrong ?
The text was updated successfully, but these errors were encountered:
Hi !
I'm trying to attach a passport strategy to express routes.
In js, it would look like this:
File auth.js:
Main.js:
Here is my try to do something similar with haxe:
And it might not be the right way to do it as calls hangs on the isAuthenticated method...
What am I doing wrong ?
The text was updated successfully, but these errors were encountered: