如何解决登录错误:在使用护照js登录此应用程序时出错?

时间:2019-04-27 15:18:04

标签: node.js express

在使用护照js进行facebook oauth时出现此错误。

错误网址:https://www.facebook.com/v3.2/dialog/oauth?response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A3000%2Fauth%2Ffacebook%2Fredirect&scope=profile&client_id=376355999757733

enter image description here

FacebookAuthorizationError: Login Error: There is an error in logging you into this application. Please try again later.
    at Strategy.authenticate (F:\outhApp\node_modules\passport-facebook\lib\strategy.js:81:23)
    at attempt (F:\outhApp\node_modules\passport\lib\middleware\authenticate.js:361:16)
    at authenticate (F:\outhApp\node_modules\passport\lib\middleware\authenticate.js:362:7)
    at Layer.handle [as handle_request] (F:\outhApp\node_modules\express\lib\router\layer.js:95:5)
    at next (F:\outhApp\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (F:\outhApp\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (F:\outhApp\node_modules\express\lib\router\layer.js:95:5)
    at F:\outhApp\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (F:\outhApp\node_modules\express\lib\router\index.js:335:12)
    at next (F:\outhApp\node_modules\express\lib\router\index.js:275:10)
    at jsonParser (F:\outhApp\node_modules\body-parser\lib\types\json.js:110:7)
    at Layer.handle [as handle_request] (F:\outhApp\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (F:\outhApp\node_modules\express\lib\router\index.js:317:13)
    at F:\outhApp\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (F:\outhApp\node_modules\express\lib\router\index.js:335:12)
    at next (F:\outhApp\node_modules\express\lib\router\index.js:275:10)

passport-setup.js (Google oauth可以正常工作)

const passport=require('passport');
const GoogleStrategy=require('passport-google-oauth20');
const FacebookStrategy = require('passport-facebook').Strategy;
const keys=require("./keys");
const User=require('../models/user-model');

passport.serializeUser((user,done)=>{
//saving userid to cookie
    done(null,user.id);
});

passport.deserializeUser((id,done)=>{
    //getting user frpm cookie
    User.findById(id).then((user)=>{
         done(null,user);
    });

});

passport.use(
    new GoogleStrategy({
    //option for google strat
    callbackURL:'http://localhost:3000/auth/google/redirect',
    clientID:keys.google.clientID,
    clientSecret:keys.google.clientSecret
},(accessToken,refreshToken,profile,done)=>{
//passport callback function
console.log("1111");
console.log(profile);
//check if user already exist in our db
User.findOne({googleId:profile.id}).then((currentUser)=>{

    if(currentUser){
        //alraedy have use
        console.log("user already exist"+currentUser);
        done(null,currentUser);
    }else{
    // new user
        new User({
            username:profile.displayName,
            googleId:profile.id,
            thumbnail:profile._json.picture
        }).save().then((newUser)=>{
            console.log("new new created:"+newUser);
            done(null,newUser);
        });

    }

});



})
) 

passport.use(new FacebookStrategy({
    clientID: keys.facebook.clientID,
    clientSecret: keys.facebook.clientSecret,
    callbackURL: "https://localhost:3000/auth/facebook/redirect"
  },
  function(accessToken, refreshToken, profile, done) {
      console.log(profile);
  }
));
  passport.authenticate('facebook'), (req,res)=>{
  //res.send(req.user);
  //res.redirect('/profile');
  res.send("facebook logged in");

  }

0 个答案:

没有答案