为什么我收到这个Facebook Passport oauth2响应错误



我正在尝试使用passport(node-js(将Facebook登录集成到我的应用程序中。当重定向到facebook时,我看到了我的应用程序,我可以接受,并且在重定向时,我得到了这个错误:传递的代码不正确或过期。

我的代码是:


passport.use(new FacebookStrategy({
clientID: process.env.FACEBOOK_APP_ID || '',
clientSecret: process.env.FACEBOOK_APP_SECRET || '',
callbackURL: hostUrl + "/api/auth/facebook/callback"
},
async function(accessToken, refreshToken, profile, cb) {
console.log(profile);
}
));
// PassportService.ts
public static redirectToHomepage(req: Request, res: Response) {
if (req.user) {
const user: any = req.user;
const token = jwt.sign({userId: user.id}, process.env.JWT_SECRET || 'abc');
res.redirect('/?token='+token);
}
}
public static authenticateFacebook(req: Request, res: Response, next: NextFunction) {
passport.authenticate('facebook')(req, res, next);
}
public static authenticateFacebookCallback(req: Request, res: Response, next: NextFunction) {
passport.authenticate('facebook', { failureRedirect: '/auth/login' })(req, res, next);
}
//routes.ts. endpoint: /api/auth
router.get('/facebook', PassportService.authenticateFacebook);
router.get('/facebook/callback', PassportService.authenticateGithubCallback, PassportService.redirectToHomepage);

现在我看到了问题。我的路线/facebook/callback正在呼叫PassportService.authenticateGithubCallback。我把它改成了Facebook回拨,现在它起作用了。

最新更新