在回调后向客户发送回复

时间:2018-01-17 07:57:19

标签: javascript node.js reactjs passport.js

在我的React网络应用中,我有一个按钮

http://localhost:3000/login

指出以下地址:

http://localhost:8000/api/auth/login/facebook

API抓住了他,用护照检查用户然后调用这样的回调:

app.get('/api/auth/login/facebook',
    passport.authenticate('facebook', { scope: ['email'] }));

app.get('/api/auth/facebook/callback', passport.authenticate('facebook'),
    (req, res) => {
        console.log(req.user);
        res.send('ok');
    }
);

我配置了这样的护照:

const FacebookStrategy  = require('passport-facebook').Strategy;
const GoogleStrategy        = require('passport-google').Strategy;
const users = require('../models').users;


module.exports = (passport) => {

/*passport.use(new GoogleStrategy({
    clientID: process.env.GOOGLE_APP_ID,
    clientSecret: process.env.GOOGLE_APP_SECRET,
    callbackURL: "https://hsoc.herokuapp.com/auth/login/google/return",
    profileFields: ['profile','email'],
    enableProof: true
},
(accessToken, refreshToken, profile, cb) => {
    console.log("PROFILE: ");
    console.log(util.inspect(profile, false, null));
    users
    .findOrCreate({where: {GOOGLE_ID: profile.id, EMAIL: profile.emails[0].value}})
    .spread((user, created) => {
        // console.log(user.get({
        //     plain: true
        // }));
        // console.log(created);
        return cb(null, user);
    });
}
));*/
passport.use(new FacebookStrategy({
    clientID: "",
    clientSecret: "",
    authParameters: {
      scope: "user_posts,manage_pages"
    },
    callbackURL: "http://localhost:8000/api/auth/facebook/callback",
    profileFields: ['id', 'displayName', 'photos', 'email'],
    enableProof: true
},
(accessToken, refreshToken, profile, cb) => {        
    console.log(profile._json);        
    return cb(null,'hei');

}
));

};

使用facebook登录后,如何在localhost:3000上重定向页面而不是localhost:8000。

0 个答案:

没有答案