【问题标题】:Passport.js Facebook Strategy not working because URL Blocked由于 URL 被阻止,Passport.js Facebook 策略不起作用
【发布时间】: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"]
    }
}

Whole app on github

【问题讨论】:

    标签: node.js oauth-2.0 passport.js facebook-authentication


    【解决方案1】:

    这里的这一行: "calbackURL": "//localhost:3000/auth/facbeook/callback"

    查看您的 fb 应用配置的站点。 我修改了我的主机文件以使用 local.mysite.com:3000 并且 FB 接受了。

    编辑: 你解决了这个问题吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      • 2020-09-11
      • 2021-04-16
      • 2018-02-26
      • 2019-11-19
      • 2020-09-12
      相关资源
      最近更新 更多