passport.js 1.17 KB

const passport = require('passport');
const TaobaoStrategy = require('./passport-taobao');

const uuid = require('uuid');

const config = global.yoho.config;

// taobao 登录
passport.use('taobao', new TaobaoStrategy({
    clientID: '27930297',
    clientSecret: '29b30287153a02f531c160df17da8078',
    callbackURL: `http://127.0.0.1:6001/xianyu/passport/callback/taobao`,
    requireState: false
}, (accessToken, refreshToken, profile, done) => {
    done(null, profile);
}));

const login = {
    taobaoLogin: (req, res, next) => {
        req.session.authState = uuid.v4();

        return passport.authenticate('taobao', {
            state: req.session.authState,
            failWithError: true
        })(req, res, next);
    },
    taobaoCallback: (req, res, next) => {
        console.log(req.session)
        // return res.send(req.query);
        passport.authenticate('taobao', (err, user) => {
            console.log('21312312')
            console.log(user)
            console.log(err)
        })(req, res, next);
        // if (req.session.authState === req.query.state) {
        // } else {
        //     res.send('error');
        // }
    }
}

module.exports = {
    login
};