[英]passportJS - passport-facebook cannot GET failureRedirect route
Following the passportJS docs for passport-facebook I am trying to implement express middleware for facebook authentication. 在用于护照-facebook的passportJS文档之后,我正在尝试实现用于Facebook身份验证的快速中间件。 I am using mongoose-findorcreate to create the findOrCreate function needed for passportJS.
我正在使用mongoose-findorcreate创建passwordJS所需的findOrCreate函数。
I am able to redirect to the facebook login form, and login with my facebook credentials. 我能够重定向到Facebook登录表单,并使用我的Facebook凭据登录。 But afterwards I get redirected to the failureRedirect URL which return the following:
但是之后,我被重定向到failureRedirect URL,该URL返回以下内容:
Cannot GET /auth/facebook/callback?code=AQBsq2xY-YTsNMmipM45BVBBC9W1QovO1grjC64nDe1psWuRZQwjGv8SMpXuou3s9SaVIIS0_3RqJn-SQ339wPD_TWjRPIpXpZZVHerTRZEQnQYLvt1CM0qMzG5R_JNqfYib6rkmuP4epXou5HoqUa01qszUpYfGMPHUYyNVx1VdMSu3RLbdta8rYle9am539NzYL8ihlwlflnFku-8H3QqlzWJ5Ta1pQ29N0ZyRRu38nKzrDQk-jE5Sq9WECDZ6aUX-KWvexM_5UAUJ60crUPFVxZyWwV__5N6DyDEpS9SrWKdcrpdwcMOd4u0z6mbK7os
不能得到/认证/ Facebook的/回调?代码= AQBsq2xY-YTsNMmipM45BVBBC9W1QovO1grjC64nDe1psWuRZQwjGv8SMpXuou3s9SaVIIS0_3RqJn-SQ339wPD_TWjRPIpXpZZVHerTRZEQnQYLvt1CM0qMzG5R_JNqfYib6rkmuP4epXou5HoqUa01qszUpYfGMPHUYyNVx1VdMSu3RLbdta8rYle9am539NzYL8ihlwlflnFku-8H3QqlzWJ5Ta1pQ29N0ZyRRu38nKzrDQk-jE5Sq9WECDZ6aUX-KWvexM_5UAUJ60crUPFVxZyWwV__5N6DyDEpS9SrWKdcrpdwcMOd4u0z6mbK7os
This is my model: 这是我的模型:
const mongoose = require('mongoose');
const findOrCreate = require('mongoose-findorcreate');
// Schema definition
const userSchema = mongoose.Schema({
provider: String,
id: String,
displayName: String,
name: [
{familyName: String},
{givenName: String},
{middleName: String},
],
emails: [
{value: String},
{type: String},
],
photos: [
{value: String},
],
});
userSchema.plugin(findOrCreate);
// Compile model from schema
module.exports = mongoose.model('User', userSchema);
The passport part of the app: 应用程序的护照部分:
passport.use(new FacebookStrategy({
clientID: conf.facebookClientID,
clientSecret: conf.facebookSecret,
callbackURL: 'http://localhost:3000/auth/facebook/callback',
},
function(accessToken, refreshToken, profile, done) {
User.findOrCreate(function(err, user) {
if (err) { return done(err); }
done(null, user);
});
}
));
// Authentication routes
app.get('/auth/facebook', passport.authenticate('facebook'));
app.get('auth/facebook/callback',
passport.authenticate('facebook', {
successRedirect: 'http://localhost:3000/words',
failureRedirect: 'http://localhost:3000/auth/facebook',
}));
I am trying to figure out why the login fails, and why the user does not get written into my database (I can query the database for other stuff so I know the connection is valid). 我试图弄清楚为什么登录失败,以及为什么用户没有被写入我的数据库(我可以在数据库中查询其他内容,所以我知道连接是有效的)。
If you need more information about the project please ask and I will edit the question. 如果您需要有关该项目的更多信息,请询问,我将编辑问题。 You can also check the gitHub repo .
您还可以检查gitHub存储库 。
Alter: 改变:
app.get('auth/facebook/callback'
to: 至:
app.get('/auth/facebook/callback'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.