Oath facebook error: “URL blocked: This redirect failed because...“ and cannot get

Oath facebook error: “URL blocked: This redirect failed because...“ and cannot get

我在网上看到了所有可能的答案,但就是无法正常工作,也不明白为什么。我遇到的第一个问题是常见的:“URL 已阻止:此重定向失败,因为重定向 URI 未在应用程序的客户端 OAuth 设置中列入白名单”。经过几个小时的反复试验,尝试了所有可能的方式(http、https、www 和没有),我管理应用程序将 FacebookId 保存在 mongoDB 中(尽管没有提示我进入 Facebook 登录页面) ,但是现在我收到 Cannot GET /auth/facebook 消息。现在我知道我在 mondoDB 中已经有一个问题,因为此时没有多个帐户可以保存,并且作为用户名的电子邮件地址将是 NULL,并且只允许一个,但是在擦除数据库后,我可以使用 Google oath 登录而没有问题,看来我在设置

时遇到了问题

Facebook and i just don`t know what im doing wrong. Thank you in advanced!

facebooksettings facebooksettings2

站点 url 设置为:https://app-secret.herokuapp.com/

app.js
...
//use session package with some setup config//
app.use(session({
  secret: 'My little secret.',
  resave: false,
  saveUninitialized: false,
}))

//initalize passport packadge and for also to deal with the session//
app.use(passport.initialize());
app.use(passport.session());

mongoose.connect("mongodb+srv://andras:MYPASSWORD@cluster0.zfr0d.mongodb.net/userDB", {
  useNewUrlParser: true,
  useUnifiedTopology: true
});

//schema in order to have a plugin it has to be a mongoose schema//
const userSchema = new mongoose.Schema({
  email: String,
  password: String,
  googleId: String,
  facebookId: String,
  secret: Array
});

//adding plugins to schema//
userSchema.plugin(passportLocalMongoose);
userSchema.plugin(findOrCreate);

const User = new mongoose.model("User", userSchema);

//configuring passport, serialize=create and deserialize=able to crack open cookie//
passport.use(User.createStrategy());

passport.serializeUser(function(user, done) {
  done(null, user.id);
});

passport.deserializeUser(function(id, done) {
  User.findById(id, function(err, user) {
    done(err, user);
  });
});

passport.use(new GoogleStrategy({
    clientID: process.env.CLIENT_ID,
    clientSecret: process.env.CLIENT_SECRET,
    callbackURL: "https://app-secret.herokuapp.com/auth/google/secrets",
    userProfileURL: "https://www.googleapis.com/oauth2/v3/userinfo"
  },
  function(accessToken, refreshToken, profile, cb) {
    // console.log(profile);
    User.findOrCreate({
      googleId: profile.id
    }, function(err, user) {
      return cb(err, user);
    });
  }
));

passport.use(new FacebookStrategy({
    clientID: process.env.FACEBOOK_APP_ID,
    clientSecret: process.env.FACEBOOK_APP_SECRET,
    callbackURL: "https://app-secret.herokuapp.com/auth/facebook"
  },
  function(accessToken, refreshToken, profile, cb) {
    User.findOrCreate({
      facebookId: profile.id
    }, function(err, user) {
      return cb(err, user);
    });
  }
));

app.get("/", function(req, res) {
  res.render("home")
});

app.get("/auth/google",
  passport.authenticate('google', {
    scope: ["profile"]
  })
);

app.get("/auth/google/secrets",
  passport.authenticate('google', {
    failureRedirect: "/login"
  }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/secrets');
  });

app.get('/auth/facebook',
  passport.authenticate('facebook'));

app.get('/auth/facebook/secrets',
  passport.authenticate('facebook', {
    failureRedirect: '/login'
  }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/secrets');
  });

很抱歉用我新手的痛苦向 Whosebug 发送垃圾邮件。我意识到我哪里出错了,我认为 facebook API 是让我头疼的那个,但没有意识到 app.js 中的 facebook 回调缺少正确的路径 .. 而不是:“app-secret.herokuapp.com/auth/facebook” 它应该是:“app-secret.herokuapp.com/auth/facebook/secrets”