My web pages https://localhost:3000/#/login
and https://localhost:3000/#/new
work, https://localhost:3000/#/new
has a button to do a facebook login by passportjs
. Here is the related code:
In auth.js
:
module.exports = {
'facebookAuth': {
'clientID': '1416536398420xxx',
'clientSecret': '...',
'callbackURL': 'https://localhost:3000/#/auth/facebook/callback'
}
}
In passport.js
:
passport.use(new FacebookStrategy({
clientID: configAuth.facebookAuth.clientID,
clientSecret: configAuth.facebookAuth.clientSecret,
callbackURL: configAuth.facebookAuth.callbackURL
},
function (accessToken, refreshToken, profile, done) {
process.nextTick(function () {
User.findOne({ 'facebook.id': profile.id }, function (err, usr) {
if (err) return done(err);
if (user) return done(null, user);
else {
var newUser = new User();
newUser.facebook.id = profile.id;
newUser.facebook.token = accessToken;
newUser.facebook.name = profile.name.givenName + ' ' + profile.name.familyName;
newUser.facebook.email = profile.emails[0].value;
newUser.save(function (err) {
if (err) throw err;
return done(null, newUser)
})
}
})
})
}
));
In index.js
:
router.get('/auth/facebook', passport.authenticate('facebook', { scope: ['email'] }));
router.get('/auth/facebook/callback',
passport.authenticate('facebook', { successRedirect: '/login',
failureRedirect: '/login' }));
By clicking the facebook login button, it does redirect to facebook login page, after entering username and password, the address becomes https://localhost:3000/?code=AQCh9Q9KgZjL3TzTpyMW61gxcNZjN2vEgQAvr5r1k9-WxjwfmVzsPL9Txu-oTkP08MJXyvmJiGEt8zrgHGjLAbpg3SsvCGQEM1jdxwj4YUGL5dmUU3Xm7JZZfUOcCqaGuLSEFcfX-s62-X6uUuPS0D62wWzrAI-NK6gdvudl_JzWBK2O5ptdhGhN8PbbLytGpySEsIY8VVKaI55Tu6fjYA9v2R7Fp_7R2c4krdhA8Pp2A3Z9dQDpg42cZLzxuUtDVqxaPHFNZOufETiE23GxSCObjdq_oSmWkgAVOH1sa2EtPzjawohDZllNmNF-8iGLQQ0#/auth/facebook/callback
As a consequence, it hangs; the page is blank.
Does anyone know what's wrong with my routes?
Edit 1: I just added Valid OAuth redirect URIs
, but the url address i get still finishes by #/auth/facebook/callbak
.