【发布时间】:2018-03-01 11:00:45
【问题描述】:
我正在尝试通过 passport-facebook 对用户进行身份验证,但发生了一件非常奇怪的事情,我真的不确定。在定义我的路线时,我有这行代码
app.get('/login/facebook',
IsAuth.facebookEnter ),
//passport.authenticate('facebook')
app.get('/login/facebook/return',
IsAuth.facebookComeBack)
在我的 IsAuth 文件中,我有以下内容
const passport = require('passport')
const FacebookStrategy = require('../passport/facebook_passport')
module.exports = {
facebookEnter(){
passport.authenticate('facebook')
},
facebookComeBack(){
passport.authenticate('facebook', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
}
}
}
and the strategy itself here
const passport = require('passport')
const User = require('../models/User')
const FacebookStrategy = require('passport-facebook')
passport.use(new FacebookStrategy({
clientID: "ALMOST POSTED IT",
clientSecret: "Ntest test",
//call baack to one of our routes to valiate the auth request
//is called when the user pressed on OK to login with facebook
callbackURL: "http://localhost:8888/login/facebook/return"
},
function(accessToken, refreshToken, profile, cb) {
console.log(profile, accessToken, refreshToken)
}
))
问题是
为什么要写
app.get('/login/facebook',
IsAuth.facebookEnter ),
it doesnt work but if i write this code
app.get('/login/facebook',
passport.authenticate('facebook') ),
然后它起作用了,那为什么呢?即使使用相同的文件夹结构,我的 JWT 护照身份验证也能按预期工作我怎样才能让它工作并将 passport.authenticate 保存在单独的文件中?
【问题讨论】:
标签: javascript node.js facebook authentication passport.js