MEAN 스택 응용 프로그램에서 페이스 북 인증을 설정하려고합니다. 서면 코드는 페이스 북에서 사용자를 인증 할 때까지 작동하지만, 애플리케이션으로 되돌려 보내면 콜백 기능이 실행되지만 passport.authenticate('facebook'.....
부분은 실행되지 않습니다.Node.js를 사용하여 passport.js로 성공적인 인증 콜백을 설정하려면 어떻게해야합니까?
이것은 루트 파일에 내 코드입니다 :
app.get('/auth/facebook', passport.authenticate('facebook', { scope : 'email' }));
app.get('/auth/facebook/callback', function() {
console.log('callback')
passport.authenticate('facebook', {
successRedirect : '/',
failureRedirect : '/fail'
})
});
"콜백"콘솔에 출력되지만 다음 응용 프로그램은로드의 상태 그 때까지 시간 초과입니다. 당신의 /auth/facebook/callback
당신이 당신의 경로 처리기 내부가 아닌 즉 미들웨어로 passport.authenticate
을 실행중인에서는
// config/passport.js
// load all the things we need
var LocalStrategy = require('passport-local').Strategy;
var FacebookStrategy = require('passport-facebook').Strategy;
// load up the user model
var User = require('../app/models/user');
// load the auth variables
var configAuth = require('./auth');
module.exports = function(passport) {
passport.use('facebook', new FacebookStrategy({
clientID : configAuth.facebookAuth.clientID,
clientSecret : configAuth.facebookAuth.clientSecret,
callbackURL : configAuth.facebookAuth.callbackURL,
profileFields: ["emails", "displayName"]
},
// facebook will send back the tokens and profile
function(access_token, refresh_token, profile, done) {
// asynchronous
process.nextTick(function() {
// find the user in the database based on their facebook id
User.findOne({ 'id' : profile.id }, function(err, user) {
// if there is an error, stop everything and return that
// ie an error connecting to the database
if (err)
return done(err);
// if the user is found, then log them in
if (user) {
return done(null, user); // user found, return that user
} else {
// if there is no user found with that facebook id, create them
var newUser = new User();
// set all of the facebook information in our user model
newUser.fb.id = profile.id; // set the users facebook id
newUser.fb.access_token = access_token; // we will save the token that facebook provides to the user
newUser.fb.firstName = profile.name.givenName;
newUser.fb.lastName = profile.name.familyName; // look at the passport user profile to see how names are returned
newUser.fb.email = profile.emails[0].value; // facebook can return multiple emails so we'll take the first
// save our user to the database
newUser.save(function(err) {
if (err)
throw err;
// if successful, return the new user
return done(null, newUser);
});
}
});
});
}));
}
는 여권 파일에 일부 로그를 추가 하시겠습니까? 어디로 가는지 봐? – DrakaSAN
@DrakaSAN 여권 파일을 전혀 실행하지 않는 것 같습니다. 나는 여권 파일의 다양한 부분에 console.log (x)를 추가했으며 전혀 실행하지 않습니다. – James