-
Notifications
You must be signed in to change notification settings - Fork 0
/
passport.js
39 lines (32 loc) · 1.01 KB
/
passport.js
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
const passport = require('passport')
const OneauthStragey = require('passport-oneauth').Strategy
const {ONEAUTH} = require('./config')
const {User} = require('./db/models')
passport.serializeUser((user, done) => {
return done(null, user.id)
})
passport.deserializeUser((userId, done) => {
User.find({
where: {
id: userId
}
}).then(user => done(null, user))
.catch((err) => console.log(err))
})
const oneauthStrategy = new OneauthStragey({
clientID: ONEAUTH.CLIENT_ID,
clientSecret: ONEAUTH.CLIENT_SECRET,
callbackURL: 'http://localhost:2626/login/callback',
include: ['facebook', 'twitter', 'github']
}, function(accessToken, refreshToken, profile, done) {
User.findCreateFind({
where: {id: profile.id},
defaults: {
id: profile.id,
name: profile.name
}
}).spread((user, created) => done(null, user))
.catch((err) => done(err))
})
passport.use(oneauthStrategy)
exports = module.exports = passport