-
Notifications
You must be signed in to change notification settings - Fork 6
/
spPassport.js
34 lines (32 loc) · 1.17 KB
/
spPassport.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
var SharePointStrategy = require('./strategy.js');
module.exports = function (passport, users, keys) {
passport.serializeUser(function(user, done) {
users[user.id] = user;
// this should just set userid in cookie. cookie is signed and secret
// not sure where this number is from, though, probably need to make
// a smarter id based on url and id or something... or a guid
// cookies should be https-only
// expires when browser session ends
done(null, user.id);
});
passport.deserializeUser(function(id, done) {
var user = users[id];
if (user) {
done(null, users[id]);
} else {
done('User not found', null);
}
});
passport.use(new SharePointStrategy({
clientID: keys.clientID,
clientSecret: keys.clientSecret
},
function(accessToken, refreshToken, profile, done) {
// Adds the tokens to the user
// It is later stored by the serialize/deserializeuser functions
profile.accessToken = accessToken;
profile.refreshToken = refreshToken;
return done(null, profile);
}
));
}