我正在使用护照允许通过 Facebook 在我的网站上登录。一切似乎都很好,但是即使我使用有效令牌从 Facebook 取回所有数据,来自 Facebook 网站的回调总是会转到 failureRedirect。关于为什么会发生这种情况的任何想法?
express = require "express"
passport = require 'passport'
FBStrategy = require('passport-facebook').Strategy
Properties = require "./config.json"
FB_APP_ID = REMOVED
FB_APP_SECRET = REMOVED
passport.serializeUser = (user, done) ->
done null, user
passport.deserializeUser = (obj, done) ->
done null, obj
fb = new FBStrategy
clientID: FB_APP_ID
clientSecret: FB_APP_SECRET
callbackURL: "http://localhost/auth/facebook/callback"
(accessToken, refreshToken, profile, done) ->
console.log "accesToken ", accessToken
console.log "refreshToken", refreshToken
console.log "profile", profile
done()
passport.use fb
app = module.exports = express.createServer()
app.Properties = Properties
console.log "starting server"
app.configure ->
app.set "views", "./views"
app.set "view engine", "jade"
app.set "view options", layout: false
app.use express.methodOverride()
app.use (express.static "#{__dirname}")
app.use express.cookieParser()
app.use express.bodyParser()
app.use (express.session secret: REMOVED, key: REMOVED)
app.use passport.initialize()
app.use passport.session()
app.use app.router
app.configure "development", ->
app.listen Properties.Port
app.get "/", (request, response) ->
{ session: Session } = request
response.render "index"
app.get "/account", (request, response) ->
{ session: Session } = request
response.render "account"
app.get "/login", (request, response) ->
{ session: Session } = request
response.render "login", {user:request.user}
app.get "/auth/facebook", passport.authenticate 'facebook'
app.get "/auth/facebook/callback", passport.authenticate ('facebook', {failureRedirect: "/login"}), (req, res) ->
res.redirect "/account"
console.log "server is ready and listening on port #{Properties.Port}"