Skip to content

Instantly share code, notes, and snippets.

@rbhatia46
Last active December 19, 2017 18:24
Show Gist options
  • Save rbhatia46/bfc98c463664582f9044c81a66d52073 to your computer and use it in GitHub Desktop.
Save rbhatia46/bfc98c463664582f9044c81a66d52073 to your computer and use it in GitHub Desktop.
Boilerplate to authenticate using Google using Passport.js and Express Server
const express = require('express');
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const keys = require('./config/keys');
const app = express();
passport.use(new GoogleStrategy({
clientID : keys.googleClientID,
clientSecret : keys.googleClientSecret,
callbackURL : '/auth/google/callback'
}, (accessToken, refreshToken, profile, done) => {
console.log('accessToken',accessToken);
console.log('refreshToken',refreshToken);
console.log('profile',profile);
})
);
app.get('/auth/google', passport.authenticate('google',{
scope : ['profile','email']
}));
app.get('/auth/google/callback',passport.authenticate('google'));
const PORT = process.env.PORT || 5000;
app.listen(PORT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment