-
Notifications
You must be signed in to change notification settings - Fork 0
/
passport.js
43 lines (39 loc) · 1.16 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
40
41
42
43
const passport = require('passport')
const VKontakteStrategy = require('passport-vkontakte').Strategy;
const User = require('./User')
const ansible = require('./ansible')
passport.use(new VKontakteStrategy({
clientID: 7246234,
clientSecret: "H68F3fPblgCeB6OMA7Jc",
callbackURL: "https://gridncloud.azurewebsites.net/auth/vkontakte/callback"
},
function(accessToken, refreshToken, params, profile, done) {
User.findOne({ vkontakteId: profile.id }, function(err, user) {
if (err) { return done(err); }
if (!user) {
let user = User.create({vkontakteId : profile.id, text: "", length: 0})
ansible.createRG(profile.id)
}
return done(null, user);
})
}
));
passport.serializeUser(function(user, done) {
console.log('Сериализация: ', user)
done(null, user.vkontakteId)
})
passport.deserializeUser(async function(id, done) {
try{
const user = await User.findOne({ vkontakteId: id})
if(!user) {
return done(null, false)
}
else{
return done(null, user)
}
}
catch(err){
return done(err)
}
});
module.exports = passport