-
Notifications
You must be signed in to change notification settings - Fork 0
/
passport.js
33 lines (26 loc) · 996 Bytes
/
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
const Auth0Startegy = require('passport-auth0'),
passport = require('passport'),
CustomStrategy = require('passport-custom');
const auth0 = new Auth0Startegy({
domain: process.env.AUTH0_DOMAIN,
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
callbackURL: process.env.CALLBACK_URL,
scope: "openid email profile offline_access",
passReqToCallback: true
}, (req, accessToken, refreshToken, _, profile, done) => {
req.session.a0Tokens = { accessToken, refreshToken };
done(null, profile._json);
});
passport.serializeUser((user, done) => done(null, user));
passport.deserializeUser((user, done) => done(null, user));
passport.use(auth0);
passport.use("sessionAuth", new CustomStrategy(function (req, done) {
//TODO: Validate Token
//Simulate user from session for now.
done(null, req.user);
}));
module.exports = function setupPassport(app) {
app.use(passport.initialize());
app.use(passport.session());
}