Passport.js Facebook策略不起作用,因为URL被阻止



当我转到localhost:3000并使用带有facebook的登录按钮时,我收到了这个错误。

URL被阻止:此重定向失败,因为重定向URI不是应用程序的客户端OAuth设置中的白名单。确保客户和Web OAuth登录已打开,并将所有应用程序域添加为有效OAuth重定向URI。

即使我没有登录到脸书,并且我试图被引导到脸书登录,我也会得到一个空白页面,显示这个错误,而不是

未登录:您未登录。请登录并重试。

这是我的身份验证模块的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&秘密,但在我的发展过程中,这些价值观确实存在,并且是从各自的提供者那里获得的。

{
    "host": "http://localhost:3000",
    "dbURI": "",
    "sessionSecret": "catscanfly",
    "fb": {
        "clientID": "",
        "clientSecret": "",
        "calbackURL": "//localhost:3000/auth/facbeook/callback",
        "profileFields": ["id", "displayName", "photos"]
    }
}

github 上的整个应用程序

此处的此行:"calbackURL":"//localhost:3000/auth/fabbeook/recallback"

查看你的fb应用程序是为哪个网站配置的。我修改了我的主机文件以使用local.mysite.com:3000,FB接受了这一点。

编辑:你解决问题了吗?

相关内容

最新更新