passport.js
1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
};