secure-express-setup
Version:
Military-grade one-command security setup for Express.js applications
32 lines (26 loc) • 954 B
JavaScript
// lib/oauth.js
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
function setupOAuth({ googleClientID, googleClientSecret, callbackURL = '/auth/google/callback' } = {}) {
if (!googleClientID || !googleClientSecret) {
throw new Error('Google OAuth client ID/secret required');
}
passport.serializeUser((user, done) => done(null, user));
passport.deserializeUser((obj, done) => done(null, obj));
passport.use(new GoogleStrategy({
clientID: googleClientID,
clientSecret: googleClientSecret,
callbackURL
}, (accessToken, refreshToken, profile, done) => {
// transform profile to your user object
const user = {
id: profile.id,
displayName: profile.displayName,
provider: profile.provider,
emails: profile.emails
};
return done(null, user);
}));
return passport;
}
module.exports = setupOAuth;