Ich mache diese Strategie, wo ich Authentifizierung von URL-Parametern versuchen. Es ruft von Java-Code.mit pass.js machen Strategie, was verwenden req.params statt req.body
url wie folgt aussieht: http://localhost/mc/download/filename/[email protected]/secretpass
diese Strategie:
passport.use('mc-login', new LocalStrategy({
passReqToCallback : true // allows us to pass back the entire request to the callback
},
function(req, email, password, done) { // callback with email and password from our form
// find a user whose email is the same as the forms email
// we are checking to see if the user trying to login already exists
User.findOne({ 'local.email' : req.params.uname }, function(err, user) {
// if there are any errors, return the error before anything else
if (err)
return done(err);
// if no user is found, return the message
if (!user)
return done(null, false, req.flash('loginMessage', 'No user found.')); // req.flash is the way to set flashdata using connect-flash
// if the user is found but the password is wrong
if (!user.validPassword(req.params.upass))
return done(null, false, req.flash('loginMessage', 'Oops! Wrong password.')); // create the loginMessage and save it to session as flashdata
// all is well, return successful user
return done(null, user);
});
}));
Ich versuche, es in diesem Code aufrufen:
app.get('/mc/download/:fname/:uname/:upass',
function(req, res, next) {
passport.authenticate('mc-login', function(err, user, info) {
if (err) { return next(err); }
if (!user) { return res.redirect('/login'); }
req.logIn(user, function(err) {
if (err) { return next(err); }
return res.redirect('/users/' + user.username);
});
})(req, res, next);
}
,function(req, res){
...
aber in info Variable zurückgeben den [stack=undefined,name="BadRequestError",message="Missing credentials"]
und Benutzer ist leer
Wie Strategie machen, was erlauben, mit req.params
Variablen