我的網頁https://localhost:3000/#/login
和https://localhost:3000/#/new
工作,https://localhost:3000/#/new
有一個按鈕,通過passportjs
做Facebook登錄。下面是相關的代碼:驗證回撥錯誤
在auth.js
:
module.exports = {
'facebookAuth': {
'clientID': '1416536398420xxx',
'clientSecret': '...',
'callbackURL': 'https://localhost:3000/#/auth/facebook/callback'
}
}
在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)
})
}
})
})
}
));
在index.js
:
router.get('/auth/facebook', passport.authenticate('facebook', { scope: ['email'] }));
router.get('/auth/facebook/callback',
passport.authenticate('facebook', { successRedirect: '/login',
failureRedirect: '/login' }));
通過點擊Facebook登錄按鈕,它重定向到Facebook登錄頁面,輸入用戶名和密碼後密碼,地址變爲https://localhost:3000/?code=AQCh9Q9KgZjL3TzTpyMW61gxcNZjN2vEgQAvr5r1k9-WxjwfmVzsPL9Txu-oTkP08MJXyvmJiGEt8zrgHGjLAbpg3SsvCGQEM1jdxwj4YUGL5dmUU3Xm7JZZfUOcCqaGuLSEFcfX-s62-X6uUuPS0D62wWzrAI-NK6gdvudl_JzWBK2O5ptdhGhN8PbbLytGpySEsIY8VVKaI55Tu6fjYA9v2R7Fp_7R2c4krdhA8Pp2A3Z9dQDpg42cZLzxuUtDVqxaPHFNZOufETiE23GxSCObjdq_oSmWkgAVOH1sa2EtPzjawohDZllNmNF-8iGLQQ0#/auth/facebook/callback
因此,它掛起;該頁面爲空白。
有人知道我的路線有什麼問題嗎?
編輯1:我剛剛加入Valid OAuth redirect URIs
,但url地址仍然完成#/auth/facebook/callbak
。
什麼URL在您的「有效的OAuth重定向URI」在facebook oauth設置頁面中? – Ken
請參閱我的更新... – SoftTimur
哇,我真的希望這不是您的實際OAuth憑證... – Paul