【发布时间】:2016-03-28 19:30:49
【问题描述】:
当我转到 localhost:3000 并使用带有 facebook 按钮的登录时出现此错误。
URL 被阻止:此重定向失败,因为重定向 URI 不是 在应用程序的客户端 OAuth 设置中列入白名单。确保客户和 Web OAuth 登录已打开并将您的所有应用程序域添加为有效 OAuth 重定向 URI。
即使我没有在 facebook 上登录,并且我尝试被定向到 facebook 进行登录,我也会得到一个包含此错误的空白页面
未登录:您尚未登录。请登录并重试。
这是我的身份验证模块的 index.js:
'use strict';
const passport = require('passport');
const config = require('../config');
const h = require('../helpers');
const FacebookStrategy = require('passport-facebook').Strategy;
module.exports = () => {
passport.serializeUser((user, done) => {
done(null, user.id);
});
passport.deserializeUser((id, done) => {
//Find the user using the _id
h.findById(id)
.then(user => done(null, user))
.catch(error => console.log('Error when deserializing user'));
});
let authProcessor = (accessToken, refreshToken, profile, done) => {
// Find a user in the local db using profile.id
// If the user is found, return the user data using the done() method
// If the user is not found, create one in the local db and return
h.findOne(profile.id)
.then(result => {
if(result) {
done(null, result);
} else {
// Create a new user and return
h.createNewUser(profile)
.then(newChatUser => done(null, newChatUser))
.catch(error => console.log("Error when creating a new user"))
}
})
}
passport.use(new FacebookStrategy(config.fb, authProcessor));
这是我的 config / development.json 文件。我取出了 dbURI 和 fb clientID & secret 的值,但在我的开发中,这些值确实存在,并且是从它们各自的提供者那里获得的。
{
"host": "http://localhost:3000",
"dbURI": "",
"sessionSecret": "catscanfly",
"fb": {
"clientID": "",
"clientSecret": "",
"calbackURL": "//localhost:3000/auth/facbeook/callback",
"profileFields": ["id", "displayName", "photos"]
}
}
【问题讨论】:
标签: node.js oauth-2.0 passport.js facebook-authentication